#include <abstractelement.h>
Inheritance diagram for AbstractElement:

Public Member Functions | |
| virtual | ~AbstractElement () |
| virtual int | type () const=0 |
| virtual const QByteArray & | key () const=0 |
| virtual const QString & | title () const=0 |
| quint32 | instanceId () const |
| ElementDoc * | doc () const |
| AbstractController * | controller () const |
| QHash< int, AbstractElementAttribute * > | attributes () const |
| AbstractElementAttribute * | attribute (int type) const |
| template<class T> | |
| T * | attribute () const |
| QVariant | attributeData (int type) const |
| virtual const QSet< int > & | requiredAttributes () const |
| virtual const QSet< int > & | additionalAttributes () const |
| virtual QDomElement | domElement (QDomDocument &doc) const |
| virtual void | initFromDomElement (const QDomElement &e, InitModeFlags modeFlags) |
Protected Member Functions | |
| AbstractElement (quint32 instanceId, ElementDoc *abstractDoc) | |
| AbstractElement (ElementDoc *abstractDoc) | |
| void | addMissingRequiredAttributes () |
| bool | trySetAttributeData (int type, const QVariant &data) |
| virtual AbstractElementAttribute * | createAttribute (int type)=0 |
| virtual AbstractElementAttribute * | createAttribute (const QByteArray &key)=0 |
| virtual int | attributeKeyToType (const QByteArray &key)=0 |
| virtual void | customEvent (QEvent *e) |
| virtual void | dispatchEvent (MEvent *) |
| virtual void | attributeAddPtrEvent (MEAttributeAddPtrEvent *) |
| virtual void | attributeRemovePtrEvent (MEAttributeRemovePtrEvent *) |
An object cannot be instantiated from it directly, you must derive from it.
| AbstractElement::~AbstractElement | ( | ) | [virtual] |
Destroys the document element.
| AbstractElement::AbstractElement | ( | quint32 | instanceId, | |
| ElementDoc * | doc | |||
| ) | [protected] |
Constructs a graph element with a doc controller and a type.
Warning: The instanceId must be unique across the set of elements for the entire document. This is asserted if the doc is non-null.
The element will become a child of the doc in the QObject hierarchy, given that it's non-null.
Knowning who the doc is means that we can query it and post to its controller (using Doc::controller() ).
However, this does not assert that the doc is non-null, as there are circumstances where temporary elements need to be created that are parent-less.
| AbstractElement::AbstractElement | ( | ElementDoc * | doc | ) | [protected] |
Convenience constructor. It behaves essentially like the above function.
The instance ID is auto-generated using ElementDoc::genElementInstanceId() if the doc is non-null.
| virtual int AbstractElement::type | ( | ) | const [pure virtual] |
| virtual const QByteArray& AbstractElement::key | ( | ) | const [pure virtual] |
Having this method as pure-virtual forces sub-classes to implement it, which is a requirement for both it and ther other methods to work correctly.
Sub-classes must return their version of classKey().
Implements DomAccessibleState.
| virtual const QString& AbstractElement::title | ( | ) | const [pure virtual] |
| quint32 AbstractElement::instanceId | ( | ) | const [inline] |
| ElementDoc * AbstractElement::doc | ( | ) | const |
| AbstractController * AbstractElement::controller | ( | ) | const |
Convenience method.
Simply returns the value of doc()->controller().
| QHash< int, AbstractElementAttribute * > AbstractElement::attributes | ( | ) | const |
Returns a hash of attributes, where for each entry, the key is the attribute type and the value is a pointer to the corresponding attribute instance.
Using a hash instead of a list helps us to quickly find an instance for a given type of attribute, such as for editors/inspectors that are specific to a given type of attribute, for sub-classes that need to update an attribute of a given type, etc.
Note: This intentionally does not return a const ref, as to ensure thread safety. However, Qt's implicit sharing should help to maintain performance.
Note: The type is an int, as to aid extensibility.
| AbstractElementAttribute * AbstractElement::attribute | ( | int | type | ) | const |
Convenience method.
Returns the pointer to the element's attribute that has the given type.
Returns null if the attribute can't be found.
Note: The type is an int, as to aid extensibility.
| T * AbstractElement::attribute | ( | ) | const [inline] |
Convenience method.
Returns a pointer to the element's attribute for the given class (which dictates the type).
Returns null if the attribute can't be found.
| QVariant AbstractElement::attributeData | ( | int | type | ) | const |
Convenience method.
Returns value of the element's attribute that has the given type.
Returns an invalid variant if the attribute can't be found.
Note: The type is an int, as to aid extensibility.
| const QSet< int > & AbstractElement::requiredAttributes | ( | ) | const [virtual] |
Reimplemented in AbstractDiagramElement, DiagramGesture, DiagramPolygon, DiagramPolyline, DiagramShape, and DiagramText.
| const QSet< int > & AbstractElement::additionalAttributes | ( | ) | const [virtual] |
Reimplemented in AbstractDiagramElement, DiagramGesture, DiagramPolygon, DiagramPolyline, DiagramShape, and DiagramText.
| QDomElement AbstractElement::domElement | ( | QDomDocument & | doc | ) | const [virtual] |
Creates an XML QDomElement that represents the AbstractElement.
Use initFromDOMElement() to restore the AbstractElement state from the resulting QDomElement.
See also initFromDomElement().
Reimplemented from DomAccessibleState.
| void AbstractElement::initFromDomElement | ( | const QDomElement & | e, | |
| InitModeFlags | modeFlags | |||
| ) | [virtual] |
Restore the AbstractElement state from a QDomElement created by domElement().
This will remove any existing attributes first if modeFlags has its InitStructure bit set.
Note: This calls addMissingRequiredAttributes() before returning, as to ensure that the element is in a "safe state". This is very helpful for when a file is loaded that was created using an older version of the software that had a requiredAttributes() set that was different in some way to the current set (e.g. because new features where added).
Important: Because the exact set of classes dervied from AbstractElementAttribute that can be used with the given sub-classed AbstractElement varies, the creation of the (AbstractElementAttribute derived) attributes is left up to AbstractElement's sub-classes. This is performed via calls to createAttribute(), which must be implemented in sub-classes.
Note: Returns immediately if e.tagName() != key().
See also domElement() and DomAccessibleState::initFromDomElement().
Reimplemented from DomAccessibleState.
| void AbstractElement::addMissingRequiredAttributes | ( | ) | [protected] |
This will create and add an instance of each attribute type that is listed by requiredAttributes() that is currently not in the attributes() collection.
Warning: This can't be called by the AbstractElement's constructors, as it relies on the sub-class' v-table to have been created, as it calls requiredAttributes() and createAttribute(), which are (pure-)virtual in this class. Hence, it must be called by the sub-class' constructor().
| bool AbstractElement::trySetAttributeData | ( | int | type, | |
| const QVariant & | data | |||
| ) | [protected] |
This convenience method will try to set the data for a given attribute type. If the attribute is found, the data will be set and this will return true, otheriwise this will return false.
This will also return false if the attribute's setData() method fails.
| virtual AbstractElementAttribute* AbstractElement::createAttribute | ( | int | type | ) | [protected, pure virtual] |
Note: The type is an int, as to aid extensibility.
Implemented in AbstractDiagramElement.
| virtual AbstractElementAttribute* AbstractElement::createAttribute | ( | const QByteArray & | key | ) | [protected, pure virtual] |
Implemented in AbstractDiagramElement.
| virtual int AbstractElement::attributeKeyToType | ( | const QByteArray & | key | ) | [protected, pure virtual] |
Implemented in AbstractDiagramElement.
| virtual void AbstractElement::customEvent | ( | QEvent * | e | ) | [inline, protected, virtual] |
| void AbstractElement::dispatchEvent | ( | MEvent * | event | ) | [protected, virtual] |
The elements's event dispatcher.
Receives events and then passes them off to be processed by appropiate (virtual) methods.
Warning: It is assumed that the events have their correct type set (as it uses static casts).
Asserts that the event is non-null.
Reimplemented in AbstractDiagramElement.
| void AbstractElement::attributeAddPtrEvent | ( | MEAttributeAddPtrEvent * | e | ) | [protected, virtual] |
Appends an attribute to the element's internal list.
Warning! At this level, multiple attributes of the same type may be added - as some applications may require this.
Asserts that the event (e) and the attribute pointer in it are both non-null.
| void AbstractElement::attributeRemovePtrEvent | ( | MEAttributeRemovePtrEvent * | e | ) | [protected, virtual] |
This WON'T delete the attribute (as in won't free its memory). All memory (de)allocation is to be handled by the document's controller (e.g. ElementDocController). This is so that the controller can remove the pointer from the document (by calling this method) and THEN update the views (which may still refer to attribute), followed by calling deleteLater() on the attribute.
Asserts that the event (e) and the attribute pointer in it are both non-null.
1.5.2