From 5de3dd4762ca33a0f92e79ffa4fe2ff67069d531 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 01:49:02 +0000 Subject: Added KDE3 version of ktechlab git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktechlab@1095338 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/flowparts/forloop.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/flowparts/forloop.cpp (limited to 'src/flowparts/forloop.cpp') diff --git a/src/flowparts/forloop.cpp b/src/flowparts/forloop.cpp new file mode 100644 index 0000000..d2fe88b --- /dev/null +++ b/src/flowparts/forloop.cpp @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2003-2004 by David Saxton * + * david@bluehaze.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "forloop.h" + +#include "libraryitem.h" +#include "flowcode.h" + +#include + +Item* ForLoop::construct( ItemDocument *itemDocument, bool newItem, const char *id ) +{ + return new ForLoop( (ICNDocument*)itemDocument, newItem, id ); +} + +LibraryItem* ForLoop::libraryItem() +{ + return new LibraryItem( + QString("flow/forloop"), + i18n("For"), + i18n("Loops"), + "for.png", + LibraryItem::lit_flowpart, + ForLoop::construct ); +} + +ForLoop::ForLoop( ICNDocument *icnDocument, bool newItem, const char *id ) + : FlowContainer( icnDocument, newItem, (id) ? id : "forloop" ) +{ + m_name = i18n("For Loop"); + m_desc = i18n("The code contained in the foor loop is repeatedly executed. By default, the variable used will be incremented every time. This can be changed by entering a value other than 1 into Step.

The for loop will exit when the value contained in the variable is equal to the end value."); + + createTopContainerNode(); + createBotContainerNode(); + + createProperty( "0-var", Variant::Type::Combo ); + property("0-var")->setToolbarCaption("for"); + property("0-var")->setEditorCaption( i18n("Variable") ); + property("0-var")->setValue("x"); + + createProperty( "1-initial", Variant::Type::Combo ); + property("1-initial")->setToolbarCaption("="); + property("1-initial")->setEditorCaption( i18n("Initial Value") ); + property("1-initial")->setValue("1"); + + createProperty( "2-end", Variant::Type::Combo ); + property("2-end")->setToolbarCaption("to"); + property("2-end")->setEditorCaption( i18n("End Value") ); + property("2-end")->setValue("10"); + + createProperty( "3-step", Variant::Type::Combo ); + property("3-step")->setToolbarCaption("step"); + property("3-step")->setEditorCaption( i18n("Step") ); + property("3-step")->setValue("1"); + property("3-step")->setAdvanced(true); +} + +ForLoop::~ForLoop() +{ +} + +void ForLoop::dataChanged() +{ + if( dataString("3-step").toInt() == 1 ) + setCaption( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") ); + else setCaption( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") + " step " + dataString("3-step")); +} + +void ForLoop::generateMicrobe( FlowCode *code ) +{ + if( dataString("3-step").toInt() == 1 ) code->addCode( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") + "\n{" ); + else code->addCode( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") + " step " + dataString("3-step") +"\n{" ); + code->addCodeBranch( outputPart("int_in") ); + code->addCode("}"); + code->addCodeBranch( outputPart("ext_out") ); +} + -- cgit v1.2.1