Classes

Attributes
[DataModel]

Collaboration diagram for Attributes:

Classes

class  IAttribute
 This is the base abstract class for state and transition attributes. More...
class  IAttributeContainer
 This is the base abstract class for state and transition attribute containers. More...
class  StateAttributes
class  StateIDTextBlockAttributes
class  TransitionAttributes

Detailed Description

Attributes are intented to be contained in IAttributeContainer-s.

Elements of a state chart are states and state transitions. Each of these elements have attributes. In addition, states and transitions can have sub elements such as commentary text. Each sub element may have attributes.

Examples of attributes are a state's ID, state type (initial, final, etc), a state's graphical position, size.

The data model holds a reference to the top-level state (class SCState). The top level state is also known as the state-machine. The top level state holds an attribute container for its attributes as well as a QList of substates and a QList of transitions which are sourced from that state.

Attributes must subclass IAttribute and implement asString(), setValue().

Generally, a view can query attribute containers for attributes, then query attributes for their values using asString().

Below is an example of generic attribute handling from the FormView, which loads the attribute table view when a state or transition is clicked in the tree-view.

Notes on State and Transition Identifiers

    // get an interator to the IAttributeContainer which is define as Map of key strings and IAttribute pointers.
    //  the key strings are the attribute id's or names, for example "name", "path", "size", "pos", "target".

    QMapIterator<QString,IAttribute*> i(*attributes);

    while (i.hasNext())
    {
        QString key  = i.next().key(); // get the key for this attribute, e.g. 'name', 'path', 'size', etc

        IAttribute* attr = attributes->value(key)  ;// get the map value, which is the IAttribute pointer

        // all IAttributes have a changed signal, so connect to it so we can be notified if another view changes
        // the value while we are displaying it here in this view, so we can update our view

        connect ( attr, SIGNAL(changed(IAttribute*)), this, SLOT(handlePropertyChanged(IAttribute*)));

        // create a table entry for this attribute

        QTableWidgetItem * propName = new QTableWidgetItem(key);

        propName->setFlags( (propName->flags() & (~Qt::ItemIsEditable)) | ((Qt::ItemIsEnabled)));

        // load the table entry with the attribute's value as a string

        QTableWidgetItem * propValue = new QTableWidgetItem(attr->asString());

        propValue->setFlags(propValue->flags() | (Qt::ItemIsEditable) | (Qt::ItemIsEnabled));

        // the table has two columns, one with the property (attribute) key and the other with the value

        propertyTable->setItem(row, 0, propName);
        propertyTable->setItem(row++, 1, propValue);

    }