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

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