mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-24 03:10:52 +01:00
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:
@@ -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<QDomElement> 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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<path_list.size() ; i++)
|
||||
{
|
||||
QDomNodeList node_list = dom_element.elementsByTagName("category");
|
||||
if (node_list.isEmpty()) return QDomElement();
|
||||
|
||||
for (int j=0 ; j <node_list.size() ; j++)
|
||||
{
|
||||
QDomNode node = node_list.at(j);
|
||||
if (node.isElement())
|
||||
{
|
||||
QDomElement qde = node.toElement();
|
||||
if (qde.attribute("name") == path_list.at(i))
|
||||
{
|
||||
dom_element = node.toElement();
|
||||
j = node_list.size(); //Use to go out of the for loop
|
||||
}
|
||||
else if (j == node_list.size()-1)
|
||||
return QDomElement();
|
||||
}
|
||||
}
|
||||
QDomElement child_dom = child(parent_dom, path_list.at(i));
|
||||
if (child_dom.isNull()) return QDomElement();
|
||||
else parent_dom = child_dom;
|
||||
}
|
||||
|
||||
return dom_element;
|
||||
return parent_dom;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user