QElectroTech  0.70
xmlelementcollection.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef XMLELEMENTCOLLECTION_H
19 #define XMLELEMENTCOLLECTION_H
20 
21 #include <QObject>
22 #include <QDomElement>
23 #include "elementslocation.h"
24 
25 class QDomElement;
26 class QFile;
27 class QETProject;
28 
33 class XmlElementCollection : public QObject
34 {
35  Q_OBJECT
36 
37  public:
39  XmlElementCollection (const QDomElement &dom_element, QETProject *project);
40  QDomElement root() const;
41  QDomElement importCategory() const;
42  QDomNodeList childs(const QDomElement &parent_element) const;
43  QDomElement child(const QDomElement &parent_element, const QString &child_name) const;
44  QDomElement child(const QString &path) const;
45  QList<QDomElement> directories(const QDomElement &parent_element) const;
46  QStringList directoriesNames(const QDomElement &parent_element) const;
47  QList<QDomElement> elements(const QDomElement &parent_element) const;
48  QStringList elementsNames(const QDomElement &parent_element) const;
49  QDomElement element(const QString &path) const;
50  QDomElement directory(const QString &path) const;
51  QString addElement (ElementsLocation &location);
52  bool addElementDefinition (const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition);
53  bool removeElement(const QString& path);
54  ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, const QString& rename = QString(), bool deep_copy = true);
55  bool exist (const QString &path) const;
56  bool createDir (const QString& path, const QString& name, const NamesList &name_list);
57  bool removeDir (const QString& path);
58 
59  QList <ElementsLocation> elementsLocation (QDomElement dom_element = QDomElement(), bool childs = true) const;
60  ElementsLocation domToLocation(QDomElement dom_element) const;
61 
62  void cleanUnusedElement();
63  void cleanUnusedDirectory();
64 
65  private:
66  ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString& rename = QString(), bool deep_copy = true);
67  ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, const QString& rename = QString());
68 
69  signals:
75  void elementAdded(QString collection_path);
81  void elementChanged (QString collection_path);
87  void elementRemoved(QString collection_path);
93  void directorieAdded(QString collection_path);
99  void directoryRemoved(QString collection_path);
100 
101  private:
102  QDomDocument m_dom_document;
103  QETProject *m_project = nullptr;
104 };
105 
106 #endif // XMLELEMENTCOLLECTION_H
QStringList directoriesNames(const QDomElement &parent_element) const
XmlElementCollection::directoriesNames.
bool removeDir(const QString &path)
XmlElementCollection::removeDir Remove the directory at path .
ElementsLocation copy(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString(), bool deep_copy=true)
XmlElementCollection::copy Copy the content represented by source (an element or a directory) to dest...
void directorieAdded(QString collection_path)
directorieAdded This signal is emited when a directorie is added to this collection ...
bool createDir(const QString &path, const QString &name, const NamesList &name_list)
ElementsLocation domToLocation(QDomElement dom_element) const
XmlElementCollection::domToLocation Return the element location who represent the xml element : dom_e...
QDomElement child(const QDomElement &parent_element, const QString &child_name) const
XmlElementCollection::child If parent_element have child element with an attribute name = ...
void elementAdded(QString collection_path)
elementAdded This signal is emited when a element is added to this collection
QDomElement root() const
XmlElementCollection::root The root is the first DOM-Element the xml collection, the tag name of the ...
void cleanUnusedDirectory()
XmlElementCollection::cleanUnusedDirectory Remove the empty directories of this collection.
QStringList elementsNames(const QDomElement &parent_element) const
XmlElementCollection::elementsNames.
QDomElement element(const QString &path) const
XmlElementCollection::element.
bool exist(const QString &path) const
XmlElementCollection::exist Return true if the path exist in this collection.
QList< QDomElement > directories(const QDomElement &parent_element) const
XmlElementCollection::directories.
QList< ElementsLocation > elementsLocation(QDomElement dom_element=QDomElement(), bool childs=true) const
XmlElementCollection::elementsLocation Return all locations stored in dom_element (element and direct...
QList< QDomElement > elements(const QDomElement &parent_element) const
XmlElementCollection::elements.
void elementChanged(QString collection_path)
elementChanged This signal is emited when the defintion of the element at path was changed ...
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString())
XmlElementCollection::copyElement Copy the element represented by source to destination (must be a di...
QDomElement directory(const QString &path) const
XmlElementCollection::directory.
void elementRemoved(QString collection_path)
elementRemoved This signal is emited when an element is removed to this collection ...
void cleanUnusedElement()
XmlElementCollection::cleanUnusedElement Remove elements in this collection which is not used in the ...
bool removeElement(const QString &path)
XmlElementCollection::removeElement Remove the element at path .
QString addElement(ElementsLocation &location)
XmlElementCollection::addElement Add the element at location to this collection. The element is copie...
void directoryRemoved(QString collection_path)
directoryRemoved This signal is emited when a directory is removed to this collection ...
bool addElementDefinition(const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition)
XmlElementCollection::addElementDefinition Add the élément defintion in the directory at path with ...
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString(), bool deep_copy=true)
XmlElementCollection::copyDirectory Copy the directory represented by source to destination. if destination have a directory with the same name as source, then this directory is removed.
QDomNodeList childs(const QDomElement &parent_element) const
XmlElementCollection::childs.
The XmlElementCollection class This class represent a collection of elements stored to xml...
XmlElementCollection(QETProject *project)
XmlElementCollection::XmlElementCollection Build an empty collection. The collection start by : <coll...
QDomElement importCategory() const
XmlElementCollection::importCategory.