Esempio n. 1
0
/**
 * @brief SCGraphicsView::handleNewState
 * @param newState
 *
 * generic add state for the graphics view:
 * called when the insert state button is pressed to create a new state graphic and when loading the xml states
 *
 * scformview::insertState -> scdatamodel::insertNewState, emit newStateSignal -> scgraphicsview::handleNewState
 * connected to signal newStateSignal in the SCDataModel
 *
 * will add a state to the graphics view
 *
 */
void SCGraphicsView::handleNewState (SCState *newState)
{
    qDebug () << "SCGraphicsView::handleNewState";
    static int zVal = 0;
    // SCState connects

    // connectState(newState);

    StateString * type = dynamic_cast<StateString *> ( newState->attributes.value("type"));
    if ( type != 0 && (type->asString() == "machine"))
        return; // don't draw a picture for the top-level machine

    SCState * parentState = 0;
    StateBoxGraphic * parentGraphic =0;
    StateBoxGraphic * stateGraphic = 0;

    parentState = dynamic_cast<SCState *>(newState->parent());

    if (_mapStateToGraphic.contains(parentState))
    {
        parentGraphic =   _mapStateToGraphic[parentState];
    }



    // after the reference has been set through the construction
    // of the stateboxgraphic, the graphic and the model
    // will be linked internally. e.g. setting the size of the graphic
    // will set the size of the model and vice versa

    // create the stateboxgraphic
    stateGraphic = new StateBoxGraphic(parentGraphic, newState);

    //
    // if a parent state is a parallel state, then its children run in parallel.
    // this is show by the children being drawn with dotted lines. So inform
    // the children to watch the parent's isParallelAttribute
    //

    // new states will be on top
    stateGraphic->setZValue(zVal++);

    // set the name
    stateGraphic->setObjectName(newState->objectName());
    //stateGraphic->setPos(newState->attributes.value("position"));
    //stateGraphic->setSize(newState->attributes.value("size"));

    // connect the state graphic's deconstructor to do removal protocol in the graphics view
    connectState(newState,stateGraphic);
//connect(stateGraphic, SIGNAL(destroyed(QObject*)), this, SLOT(handleStateGraphicDeleted(QObject*)));

    // quick look up of graphics from state model references
    // link the SCState and StateBoxGraphic
    _mapStateToGraphic.insert(newState, stateGraphic);
    _hashStateToGraphic.insert(newState,stateGraphic);

    // load size and position from state model
    PositionAttribute * position = dynamic_cast<PositionAttribute*> (newState->attributes.value("position"));
    stateGraphic->setPos(position->asPointF());
    //qDebug() << "pos : " << position->asString();
    //SelectableTextBlock stateTextBlock = stateGraphic->TextItem;
    //PositionAttribute * tbPosition = dynamic_cast<PositionAttribute*> (stateTextBlock.att);

    SizeAttribute * size = dynamic_cast<SizeAttribute*> (newState->attributes.value("size"));
    stateGraphic->setSize(size->asPointF());
    if ( ! parentGraphic )
    {
        _scene->addItem(stateGraphic);
    }

    // make the parent bigger to hold this state
    // and since its bigger, make its parent bigger.....
   // increaseSizeOfAllAncestors (newState);


    // load the text blocks

    // reposition the text items after loading their text
    stateGraphic->updateElements();

}
Esempio n. 2
0
SizeAttribute::SizeAttribute(const SizeAttribute& sa):IAttribute(sa), _size(sa.asPointF())
{
    qRegisterMetaType<SizeAttribute>("SizeAttribute");
}