forloop.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2004 by David Saxton                               *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "forloop.h"
00012 
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015 
00016 #include <klocale.h>
00017 
00018 Item* ForLoop::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00019 {
00020         return new ForLoop( (ICNDocument*)itemDocument, newItem, id );
00021 }
00022 
00023 LibraryItem* ForLoop::libraryItem()
00024 {
00025         return new LibraryItem(
00026                 QString("flow/forloop"),
00027                 i18n("For"),
00028                 i18n("Loops"),
00029                 "for.png",
00030                 LibraryItem::lit_flowpart,
00031                 ForLoop::construct );
00032 }
00033 
00034 ForLoop::ForLoop( ICNDocument *icnDocument, bool newItem, const char *id )
00035         : FlowContainer( icnDocument, newItem, (id) ? id : "forloop" )
00036 {
00037         m_name = i18n("For Loop");
00038         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.<br><br>The for loop will exit when the value contained in the variable is equal to the end value.");
00039         
00040         createTopContainerNode();
00041         createBotContainerNode();
00042         
00043         createProperty( "0-var", Variant::Type::Combo );
00044         property("0-var")->setToolbarCaption("for");
00045         property("0-var")->setEditorCaption( i18n("Variable") );
00046         property("0-var")->setValue("x");
00047         
00048         createProperty( "1-initial", Variant::Type::Combo );
00049         property("1-initial")->setToolbarCaption("=");
00050         property("1-initial")->setEditorCaption( i18n("Initial Value") );
00051         property("1-initial")->setValue("1");
00052         
00053         createProperty( "2-end", Variant::Type::Combo );
00054         property("2-end")->setToolbarCaption("to");
00055         property("2-end")->setEditorCaption( i18n("End Value") );
00056         property("2-end")->setValue("10");
00057         
00058         createProperty( "3-step", Variant::Type::Combo );
00059         property("3-step")->setToolbarCaption("step");
00060         property("3-step")->setEditorCaption( i18n("Step") );
00061         property("3-step")->setValue("1");
00062         property("3-step")->setAdvanced(true);
00063 }
00064 
00065 ForLoop::~ForLoop()
00066 {
00067 }
00068 
00069 void ForLoop::dataChanged()
00070 {
00071         if( dataString("3-step").toInt() == 1 )
00072         setCaption( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") );
00073         else setCaption( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") + " step " + dataString("3-step"));
00074 }
00075 
00076 void ForLoop::generateMicrobe( FlowCode *code )
00077 {
00078         if( dataString("3-step").toInt() == 1 ) code->addCode( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") + "\n{" );
00079         else code->addCode( "for " + dataString("0-var") + " = " + dataString("1-initial") + " to " + dataString("2-end") + " step " + dataString("3-step") +"\n{" );
00080         code->addCodeBranch( outputPart("int_in") );
00081         code->addCode("}");
00082         code->addCodeBranch( outputPart("ext_out") );
00083 }
00084 

Generated on Tue May 8 17:05:30 2007 for KTechLab by  doxygen 1.5.1