31 #include "../StatechartViewerPlugin/view/StatechartView.h"
32 #include "../StatechartViewerPlugin/model/stateinstance/RemoteState.h"
33 #include "../StatechartViewerPlugin/model/stateinstance/DynamicRemoteState.h"
35 #include <QMessageBox>
43 mainWindow(mainWindow),
44 treeController(treeController),
45 communicator(communicator),
46 variantInfo(variantInfo),
47 currentProfile(currentProfile),
59 editState =
menu.addAction(QIcon(
":/icons/accessories-text-editor-6.ico"),
"");
60 deleteState =
menu.addAction(QIcon(
":/icons/delete.ico"),
"Delete State");
61 layoutState =
menu.addAction(QIcon(
":/icons/magic-wand-icon.png"),
"Layout State");
64 newEndstate =
menu.addAction(QIcon(
":/statechart-editor/new-endstate.svg"),
"Insert new Endstate");
66 openCode =
menu.addAction(QIcon(
":/icons/cpp.svg"),
"Open C++ Code");
68 for (QAction*
a :
menu.actions())
70 a->setIconVisibleInMenu(
true);
80 if (stateInstance->getParent())
82 stateInstance->getParent()->renameSubstate(stateInstance->getInstanceName(), d.
getStateInstanceName());
118 bool editable =
true;
120 stateInstance->getStateClass() &&
121 !stateInstance->getStateClass()->isEditable())
130 editState->setText(
"Edit State " + stateInstance->getInstanceName());
131 deleteState->setEnabled(!!parentState && parentState->isEditable());
132 setstartstate->setEnabled(!!parentState && parentState->isEditable());
137 openCode->setEnabled(!(!stateInstance->getStateClass() || (node && !node->getCppExists())));
140 newEndstate->setEnabled(!(stateInstance->getType() == eFinalState || stateInstance->getType() == eDynamicRemoteState)
141 && stateInstance->getStateClass()
142 && stateInstance->getStateClass()->isEditable());
145 layoutState->setEnabled(!(stateInstance->getType() == eFinalState
146 || stateInstance->getType() == eDynamicRemoteState
147 || !stateInstance->getStateClass()
148 || stateInstance->getStateClass()->getSubstates().size() <= 1));
153 QAction* result =
menu.exec(mouseScreenPos);
159 if (d.exec() == QDialog::Accepted)
168 parentState->removeSubstate(stateInstance);
177 parentState->setStartState(stateInstance);
184 const QString newStateNameBase =
"MyEndState";
185 QString newStateName = newStateNameBase;
187 while (!state->addEndSubstate(newStateName, newStateName, mouseItemPos))
189 newStateName = newStateNameBase +
"_" + QString::number(i);
194 else if (result ==
openCode && stateInstance->getStateClass())
201 treeController->selectNodeByState(stateInstance->getStateClass());
210 QAction* editTransition =
menu.addAction(
"Edit Transition " + transition->eventName);
211 QAction* enableTransitionCode =
menu.addAction(
"Enable Transition Hook for " + transition->eventName);
212 enableTransitionCode->setCheckable(
true);
213 enableTransitionCode->setChecked(transition->transitionUserCode);
218 if (!transition->destinationState || !transition->destinationState->getStateClass()
219 || !node || !node->getCppExists() || !transition->sourceState)
221 if (!node->getCppExists())
223 enableTransitionCode->setText(enableTransitionCode->text() +
" (no parent cpp)");
225 else if (!transition->sourceState)
227 enableTransitionCode->setText(
"Transition code unavailable for initial transition");
229 else if (transition->destinationState && !transition->destinationState->getStateClass())
231 enableTransitionCode->setText(enableTransitionCode->text() +
" (final or unloaded destination state)");
233 enableTransitionCode->setEnabled(
false);
236 QAction* detach =
menu.addAction(
"Detach Transition");
240 if (!transition->sourceState || !transition->destinationState)
242 detach->setEnabled(
false);
245 QAction* setSupportPoint {
nullptr};
246 std::map<QAction*, int> bendMap;
248 if (transition->sourceState && transition->destinationState)
251 bendMap.insert(std::make_pair(
menu.addAction(
"Straighten"), 0));
252 QMenu* bend =
menu.addMenu(
"Bend");
253 bendMap.insert(std::make_pair(bend->addAction(
"Bend Left 10%"), 10));
254 bendMap.insert(std::make_pair(bend->addAction(
"Bend Left 25%"), 25));
255 bendMap.insert(std::make_pair(bend->addAction(
"Bend Left 50%"), 50));
256 bendMap.insert(std::make_pair(bend->addAction(
"Bend Left 100%"), 100));
257 bendMap.insert(std::make_pair(bend->addAction(
"Bend Right 10%"), -10));
258 bendMap.insert(std::make_pair(bend->addAction(
"Bend Right 25%"), -25));
259 bendMap.insert(std::make_pair(bend->addAction(
"Bend Right 50%"), -50));
260 bendMap.insert(std::make_pair(bend->addAction(
"Bend Right 100%"), -100));
261 setSupportPoint =
menu.addAction(
"Set Support Point");
264 QAction* result =
menu.exec(mouseScreenPos);
269 if (result == editTransition)
271 if (transition->destinationState &&
272 transition->destinationState->getType() != eFinalState &&
273 !transition->destinationState->getStateClass())
275 QMessageBox::warning(
mainWindow,
"Transition Editing Error",
"Transition editing not possible because destination state is not loaded - load statechart group of destination state.");
282 if (d.exec() == QDialog::Accepted)
290 else if (result == detach)
292 state->detachTransitionDestination(transition);
298 else if (bendMap.find(result) != bendMap.end())
300 state->bendTransition(transition, 50, bendMap[result]);
302 else if (result == setSupportPoint)
306 if (d.exec() == QDialog::Accepted)
308 state->bendTransition(transition, d.
getU(), d.
getV());
311 else if (result == enableTransitionCode)
313 state->setTransitionUserCodeEnabled(transition, result->isChecked());
314 if (result->isChecked())
316 tipDialog->showMessage(
"Transition functions enable you to execute user code during a transition. This is designated for parameter conversion or minor calculations. Do NOT execute long running operations in transition functions.\n"
317 "On next saving of the statecharts a pure virtual function will be generated in the state of this transition. You need to implement this function. Otherwise a compilation error will occur.",
"Transition Function",
"TransitionFunction");
326 return QList<QString>();
329 QList<QString> result {QString::fromUtf8(
currentProfile->getName().c_str())};
332 while ((profile = profile->getParent()))
334 result.push_back(QString::fromUtf8(profile->getName().c_str()));
351 if (d.exec() == QDialog::Accepted)
360 item =
dynamic_cast<StateItem*
>(transitionItem->parentItem());
361 if (transitionItem && item)
365 if (d.exec() == QDialog::Accepted)
384 void StateEditorController::connectToStateTab(
int index)
389 connect(
mainWindow->
getStateTabWidget()->
currentStateview()->
getScene(), SIGNAL(transitionContextMenuRequested(
statechartmodel::TransitionCPtr,
statechartmodel::StatePtr, QPoint, QPointF)),
this, SLOT(
showTransitionContextMenu(
statechartmodel::TransitionCPtr,
statechartmodel::StatePtr, QPoint, QPointF)), Qt::UniqueConnection);
390 connect(
mainWindow->ui->actionShow_Subsubstates,
391 SIGNAL(toggled(
bool)),
393 SLOT(showSubSubstates(
bool)));