mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-11 00:29:57 +01:00
ElementsCategoryEditor : remove the use of ElementsCategory
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4475 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -298,3 +298,117 @@ ElementsLocation ElementCollectionHandler::copy(ElementsLocation &source, Elemen
|
||||
else
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementCollectionHandler::createDir
|
||||
* Create a directorie with name @name as child of @parent.
|
||||
* Parent must be a directory
|
||||
* @param parent : parent of the dir to create
|
||||
* @param name : name of directorie to create
|
||||
* @param name_list : translations of the directorie name
|
||||
* @return : ElementsLocation that represent the new directorie, location can be null if an error was occured
|
||||
*/
|
||||
ElementsLocation ElementCollectionHandler::createDir(ElementsLocation &parent, const QString &name, const NamesList &name_list)
|
||||
{
|
||||
//Parent must be a directorie and writable
|
||||
if (!(parent.isDirectory() && parent.isWritable() && parent.exist())) {
|
||||
qDebug() << "ElementCollectionHandler::createDir : the prerequisites are not valid. " << parent;
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
//Directorie to create must not already exist
|
||||
ElementsLocation created_dir = parent;
|
||||
created_dir.addToPath(name);
|
||||
if (created_dir.exist()) {
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
//Location is a file system
|
||||
if (parent.isFileSystem()) {
|
||||
|
||||
QDir parent_dir(parent.fileSystemPath());
|
||||
|
||||
if (parent_dir.mkdir(name)) {
|
||||
//Create the qet-directory file
|
||||
QDomDocument document;
|
||||
QDomElement root = document.createElement("qet-directory");
|
||||
document.appendChild(root);
|
||||
root.appendChild(name_list.toXml(document));
|
||||
|
||||
QString filepath = created_dir.fileSystemPath() + "/qet_directory";
|
||||
if (!QET::writeXmlFile(document, filepath)) {
|
||||
qDebug() << "ElementCollectionHandler::createDir : write qet-directory file failed";
|
||||
}
|
||||
return created_dir;
|
||||
}
|
||||
else {
|
||||
qDebug() << "ElementCollectionHandler::createDir : error was occured at creation of new directories in file system. ";
|
||||
return ElementsLocation();
|
||||
}
|
||||
}
|
||||
else if (parent.isProject()) {
|
||||
XmlElementCollection *xmlec = parent.projectCollection();
|
||||
if (xmlec->createDir(parent.collectionPath(false), name, name_list)) {
|
||||
return created_dir;
|
||||
}
|
||||
else {
|
||||
qDebug() << "ElementCollectionHandler::createDir : error was occured at creation of new directories in embbeded collection.";
|
||||
return ElementsLocation();
|
||||
}
|
||||
}
|
||||
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementCollectionHandler::setNames
|
||||
* Set the names stored in @name_list as the names of the item represented by location
|
||||
* @param location : location to change the names
|
||||
* @param name_list : NamesList to use
|
||||
* @return return true if success
|
||||
*/
|
||||
bool ElementCollectionHandler::setNames(ElementsLocation &location, const NamesList &name_list)
|
||||
{
|
||||
if ( !(location.exist() && location.isWritable()) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (location.isFileSystem()) {
|
||||
if (location.isDirectory()) {
|
||||
QDomDocument document;
|
||||
QDomElement root = document.createElement("qet-directory");
|
||||
document.appendChild(root);
|
||||
root.appendChild(name_list.toXml(document));
|
||||
|
||||
QString filepath = location.fileSystemPath() + "/qet_directory";
|
||||
if (!QET::writeXmlFile(document, filepath)) {
|
||||
qDebug() << "ElementCollectionHandler::setNames : write qet-directory file failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (location.isElement()) {
|
||||
QDomDocument document;
|
||||
document.appendChild(document.importNode(location.xml(), true));
|
||||
if (document.isNull()) {
|
||||
qDebug() << "ElementCollectionHandler::setNames : failed to load xml document from file";
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement document_element = document.documentElement();
|
||||
document_element.replaceChild(name_list.toXml(document), document_element.firstChildElement("names"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (location.isProject()) {
|
||||
QDomElement element = location.xml();
|
||||
QDomDocument document = element.ownerDocument();
|
||||
element.replaceChild(name_list.toXml(document), element.firstChildElement("names"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define ELEMENTCOLLECTIONHANDLER_H
|
||||
|
||||
#include "elementslocation.h"
|
||||
#include "nameslist.h"
|
||||
|
||||
class QWidget;
|
||||
|
||||
@@ -90,6 +91,8 @@ class ElementCollectionHandler
|
||||
~ElementCollectionHandler();
|
||||
|
||||
ElementsLocation copy(ElementsLocation &source, ElementsLocation &destination);
|
||||
ElementsLocation createDir(ElementsLocation &parent, const QString &name, const NamesList &name_list);
|
||||
bool setNames(ElementsLocation &location, const NamesList &name_list);
|
||||
|
||||
private:
|
||||
ECHStrategy *m_strategy = nullptr;
|
||||
|
||||
@@ -335,8 +335,9 @@ void ElementsCollectionWidget::editDirectory()
|
||||
|
||||
ElementsLocation location(feci->collectionPath());
|
||||
ElementsCategoryEditor ece(location, true, this);
|
||||
|
||||
if (ece.exec() == QDialog::Accepted)
|
||||
reload();
|
||||
eci->clearData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -495,7 +495,7 @@ NamesList ElementsLocation::nameList()
|
||||
|
||||
/**
|
||||
* @brief ElementsLocation::xml
|
||||
* @return The definition of this element.
|
||||
* @return The definition of this element or directory.
|
||||
* The definition can be null.
|
||||
*/
|
||||
QDomElement ElementsLocation::xml() const
|
||||
|
||||
@@ -465,6 +465,40 @@ bool XmlElementCollection::exist(const QString &path)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::createDir
|
||||
* Create a child directorie at path @path with the name @name.
|
||||
* Emit directorieAdded if success.
|
||||
* @param path : path of parent diectorie
|
||||
* @param name : name of the directori to create.
|
||||
* @param name_list : translation of the directorie name.
|
||||
* @return true if creation success, if directorie already exist return true.
|
||||
*/
|
||||
bool XmlElementCollection::createDir(QString path, QString name, const NamesList &name_list)
|
||||
{
|
||||
QString new_dir_path = path + "/" + name;
|
||||
|
||||
if (!directory(new_dir_path).isNull()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QDomElement parent_dir = directory(path);
|
||||
if (parent_dir.isNull()) {
|
||||
qDebug() << "XmlElementCollection::createDir : directorie at path doesn't exist";
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomElement new_dir = m_dom_document.createElement("category");
|
||||
new_dir.setAttribute("name", name);
|
||||
new_dir.appendChild(name_list.toXml(m_dom_document));
|
||||
|
||||
parent_dir.appendChild(new_dir);
|
||||
|
||||
emit directorieAdded(new_dir_path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::copyDirectory
|
||||
* Copy the directory represented by source to destination.
|
||||
|
||||
@@ -50,6 +50,7 @@ class XmlElementCollection : public QObject
|
||||
bool addElementDefinition (const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition);
|
||||
ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
bool exist (const QString &path);
|
||||
bool createDir (QString path, QString name, const NamesList &name_list);
|
||||
|
||||
private:
|
||||
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
@@ -68,8 +69,12 @@ class XmlElementCollection : public QObject
|
||||
* @param collection_path, the path of this element in this collection
|
||||
*/
|
||||
void elementChanged (QString collection_path);
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief directorieAdded
|
||||
* This signal is emited when a directorie is added to this collection
|
||||
* @param collection_path, the path of the new directorie
|
||||
*/
|
||||
void directorieAdded(QString collection_path);
|
||||
|
||||
private:
|
||||
QDomDocument m_dom_document;
|
||||
|
||||
Reference in New Issue
Block a user