File indexing completed on 2024-04-21 05:43:37

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 "repeat.h"
0012 
0013 #include "flowcode.h"
0014 #include "libraryitem.h"
0015 #include "icndocument.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 Item *Repeat::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new Repeat(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *Repeat::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("flow/repeat")), i18n("Repeat"), i18n("Loops"), "repeat.png", LibraryItem::lit_flowpart, Repeat::construct);
0027 }
0028 
0029 Repeat::Repeat(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : FlowContainer(icnDocument, newItem, id ? id : "repeatloop")
0031 {
0032     m_name = i18n("Repeat");
0033     createTopContainerNode();
0034     createBotContainerNode();
0035 
0036     createProperty("0var1", Variant::Type::Combo);
0037     property("0var1")->setToolbarCaption("repeat until");
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 Repeat::~Repeat()
0058 {
0059 }
0060 
0061 void Repeat::dataChanged()
0062 {
0063     setCaption(i18n("repeat until %1 %2 %3", dataString("0var1"), dataString("1op"), dataString("2var2")));
0064 }
0065 
0066 void Repeat::generateMicrobe(FlowCode *code)
0067 {
0068     code->addCode("repeat\n{\n");
0069     code->addCodeBranch(outputPart("int_in"));
0070     code->addCode("}\n");
0071     code->addCode("until " + dataString("0var1") + " " + dataString("1op") + " " + dataString("2var2"));
0072     code->addCodeBranch(outputPart("ext_out"));
0073 }