void SubprogramBlock::run() { const Id logicalId = mGraphicalModelApi->logicalId(id()); const QString name = mLogicalModelApi->name(logicalId); const QString validName = utils::NameNormalizer::normalizeStrongly(name, false); if (validName.isEmpty()) { error(tr("Please enter valid c-style name for subprogram \"") + name + "\""); return; } const QList<DynamicParameter> parameters = dynamicParameters(); for (const DynamicParameter ¶m : parameters) { if (param.type == "bool") { setVariableValue<bool>(param.name, evalCode<bool>(param.code)); } else if (param.type == "int") { setVariableValue<int>(param.name, evalCode<int>(param.code)); } else if (param.type == "float") { setVariableValue<qreal>(param.name, evalCode<qreal>(param.code)); } else { setVariableValue<QString>(param.name, evalCode<QString>(param.code)); } } const Id logicalDiagram = mLogicalModelApi->logicalRepoApi().outgoingExplosion(logicalId); const IdList diagrams = mGraphicalModelApi->graphicalIdsByLogicalId(logicalDiagram); if (!diagrams.isEmpty()) { emit stepInto(diagrams[0]); } }
void MultipleRemoveCommand::setItemsToDelete(IdList &itemsToDelete) { IdList itemsToUpdate; addEdgesToBeDeleted(itemsToDelete); // QGraphicsScene::selectedItems() returns items in no particular order, // so we should handle parent-child relationships manually while (!itemsToDelete.isEmpty()) { const Id currentItem = itemsToDelete.at(0); const IdList children = mGraphicalApi.children(currentItem); foreach (const Id &child, children) { itemsToDelete.removeAll(child); // Child remove commands will be added in currentItem delete command } const bool isEdge = !mLogicalApi.editorManagerInterface().isGraphicalElementNode(currentItem); if (isEdge) { const Id src = mGraphicalApi.from(currentItem); if (src != Id() && !itemsToUpdate.contains(src)) { itemsToUpdate.append(src); } const Id dst = mGraphicalApi.to(currentItem); if (dst != Id() && !itemsToUpdate.contains(dst)) { itemsToUpdate.append(dst); } insertPreAction(graphicalDeleteCommand(currentItem), 0); } else { addPreAction(graphicalDeleteCommand(currentItem)); } itemsToDelete.removeAll(currentItem); }
QString JavaHandler::generateToJava(QString const &pathToDir) { mErrorText = ""; this->pathToDir = pathToDir; Id repoId = ROOT_ID; if (checkTheModel()) { IdList allDiagrams = mApi.children(repoId); IdList classDiagrams; //separate just class diagrams, because they are the main diagrams, others are connected foreach (Id const aDiagram, allDiagrams) { if (objectType(aDiagram) == "ClassDiagram_ClassDiagramNode") { classDiagrams.append(aDiagram); } if (objectType(aDiagram) == "ActivityDiagram_ActivityDiagramNode") { //If there is no connected Class Methods it won't be serialized IdList incomingConnections = mApi.incomingConnections(aDiagram); if (incomingConnections.isEmpty()) { addError("Unable to serialize object " + objectType(aDiagram) + " with type: " + aDiagram.toString() + ". It is not connected to some class method."); } } } foreach (Id const classDiagram, classDiagrams) { serializeChildren(classDiagram); } }
void DraggableElement::checkElementForChildren() { mIsRootDiagramNode = false; const IdList children = mEditorManagerProxy.children(mDeletedElementId); if (!children.isEmpty()) { QString childrenNames; foreach (const Id child, children) { childrenNames += " " + mEditorManagerProxy.friendlyName(child) + ","; }
QString join(IdList ids) { QString result; if (ids.isEmpty()) return result; result = QString::number(ids.takeFirst()); foreach (auto id, ids) result += QLatin1Literal(",") % QString::number(id); return result; }
void RulesChecker::checkFinalNodeRule(qReal::Id const &node) { bool isLastNode = isEndNode(node); if (!isLastNode && !isStartNode(node)) { return; } IdList incorrectLinks = (isLastNode) ? outgoingSequenceFlow(node) : incomingSequenceFlow(node); if (!incorrectLinks.isEmpty()) { postError((isLastNode) ? linkFromFinalNode : linkToStartNode, node); foreach (Id const &key, incorrectLinks) { mDiagramElements.removeOne(key); }
void SubprogramBlock::run() { const Id logicalId = mGraphicalModelApi->logicalId(id()); const QString name = mLogicalModelApi->name(logicalId); const QString validName = utils::NameNormalizer::normalizeStrongly(name, false); if (validName.isEmpty()) { error(tr("Please enter valid c-style name for subprogram \"") + name + "\""); return; } const QString properties = mLogicalModelApi->logicalRepoApi().stringProperty(logicalId, "dynamicProperties"); if (!properties.isEmpty()) { QDomDocument dynamicProperties; dynamicProperties.setContent(properties); QHash<QString, QVariant> calculatedValues; for (QDomElement element = dynamicProperties.firstChildElement("properties").firstChildElement("property") ; !element.isNull() ; element = element.nextSiblingElement("property")) { const QString type = element.attribute("type"); const QString value = element.attribute("value"); const QString name = element.attribute("text"); if (type == "bool") { calculatedValues.insert(name, evalCode<bool>(value)); } else if (type == "int") { calculatedValues.insert(name, evalCode<int>(value)); } else { calculatedValues.insert(name, evalCode<QString>(value)); } } for (QHash<QString, QVariant>::iterator i = calculatedValues.begin(); i != calculatedValues.end(); ++i) { if (i.value().type() == QVariant::Bool) { setVariableValue<bool>(i.key(), i.value().toBool()); } else if (i.value().type() == QVariant::Int) { setVariableValue<int>(i.key(), i.value().toInt()); } else { setVariableValue<QString>(i.key(), i.value().toString()); } } } const Id logicalDiagram = mLogicalModelApi->logicalRepoApi().outgoingExplosion(logicalId); const IdList diagrams = mGraphicalModelApi->graphicalIdsByLogicalId(logicalDiagram); if (!diagrams.isEmpty()) { emit stepInto(diagrams[0]); } }
qReal::ProjectConverter SaveConvertionManager::constructConverter(const QString &oldVersion , const QString &newVersion , const QList<LogicalFilter> &logicalFilters , const QList<GraphicalFilter> &graphicalFilters , const std::function<bool(const qReal::Id &)> &condition ) { return ProjectConverter(editor(), Version::fromString(oldVersion), Version::fromString(newVersion) , [=](GraphicalModelAssistInterface &graphicalApi, LogicalModelAssistInterface &logicalApi) { bool modificationsMade = false; for (const Id &block : elementsOfRobotsDiagrams(logicalApi)) { const Id logicalBlock = graphicalApi.isGraphicalId(block) ? graphicalApi.logicalId(block) : block; if (!condition(logicalBlock)) { continue; } for (const auto &filter : logicalFilters) { modificationsMade |= filter(logicalBlock, logicalApi); } if (graphicalFilters.isEmpty()) { // A small optimization not to count graphical id. continue; } Id graphicalBlock; if (graphicalApi.isGraphicalId(block)) { graphicalBlock = block; } else { const IdList graphicalIds = graphicalApi.graphicalIdsByLogicalId(logicalBlock); if (graphicalIds.isEmpty()) { continue; } graphicalBlock = graphicalIds.first(); } for (const auto &filter : graphicalFilters) { modificationsMade |= filter(graphicalBlock, graphicalApi); } } return modificationsMade ? ProjectConverter::Success : ProjectConverter::NoModificationsMade; }); }
void SubprogramBlock::run() { Id const logicalId = mGraphicalModelApi->logicalId(id()); QString const name = mLogicalModelApi->name(logicalId); Tracer::debug(tracer::enums::blocks, "SubprogramBlock::run", "stepping into " + name); QString const validName = utils::NameNormalizer::normalizeStrongly(name, false); if (validName.isEmpty()) { error(tr("Please enter valid c-style name for subprogram \"") + name + "\""); return; } Id const logicalDiagram = mLogicalModelApi->logicalRepoApi().outgoingExplosion(logicalId); IdList const diagrams = mGraphicalModelApi->graphicalIdsByLogicalId(logicalDiagram); if (!diagrams.isEmpty()) { emit stepInto(diagrams[0]); } }
bool RulesChecker::makeDetour(Id const ¤tNode, IdList &usedNodes) { if (usedNodes.contains(currentNode)) { return false; // cannot learn some more here } if (!mDiagramElements.contains(currentNode)) { return true; // we already have made detour of forward nodes } mDiagramElements.removeOne(currentNode); usedNodes.append(currentNode); if (currentNode.element() != "MessageFlow" && isLink(currentNode)) { Id const destinationNode = mGRepoApi->to(currentNode); if (destinationNode == Id::rootId()) { postError(noEndNode, currentNode); // we've already put info that link is incorrect return true; // done end-job for link(50%) } return makeDetour(destinationNode, usedNodes); } if (isEndNode(currentNode)) { return true; // we found real end-node } IdList frontNodes = outgoingSequenceFlow(currentNode); if (frontNodes.isEmpty()) { postError(noEndNode, currentNode); return true; // done end-job for nodes (now 100%) } bool foundFinalNode = false; // to catch that we have found end-node anywhere in path foreach (Id const &node, frontNodes) { if (makeDetour(node, usedNodes)) { foundFinalNode = true; } } return foundFinalNode; }
void EditPropertiesDialog::acceptPropertyModifications() { if (mPropertyName.isEmpty()) { const IdList sameNameProperties = mInterpreterEditorManager.propertiesWithTheSameName(mId, "" , mUi->displayedNameEdit->text()); if (sameNameProperties.isEmpty()) { mPropertyName = mUi->displayedNameEdit->text(); } else { mPropertyName = mUi->displayedNameEdit->text() + "_" + sameNameProperties.count(); } mInterpreterEditorManager.addProperty(mId, mPropertyName); // set property default value for elements on diagram for (const auto &elementOnDiagram: mElementsOnDiagram) { mApi.setProperty(elementOnDiagram, mPropertyName, mUi->defaultValueEdit->text()); } mElementsOnDiagram.clear(); } if (mMode == editExisting && mInterpreterEditorManager.typeName(mId, mPropertyName) != mUi->attributeTypeEdit->text() ) { // TODO: Remove connects. QMessageBox messageBox(tr("Warning:") , tr("You changed the type of property. In case of incorrect conversion it may" " result in resetting of the existing property value.") , QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Cancel, QMessageBox::NoButton); messageBox.button(QMessageBox::Ok)->setText(tr("Proceed anyway")); messageBox.button(QMessageBox::Cancel)->setText(tr("Cancel the type conversion")); connect(messageBox.button(QMessageBox::Cancel), &QAbstractButton::clicked , this, &EditPropertiesDialog::messageBoxCancel); connect(messageBox.button(QMessageBox::Ok), &QAbstractButton::clicked , this, &EditPropertiesDialog::updateProperties); messageBox.exec(); } else { updateProperties(); } }
void EdgePropertiesDialog::okButtonClicked() { if (mUi->nameEdit->text().isEmpty()) { QMessageBox::critical(this, tr("Error"), tr("All required properties should be filled!")); } else { mEdgeName = mUi->nameEdit->text(); IdList const edgesWithTheSameNameList = mEditorManagerProxy.elementsWithTheSameName(mDiagram , mUi->nameEdit->text(), "MetaEntityEdge"); if (!edgesWithTheSameNameList.isEmpty()) { mEdgeName = mUi->nameEdit->text() + "_" + edgesWithTheSameNameList.count(); mRestoreElementDialog = new RestoreElementDialog(this, mMainWindow, mEditorManagerProxy, edgesWithTheSameNameList); mRestoreElementDialog->setModal(true); mRestoreElementDialog->show(); connect(mRestoreElementDialog, &qReal::RestoreElementDialog::createNewChosen , this, &EdgePropertiesDialog::addEdgeElement); connect(mRestoreElementDialog, &qReal::RestoreElementDialog::restoreChosen , this, &EdgePropertiesDialog::done); } else { addEdgeElement(); } } }
void EditPropertiesDialog::okButtonClicked() { if (mUi->attributeTypeEdit->text().isEmpty() || mUi->displayedNameEdit->text().isEmpty()) { QMessageBox::critical(this, tr("Error"), tr("All required properties should be filled!")); } else { const IdList propertiesWithTheSameNameList = mInterpreterEditorManager.propertiesWithTheSameName(mId , mPropertyName, mUi->displayedNameEdit->text()); if (!propertiesWithTheSameNameList.isEmpty()) { hide(); mRestorePropertiesDialog = new RestorePropertiesDialog(this, mInterpreterEditorManager); mRestorePropertiesDialog->fillSameNamePropertiesTW(propertiesWithTheSameNameList , mUi->displayedNameEdit->text()); mRestorePropertiesDialog->setWindowTitle(tr("Restore properties")); mRestorePropertiesDialog->setModal(true); mRestorePropertiesDialog->show(); connect(mRestorePropertiesDialog, &qReal::RestorePropertiesDialog::createNewChosen , this, &EditPropertiesDialog::acceptPropertyModifications); connect(mRestorePropertiesDialog, &qReal::RestorePropertiesDialog::finished , this, &EditPropertiesDialog::done); } else { acceptPropertyModifications(); } } }
MainWindow::MainWindow() : mUi(new Ui::MainWindowUi) , mCloseEvent(NULL) , mModels(NULL) , mListenerManager(NULL) , mPropertyModel(mEditorManager) , mGesturesWidget(NULL) , mVisualDebugger(NULL) , mRobotInterpreter(NULL) , mBluetoothCommunication(NULL) , mErrorReporter(NULL) { QSettings settings("SPbSU", "QReal"); bool showSplash = settings.value("Splashscreen", true).toBool(); QSplashScreen* splash = new QSplashScreen(QPixmap(":/icons/kroki3.PNG"), Qt::SplashScreen | Qt::WindowStaysOnTopHint); QProgressBar *progress = new QProgressBar((QWidget*) splash); progress->move(20, 270); progress->setFixedWidth(600); progress->setFixedHeight(15); progress->setRange(0, 100); // Step 1: splash screen loaded, progress bar initialized. progress->setValue(5); if (showSplash) { splash->show(); QApplication::processEvents(); } mUi->setupUi(this); mUi->tabs->setTabsClosable(true); mUi->tabs->setMovable(true); mUi->logicalModelDock->setVisible(false); if (!showSplash) mUi->actionShowSplash->setChecked(false); mUi->minimapView->setRenderHint(QPainter::Antialiasing, true); // Step 2: Ui is ready, splash screen shown. progress->setValue(20); mUi->actionShow_grid->setChecked(settings.value("ShowGrid", true).toBool()); mUi->actionShow_alignment->setChecked(settings.value("ShowAlignment", true).toBool()); mUi->actionSwitch_on_grid->setChecked(settings.value("ActivateGrid", true).toBool()); mUi->actionSwitch_on_alignment->setChecked(settings.value("ActivateAlignment", true).toBool()); connect(mUi->actionQuit, SIGNAL(triggered()), this, SLOT(close())); connect(mUi->actionShowSplash, SIGNAL(toggled(bool)), this, SLOT (toggleShowSplash(bool))); connect(mUi->actionOpen, SIGNAL(triggered()), this, SLOT(open())); connect(mUi->actionSave, SIGNAL(triggered()), this, SLOT(saveAll())); connect(mUi->actionSave_as, SIGNAL(triggered()), this, SLOT(saveAs())); connect(mUi->actionPrint, SIGNAL(triggered()), this, SLOT(print())); connect(mUi->actionMakeSvg, SIGNAL(triggered()), this, SLOT(makeSvg())); connect(mUi->actionDeleteFromDiagram, SIGNAL(triggered()), this, SLOT(deleteFromDiagram())); connect(mUi->tabs, SIGNAL(currentChanged(int)), this, SLOT(changeMiniMapSource(int))); connect(mUi->tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); connect(mUi->actionGenerate_Editor, SIGNAL(triggered()), this, SLOT(generateEditor())); connect(mUi->actionParse_Editor_xml, SIGNAL(triggered()), this, SLOT(parseEditorXml())); connect(mUi->actionPreferences, SIGNAL(triggered()), this, SLOT(showPreferencesDialog())); connect(mUi->actionPlugins, SIGNAL(triggered()), this, SLOT(settingsPlugins())); connect(mUi->actionShow_grid, SIGNAL(toggled(bool)), this, SLOT(showGrid(bool))); connect(mUi->actionShow_alignment, SIGNAL(toggled(bool)), this, SLOT(showAlignment(bool))); connect(mUi->actionSwitch_on_grid, SIGNAL(toggled(bool)), this, SLOT(switchGrid(bool))); connect(mUi->actionSwitch_on_alignment, SIGNAL(toggled(bool)), this, SLOT(switchAlignment(bool))); connect(mUi->actionHelp, SIGNAL(triggered()), this, SLOT(showHelp())); connect(mUi->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout())); connect(mUi->actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(mUi->actionShow, SIGNAL(triggered()), this, SLOT(showGestures())); connect(mUi->minimapZoomSlider, SIGNAL(valueChanged(int)), this, SLOT(adjustMinimapZoom(int))); connect(mUi->actionClear, SIGNAL(triggered()), this, SLOT(exterminate())); connect(mUi->actionRun, SIGNAL(triggered()), this, SLOT(run())); connect(mUi->actionStop_Running, SIGNAL(triggered()), this, SLOT(stop())); connect(mUi->actionStop_Robot, SIGNAL(triggered()), this, SLOT(stopRobot())); connect(mUi->actionRobot_Settings, SIGNAL(triggered()), this, SLOT(showRobotSettingsDialog())); adjustMinimapZoom(mUi->minimapZoomSlider->value()); initGridProperties(); // Step 3: Ui connects are done. progress->setValue(40); mUi->paletteDock->setWidget(mUi->paletteToolbox); mUi->errorDock->setWidget(mUi->errorListWidget); mUi->errorListWidget->init(this); mUi->errorDock->setVisible(false); mUi->propertyEditor->setModel(&mPropertyModel); mUi->propertyEditor->verticalHeader()->hide(); mUi->propertyEditor->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents); mUi->propertyEditor->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch); mUi->propertyEditor->setItemDelegate(&mDelegate); connect(mUi->graphicalModelExplorer, SIGNAL(clicked(QModelIndex const &)), this, SLOT(graphicalModelExplorerClicked(QModelIndex))); connect(mUi->logicalModelExplorer, SIGNAL(clicked(QModelIndex const &)), this, SLOT(logicalModelExplorerClicked(QModelIndex))); mUi->graphicalModelExplorer->addAction(mUi->actionDeleteFromDiagram); mUi->logicalModelExplorer->addAction(mUi->actionDeleteFromDiagram); // Step 4: Property editor and model explorers are initialized. progress->setValue(60); loadPlugins(); showMaximized(); // Step 5: Plugins are loaded. progress->setValue(70); settings.beginGroup("MainWindow"); if (!settings.value("maximized", true).toBool()) { showNormal(); resize(settings.value("size", QSize(1024, 800)).toSize()); move(settings.value("pos", QPoint(0, 0)).toPoint()); } settings.endGroup(); QString workingDir = settings.value("workingDir", ".").toString(); mRootIndex = QModelIndex(); mModels = new models::Models(workingDir, mEditorManager); // Step 6: Save loaded, models initialized. progress->setValue(80); mListenerManager = new ListenerManager(mEditorManager.listeners() , mModels->logicalModelAssistApi(), mModels->graphicalModelAssistApi()); IdList missingPlugins = mEditorManager.checkNeededPlugins(mModels->logicalRepoApi(), mModels->graphicalRepoApi()); if (!missingPlugins.isEmpty()) { QString text = tr("These plugins are not present, but needed to load the save:\n"); foreach (Id const id, missingPlugins) text += id.editor() + "\n"; QMessageBox::warning(this, tr("Some plugins are missing"), text); close(); return; }