diff --git a/sources/ElementsCollection/elementslocation.cpp b/sources/ElementsCollection/elementslocation.cpp index 5451213ac..bc3d096a8 100644 --- a/sources/ElementsCollection/elementslocation.cpp +++ b/sources/ElementsCollection/elementslocation.cpp @@ -57,10 +57,7 @@ ElementsLocation::~ElementsLocation() { ElementsLocation::ElementsLocation(const ElementsLocation &other) : m_collection_path(other.m_collection_path), m_file_system_path(other.m_file_system_path), - m_project(other.m_project), - m_xml(other.m_xml), - m_uuid(other.m_uuid), - m_icon(other.m_icon) + m_project(other.m_project) {} /** @@ -84,9 +81,6 @@ ElementsLocation &ElementsLocation::operator=(const ElementsLocation &other) { m_collection_path = other.m_collection_path; m_file_system_path = other.m_file_system_path; m_project = other.m_project; - m_xml = other.m_xml; - m_uuid = other.m_uuid; - m_icon = other.m_icon; return(*this); } @@ -491,17 +485,14 @@ NamesList ElementsLocation::nameList() * @return The definition of this element. * The definition can be null. */ -QDomElement ElementsLocation::xml() +QDomElement ElementsLocation::xml() const { - if (!m_xml.isNull()) - return m_xml; - if (!m_project) { QFile file (m_file_system_path); QDomDocument docu; if (docu.setContent(&file)) - m_xml = docu.documentElement().cloneNode().toElement(); + return docu.documentElement().cloneNode().toElement(); } else { @@ -509,33 +500,32 @@ QDomElement ElementsLocation::xml() if (isElement()) { QDomElement element = m_project->embeddedElementCollection()->element(str.remove("embed://")); - m_xml = element.firstChildElement("definition"); + return element.firstChildElement("definition"); } else { QDomElement element = m_project->embeddedElementCollection()->directory(str.remove("embed://")); - m_xml = element; + return element; } } - return m_xml; + return QDomElement(); } /** * @brief ElementsLocation::uuid * @return The uuid of the pointed element + * Uuid can be null */ -QUuid ElementsLocation::uuid() +QUuid ElementsLocation::uuid() const { - if (!m_uuid.isNull()) return m_uuid; - //Get the uuid of element QList list_ = QET::findInDomElement(xml(), "uuid"); if (!list_.isEmpty()) - m_uuid = QUuid(list_.first().attribute("uuid")); + return QUuid(list_.first().attribute("uuid")); - return m_uuid; + return QUuid(); } /** @@ -543,15 +533,14 @@ QUuid ElementsLocation::uuid() * @return The icon of the represented element. * If icon can't be set, return a null QIcon */ -QIcon ElementsLocation::icon() +QIcon ElementsLocation::icon() const { - if (!m_icon.isNull()) return m_icon; - if (!m_project) { ElementsCollectionCache *cache = QETApp::collectionCache(); - if (cache->fetchElement(*this)) - m_icon = QIcon(cache->pixmap()); + ElementsLocation loc(*this); //Make a copy of this to keep this method const + if (cache->fetchElement(loc)) + return QIcon(cache->pixmap()); } else { @@ -560,22 +549,23 @@ QIcon ElementsLocation::icon() Element *elmt = factory->createElement(*this, 0, &state); if (state == 0) - m_icon = QIcon(elmt->pixmap()); + return QIcon(elmt->pixmap()); } - return m_icon; + return QIcon(); } /** * @brief ElementLocation::name * @return The name of the represented element in the current local */ -QString ElementsLocation::name() +QString ElementsLocation::name() const { if (!m_project) { ElementsCollectionCache *cache = QETApp::collectionCache(); - if (cache->fetchElement(*this)) + ElementsLocation loc(*this); //Make a copy of this to keep this method const + if (cache->fetchElement(loc)) return cache->name(); else return QString(); diff --git a/sources/ElementsCollection/elementslocation.h b/sources/ElementsCollection/elementslocation.h index 68b4622c8..1218d18fd 100644 --- a/sources/ElementsCollection/elementslocation.h +++ b/sources/ElementsCollection/elementslocation.h @@ -67,19 +67,16 @@ class ElementsLocation XmlElementCollection *projectCollection() const; NamesList nameList(); - QDomElement xml(); - QUuid uuid(); - QIcon icon(); - QString name(); + QDomElement xml() const; + QUuid uuid() const; + QIcon icon() const; + QString name() const; QString fileName() const; private: QString m_collection_path; QString m_file_system_path; QETProject *m_project = nullptr; - QDomElement m_xml; - QUuid m_uuid; - QIcon m_icon; public: static int MetaTypeId; ///< Id of the corresponding Qt meta type diff --git a/sources/ElementsCollection/xmlelementcollection.cpp b/sources/ElementsCollection/xmlelementcollection.cpp index 29bdacd0e..04b0e08d5 100644 --- a/sources/ElementsCollection/xmlelementcollection.cpp +++ b/sources/ElementsCollection/xmlelementcollection.cpp @@ -285,31 +285,16 @@ QDomElement XmlElementCollection::element(const QString &path) QDomElement XmlElementCollection::directory(const QString &path) { QStringList path_list = path.split("/"); - QDomElement dom_element = m_dom_document.documentElement(); + QDomElement parent_dom = m_dom_document.documentElement(); for (int i=0 ; i. */ #include "diagrameventaddelement.h" -#include "elementscollectionitem.h" -#include "qetapp.h" #include "integrationmoveelementshandler.h" #include "elementfactory.h" #include "diagram.h" @@ -39,8 +37,7 @@ DiagramEventAddElement::DiagramEventAddElement(ElementsLocation &location, Diagr m_element(nullptr) { //Check if there is an element at this location - ElementsCollectionItem *item = QETApp::collectionItem(location); - if (item) + if (location.isElement() && location.exist()) { //location is an element, we build it, if build fail, //m_running stay to false (by default), so this interface will be deleted at next event diff --git a/sources/factory/elementfactory.cpp b/sources/factory/elementfactory.cpp index 8a3dccc4c..0484d9ee9 100644 --- a/sources/factory/elementfactory.cpp +++ b/sources/factory/elementfactory.cpp @@ -16,9 +16,6 @@ along with QElectroTech. If not, see . */ #include "elementfactory.h" -#include "elementdefinition.h" -#include "elementscollectionitem.h" -#include "qetapp.h" #include "QDomElement" #include "simpleelement.h" #include "reportelement.h" @@ -26,7 +23,7 @@ #include "slaveelement.h" #include "terminalelement.h" -ElementFactory* ElementFactory::factory_ = 0; +ElementFactory* ElementFactory::factory_ = nullptr; /** * @brief ElementFactory::createElement * @param location create element at this location @@ -36,20 +33,16 @@ ElementFactory* ElementFactory::factory_ = 0; */ Element * ElementFactory::createElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) { - // 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(element_item))) + if (Q_UNLIKELY( !(location.isElement() && location.exist()) )) { - if (state) *state = 1; - return 0; + if (state) + *state = 1; + return nullptr; } - if (element_definition->xml().hasAttribute("link_type")) + if (location.xml().hasAttribute("link_type")) { - QString link_type = element_definition->xml().attribute("link_type"); + QString link_type = location.xml().attribute("link_type"); if (link_type == "next_report" || link_type == "previous_report") return (new ReportElement(location, link_type, qgi, state)); if (link_type == "master") return (new MasterElement (location, qgi, state)); if (link_type == "slave") return (new SlaveElement (location, qgi, state)); diff --git a/sources/factory/elementfactory.h b/sources/factory/elementfactory.h index 84c6cdd18..fdb0c0ab5 100644 --- a/sources/factory/elementfactory.h +++ b/sources/factory/elementfactory.h @@ -23,7 +23,6 @@ class Element; class ElementsLocation; class QGraphicsItem; -class Diagram; /** * @brief The ElementFactory class diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index 352753a8d..1795861bc 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -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(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); } diff --git a/sources/qetgraphicsitem/customelement.h b/sources/qetgraphicsitem/customelement.h index c9c82081b..fe61519cb 100644 --- a/sources/qetgraphicsitem/customelement.h +++ b/sources/qetgraphicsitem/customelement.h @@ -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. */