Download Diplom 2011
Transcript
IMPLEMENTIERUNG DES STATE CHART EDITORS
den Elementen wird der logische Teil erstellt, mit dem graphischen Element verlinkt und
anschliessend dem Modell hinzugefügt.
Am Ende wird die Vorschau der Transition verworfen.
void Diagram::mouseReleaseAddConnection( QGraphicsSceneMouseEvent * mouseEvent )
{
Editor* editor = Editor::instance();
DiagramItem* to = NULL;
...
// if source and destination are available and destination type is ok,
// then create connection
if( editor->from() &&
to &&
to->parentRegion() == editor->from()->parentRegion() &&
to != editor->from() &&
( to->type() == DiagramItem::StateType ||
to->type() == DiagramItem::ConditionStateType ||
to->type() == DiagramItem::TerminateStateType ) )
{
...
// if destination has no parent, add connection to scene
if( to->parentRegion() == NULL )
{
Transition* transition = new Transition(editor->from(),
*editor->connectionStart(),
to, mouseEvent->scenePos());
...
addItem(transition);
// add transition to data model
TransitionItem* t = new TransitionItem(transition->uuid());
transition->setDataItem(t);
t->setSourceTarget(editor->from()->dataItem(), to->dataItem());
dataModel->addItem(this->dataItem(), t);
...
}
// if destination has parent, add connection to the parent
else
{
State* parentState = dynamic_cast<State*>(to->parentItem());
Region* parentRegion = NULL;
if( parentState )
{
parentRegion = to->parentRegion();
}
if( parentState && parentRegion )
{
Transition* transition
= new Transition(editor->from(),
parentState->mapFromScene(*editor->connectionStart()),
to, parentState->mapFromScene(mouseEvent->scenePos()));
...
parentRegion->addConnectionItem(transition);
transition->setParents(parentState, parentRegion);
}
}
}
// add transition to data model
TransitionItem* t = new TransitionItem(transition->uuid());
transition->setDataItem(t);
t->setSourceTarget(editor->from()->dataItem(), to->dataItem());
dataModel->addItem(parentRegion->dataItem(), t);
...
}
...
mouseEvent->accept();
......................................................................................................................................................................................................
58 / 80