File indexing completed on 2024-04-14 05:36:44

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2004 by David Saxton                               *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "while.h"
0012 
0013 #include "flowcode.h"
0014 #include "libraryitem.h"
0015 #include "icndocument.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 Item *While::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new While(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *While::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("flow/while")), i18n("While"), i18n("Loops"), "while.png", LibraryItem::lit_flowpart, While::construct);
0027 }
0028 
0029 While::While(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : FlowContainer(icnDocument, newItem, id ? id : "whileloop")
0031 {
0032     m_name = i18n("While");
0033     createTopContainerNode();
0034     createBotContainerNode();
0035 
0036     createProperty("0var1", Variant::Type::Combo);
0037     property("0var1")->setToolbarCaption("while");
0038     property("0var1")->setEditorCaption(i18n("Variable"));
0039     property("0var1")->setValue("x");
0040 
0041     createProperty("1op", Variant::Type::Select);
0042     property("1op")->setToolbarCaption(" ");
0043     property("1op")->setEditorCaption(i18n("Operation"));
0044     property("1op")->setAllowed((QStringList("==") << "<"
0045                                                    << ">"
0046                                                    << "<="
0047                                                    << ">="
0048                                                    << "!="));
0049     property("1op")->setValue("==");
0050 
0051     createProperty("2var2", Variant::Type::Combo);
0052     property("2var2")->setToolbarCaption(" ");
0053     property("2var2")->setEditorCaption(i18n("Value"));
0054     property("2var2")->setValue("0");
0055 }
0056 
0057 While::~While()
0058 {
0059 }
0060 
0061 void While::dataChanged()
0062 {
0063     setCaption(i18n("while %1 %2 %3", dataString("0var1"), dataString("1op"), dataString("2var2")));
0064 }
0065 
0066 void While::generateMicrobe(FlowCode *code)
0067 {
0068     code->addCode("while " + dataString("0var1") + " " + dataString("1op") + " " + dataString("2var2") + "\n{");
0069     code->addCodeBranch(outputPart("int_in"));
0070     code->addCode("}");
0071     code->addCodeBranch(outputPart("ext_out"));
0072 }