mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-02-07 14:59:58 +01:00
Remove the use of ElementsCollectionItem and ElementDefinition from qetelementeditor class
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4413 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -61,6 +61,7 @@ class ElementCollectionItem : public QObject
|
||||
int row() const;
|
||||
virtual QString name();
|
||||
virtual QString collectionName() const;
|
||||
virtual QString collectionPath() const {return QString();}
|
||||
|
||||
virtual bool isDir() const;
|
||||
virtual bool isElement() const;
|
||||
|
||||
@@ -240,11 +240,9 @@ void ElementsCollectionWidget::editElement()
|
||||
{
|
||||
ElementCollectionItem *eci = elementCollectionItemForIndex(m_index_at_context_menu);
|
||||
|
||||
if (!eci ||
|
||||
!eci->isElement() ||
|
||||
(eci->type() != FileElementCollectionItem::Type)) return;
|
||||
if ( !(eci && eci->isElement()) ) return;
|
||||
|
||||
ElementsLocation location(static_cast<FileElementCollectionItem*>(eci)->collectionPath());
|
||||
ElementsLocation location(eci->collectionPath());
|
||||
|
||||
QETApp *app = QETApp::instance();
|
||||
app->openElementLocations(QList<ElementsLocation>() << location);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "elementscollectioncache.h"
|
||||
#include "elementfactory.h"
|
||||
#include "element.h"
|
||||
#include "qetxml.h"
|
||||
|
||||
// make this class usable with QVariant
|
||||
int ElementsLocation::MetaTypeId = qRegisterMetaType<ElementsLocation>("ElementsLocation");
|
||||
@@ -430,6 +431,24 @@ bool ElementsLocation::exist() const
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::isWritable
|
||||
* @return True if this element can be writable (can use set xml)
|
||||
*/
|
||||
bool ElementsLocation::isWritable() const
|
||||
{
|
||||
if (m_project)
|
||||
return !m_project->isReadOnly();
|
||||
else if (isFileSystem())
|
||||
{
|
||||
if (fileSystemPath().startsWith(QETApp::commonElementsDirN()))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::projectCollection
|
||||
* @return If this location represente a item in an embedded project collection, return this collection
|
||||
@@ -492,7 +511,7 @@ QDomElement ElementsLocation::xml() const
|
||||
QFile file (m_file_system_path);
|
||||
QDomDocument docu;
|
||||
if (docu.setContent(&file))
|
||||
return docu.documentElement().cloneNode().toElement();
|
||||
return docu.documentElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -512,6 +531,51 @@ QDomElement ElementsLocation::xml() const
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::setXml
|
||||
* Replace the current xml description by @xml_element;
|
||||
* The document element of @xml_document must have tagname "definition" to be written
|
||||
* This definition must be writable
|
||||
* @param xml_element
|
||||
* @return true if success
|
||||
*/
|
||||
bool ElementsLocation::setXml(const QDomDocument &xml_document) const
|
||||
{
|
||||
if (!isWritable())
|
||||
return false;
|
||||
|
||||
if (xml_document.documentElement().tagName() != "definition")
|
||||
{
|
||||
qDebug() << "ElementsLocation::setXml : tag name of document element isn't 'definition'";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isFileSystem())
|
||||
{
|
||||
QString error;
|
||||
QETXML::writeXmlFile(xml_document, fileSystemPath(), &error);
|
||||
|
||||
if (!error.isEmpty())
|
||||
{
|
||||
qDebug() << "ElementsLocation::setXml error : " << error;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else if (isProject() && exist())
|
||||
{
|
||||
QDomElement dom_element = xml();
|
||||
QDomNode parent_node = dom_element.parentNode();
|
||||
parent_node.removeChild(dom_element);
|
||||
parent_node.appendChild(xml_document.documentElement().cloneNode(true));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::uuid
|
||||
* @return The uuid of the pointed element
|
||||
|
||||
@@ -63,11 +63,13 @@ class ElementsLocation
|
||||
bool isFileSystem() const;
|
||||
bool isProject() const;
|
||||
bool exist() const;
|
||||
bool isWritable() const;
|
||||
|
||||
XmlElementCollection *projectCollection() const;
|
||||
NamesList nameList();
|
||||
|
||||
QDomElement xml() const;
|
||||
bool setXml(const QDomDocument &xml_document) const;
|
||||
QUuid uuid() const;
|
||||
QIcon icon() const;
|
||||
QString name() const;
|
||||
|
||||
@@ -102,6 +102,12 @@ QVariant XmlProjectElementCollectionItem::data(int column, int role)
|
||||
}
|
||||
}
|
||||
|
||||
void XmlProjectElementCollectionItem::clearData()
|
||||
{
|
||||
m_icon = QIcon();
|
||||
ElementCollectionItem::clearData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlProjectElementCollectionItem::mimeData
|
||||
* @return The mimedata of this item
|
||||
|
||||
@@ -44,6 +44,7 @@ class XmlProjectElementCollectionItem : public ElementCollectionItem
|
||||
virtual int type() const {return Type;}
|
||||
|
||||
virtual QVariant data(int column, int role);
|
||||
virtual void clearData();
|
||||
virtual QMimeData *mimeData();
|
||||
virtual bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column) const;
|
||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column);
|
||||
|
||||
Reference in New Issue
Block a user