Minor improvement and remove some use of ElementsCollectionItem and ElementsDefinition

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4407 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-03-29 17:23:58 +00:00
parent dd5d9c9504
commit 95e309ff18
8 changed files with 44 additions and 128 deletions

View File

@@ -46,48 +46,29 @@
*/
CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
FixedElement(qgi),
elmt_state(-1),
location_(location),
forbid_antialiasing(false)
{
// recupere la definition de l'element
ElementsCollectionItem *element_item = QETApp::collectionItem(location);
ElementDefinition *element_definition;
if (
!element_item ||\
!element_item -> isElement() ||\
!(element_definition = qobject_cast<ElementDefinition *>(element_item))
) {
if(Q_UNLIKELY( !(location.isElement() && location.exist()) ))
{
if (state) *state = 1;
elmt_state = 1;
return;
}
if (!element_definition -> isReadable()) {
if (state) *state = 2;
elmt_state = 2;
return;
}
if (element_definition -> isNull()) {
if (state) *state = 3;
elmt_state = 3;
return;
}
//Start from empty lists.
//Start from empty lists.
list_lines_.clear();
list_rectangles_.clear();
list_circles_.clear();
list_polygons_.clear();
list_arcs_.clear();
buildFromXml(element_definition -> xml(), &elmt_state);
int elmt_state;
buildFromXml(location.xml(), &elmt_state);
if (state) *state = elmt_state;
if (elmt_state) return;
if (state) *state = 0;
elmt_state = 0;
}
/**
@@ -106,7 +87,8 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg
*/
bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element") {
if (xml_def_elmt.tagName() != "definition" || xml_def_elmt.attribute("type") != "element")
{
if (state) *state = 4;
return(false);
}

View File

@@ -45,7 +45,6 @@ class CustomElement : public FixedElement
// attributes
protected:
int elmt_state; // hold the error code in case the instanciation fails, or 0 if everything went well
NamesList names;
ElementsLocation location_;
QPicture drawing;
@@ -75,8 +74,6 @@ class CustomElement : public FixedElement
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
QString typeId() const;
ElementsLocation location() const;
bool isNull() const;
int state() const;
QString name() const;
ElementTextItem* taggedText(const QString &tagg) const;
@@ -114,30 +111,6 @@ inline ElementsLocation CustomElement::location() const {
return(location_);
}
/**
@return true if this element is null, i.e. if its XML description could not
be loaded.
*/
inline bool CustomElement::isNull() const {
return(elmt_state);
}
/**
@return An integer representing the state of this element:
- 0: instantiation succeeded
- 1: the file does not exist
- 2: the file could not be opened
- 3: The file is not a valid XML document
- 4: The XML document does not have a "definition" root element.
- 5: The definition attributes are missing or invalid
- 6: The definition is empty
- 7: The parsing of an XML element describing an element drawing primitive failed
- 8: No primitive could be loadedAucune partie du dessin n'a pu etre chargee
*/
inline int CustomElement::state() const {
return(elmt_state);
}
/**
@return The name of this element.
*/