repeat.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 "repeat.h"
00012 
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015 
00016 #include <klocale.h>
00017 
00018 Item* Repeat::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00019 {
00020         return new Repeat( (ICNDocument*)itemDocument, newItem, id );
00021 }
00022 
00023 LibraryItem* Repeat::libraryItem()
00024 {
00025         return new LibraryItem(
00026                 QString("flow/repeat"),
00027                 i18n("Repeat"),
00028                 i18n("Loops"),
00029                 "repeat.png",
00030                 LibraryItem::lit_flowpart,
00031                 Repeat::construct );
00032 }
00033 
00034 Repeat::Repeat( ICNDocument *icnDocument, bool newItem, const char *id )
00035         : FlowContainer( icnDocument, newItem, (id) ? id : "repeatloop" )
00036 {
00037         m_name = i18n("Repeat");
00038         m_desc = i18n("Repeatedly execute code, until the given condition is false. The condition is checked after the code has been executed.<br><br>This is different from \"While\", which checks for the condition to be true before the code is executed.");
00039         createTopContainerNode();
00040         createBotContainerNode();
00041         
00042         createProperty( "0var1", Variant::Type::Combo );
00043         property("0var1")->setToolbarCaption( "repeat until" );
00044         property("0var1")->setEditorCaption( i18n("Variable") );
00045         property("0var1")->setValue("x");
00046         
00047         createProperty( "1op", Variant::Type::Select );
00048         property("1op")->setToolbarCaption(" ");
00049         property("1op")->setEditorCaption( i18n("Operation") );
00050         property("1op")->setAllowed( QStringList::split( ',', "==,<,>,<=,>=,!=" ) );
00051         property("1op")->setValue("==");
00052         
00053         createProperty( "2var2", Variant::Type::Combo );
00054         property("2var2")->setToolbarCaption(" ");
00055         property("2var2")->setEditorCaption( i18n("Value") );
00056         property("2var2")->setValue("0");
00057 }
00058 
00059 Repeat::~Repeat()
00060 {
00061 }
00062 
00063 void Repeat::dataChanged()
00064 {
00065         setCaption( i18n("repeat until %1 %2 %3").arg(dataString("0var1")).arg(dataString("1op")).arg(dataString("2var2")) );
00066 }
00067 
00068 void Repeat::generateMicrobe( FlowCode *code )
00069 {
00070         code->addCode("repeat\n{\n");
00071         code->addCodeBranch( outputPart("int_in") );
00072         code->addCode("}\n");
00073         code->addCode("until "+dataString("0var1")+" "+dataString("1op")+" " + dataString("2var2") );
00074         code->addCodeBranch( outputPart("ext_out") );
00075 }
00076 
00077 
00078 
00079 
00080 

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