QElectroTech  0.8-dev
xmlelementcollection.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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,
40  QETProject *project);
41  QDomElement root() const;
42  QDomElement importCategory() const;
43  QDomNodeList childs(const QDomElement &parent_element) const;
44  QDomElement child(const QDomElement &parent_element,
45  const QString &child_name) const;
46  QDomElement child(const QString &path) const;
47  QList<QDomElement> directories(
48  const QDomElement &parent_element) const;
49  QStringList directoriesNames(
50  const QDomElement &parent_element) const;
51  QList<QDomElement> elements(
52  const QDomElement &parent_element) const;
53  QStringList elementsNames(
54  const QDomElement &parent_element) const;
55  QDomElement element(const QString &path) const;
56  QDomElement directory(const QString &path) const;
57  QString addElement (ElementsLocation &location);
58  bool addElementDefinition (const QString &dir_path,
59  const QString &elmt_name,
60  const QDomElement &xml_definition);
61  bool removeElement(const QString& path);
63  ElementsLocation &destination,
64  const QString& rename = QString(),
65  bool deep_copy = true);
66  bool exist (const QString &path) const;
67  bool createDir (const QString& path,
68  const QString& name,
69  const NamesList &name_list);
70  bool removeDir (const QString& path);
71 
72  QList <ElementsLocation> elementsLocation (
73  QDomElement dom_element = QDomElement(),
74  bool childs = true) const;
75  ElementsLocation domToLocation(QDomElement dom_element) const;
76 
77  void cleanUnusedElement();
78  void cleanUnusedDirectory();
79 
80  private:
82  ElementsLocation &source,
83  ElementsLocation &destination,
84  const QString& rename = QString(),
85  bool deep_copy = true);
87  ElementsLocation &destination,
88  const QString& rename = QString());
89 
90  signals:
96  void elementAdded(QString collection_path);
102  void elementChanged (QString collection_path);
108  void elementRemoved(QString collection_path);
114  void directorieAdded(QString collection_path);
120  void directoryRemoved(QString collection_path);
121 
122  private:
123  QDomDocument m_dom_document;
124  QETProject *m_project = nullptr;
125 };
126 
127 #endif // XMLELEMENTCOLLECTION_H
ElementsLocation::exist
bool exist() const
ElementsLocation::exist.
Definition: elementslocation.cpp:472
XmlElementCollection::createDir
bool createDir(const QString &path, const QString &name, const NamesList &name_list)
XmlElementCollection::createDir Create a child directorie at path path with the name name....
Definition: xmlelementcollection.cpp:587
XmlElementCollection::m_dom_document
QDomDocument m_dom_document
Definition: xmlelementcollection.h:123
NamesList::addName
void addName(const QString &, const QString &)
Definition: nameslist.cpp:43
XmlElementCollection::domToLocation
ElementsLocation domToLocation(QDomElement dom_element) const
XmlElementCollection::domToLocation Return the element location who represent the xml element : dom_e...
Definition: xmlelementcollection.cpp:687
nameslist.h
ElementsLocation::fileName
QString fileName() const
ElementLocation::fileName.
Definition: elementslocation.cpp:793
XmlElementCollection::directorieAdded
void directorieAdded(QString collection_path)
directorieAdded This signal is emited when a directorie is added to this collection
XmlElementCollection::copy
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...
Definition: xmlelementcollection.cpp:545
XmlElementCollection::directoriesNames
QStringList directoriesNames(const QDomElement &parent_element) const
XmlElementCollection::directoriesNames.
Definition: xmlelementcollection.cpp:226
XmlElementCollection
The XmlElementCollection class This class represent a collection of elements stored to xml.
Definition: xmlelementcollection.h:34
xmlelementcollection.h
XmlElementCollection::exist
bool exist(const QString &path) const
XmlElementCollection::exist Return true if the path path exist in this collection.
Definition: xmlelementcollection.cpp:569
ElementsLocation::isFileSystem
bool isFileSystem() const
ElementsLocation::isFileSystem.
Definition: elementslocation.cpp:428
XmlElementCollection::elementAdded
void elementAdded(QString collection_path)
elementAdded This signal is emited when a element is added to this collection
XmlElementCollection::childs
QDomNodeList childs(const QDomElement &parent_element) const
XmlElementCollection::childs.
Definition: xmlelementcollection.cpp:128
XmlElementCollection::element
QDomElement element(const QString &path) const
XmlElementCollection::element.
Definition: xmlelementcollection.cpp:291
XmlElementCollection::cleanUnusedElement
void cleanUnusedElement()
XmlElementCollection::cleanUnusedElement Remove elements in this collection which is not used in the ...
Definition: xmlelementcollection.cpp:711
ElementsLocation::isElement
bool isElement() const
ElementsLocation::isElement.
Definition: elementslocation.cpp:412
QETProject::unusedElements
QList< ElementsLocation > unusedElements() const
QETProject::unusedElements.
Definition: qetproject.cpp:1117
XmlElementCollection::elementsNames
QStringList elementsNames(const QDomElement &parent_element) const
XmlElementCollection::elementsNames.
Definition: xmlelementcollection.cpp:269
XmlElementCollection::copyElement
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString())
XmlElementCollection::copyElement Copy the element represented by source to destination (must be a di...
Definition: xmlelementcollection.cpp:851
XmlElementCollection::addElement
QString addElement(ElementsLocation &location)
XmlElementCollection::addElement Add the element at location to this collection. The element is copie...
Definition: xmlelementcollection.cpp:333
QETXML::fileSystemElementToXmlCollectionElement
QDomElement fileSystemElementToXmlCollectionElement(QDomDocument &document, QFile &file, const QString &rename=QString())
Definition: qetxml.cpp:220
XmlElementCollection::directoryRemoved
void directoryRemoved(QString collection_path)
directoryRemoved This signal is emited when a directory is removed to this collection
ElementsLocation::xml
QDomElement xml() const
ElementsLocation::xml.
Definition: elementslocation.cpp:575
elementslocation.h
ElementsLocation::isDirectory
bool isDirectory() const
ElementsLocation::isDirectory.
Definition: elementslocation.cpp:420
XmlElementCollection::addElementDefinition
bool addElementDefinition(const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition)
XmlElementCollection::addElementDefinition Add the élément defintion xml_definition in the directory ...
Definition: xmlelementcollection.cpp:477
ElementsLocation::projectCollectionPath
QString projectCollectionPath() const
ElementsLocation::projectCollectionPath.
Definition: elementslocation.cpp:176
XmlElementCollection::child
QDomElement child(const QDomElement &parent_element, const QString &child_name) const
XmlElementCollection::child If parent_element have child element with an attribute name = child_name,...
Definition: xmlelementcollection.cpp:148
XmlElementCollection::m_project
QETProject * m_project
Definition: xmlelementcollection.h:124
XmlElementCollection::root
QDomElement root() const
XmlElementCollection::root The root is the first DOM-Element the xml collection, the tag name of the ...
Definition: xmlelementcollection.cpp:110
ElementsLocation::fileSystemPath
QString fileSystemPath() const
ElementsLocation::fileSystemPath.
Definition: elementslocation.cpp:193
XmlElementCollection::elementRemoved
void elementRemoved(QString collection_path)
elementRemoved This signal is emited when an element is removed to this collection
ElementsLocation::isProject
bool isProject() const
ElementsLocation::isProject.
Definition: elementslocation.cpp:459
XmlElementCollection::directory
QDomElement directory(const QString &path) const
XmlElementCollection::directory.
Definition: xmlelementcollection.cpp:309
qetproject.h
ElementsLocation::collectionPath
QString collectionPath(bool protocol=true) const
ElementsLocation::collectionPath Return the path of the represented element relative to collection if...
Definition: elementslocation.cpp:160
ElementsLocation::nameList
NamesList nameList()
ElementsLocation::nameList.
Definition: elementslocation.cpp:532
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
QETProject
Definition: qetproject.h:51
NamesList
Definition: nameslist.h:30
XmlElementCollection::directories
QList< QDomElement > directories(const QDomElement &parent_element) const
XmlElementCollection::directories.
Definition: xmlelementcollection.cpp:203
XmlElementCollection::copyDirectory
ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString(), bool deep_copy=true)
XmlElementCollection::copyDirectory Copy the directory represented by source to destination....
Definition: xmlelementcollection.cpp:749
QETXML::fileSystemDirToXmlCollectionDir
QDomElement fileSystemDirToXmlCollectionDir(QDomDocument &document, const QDir &dir, const QString &rename=QString())
Definition: qetxml.cpp:175
ElementsLocation::projectCollection
XmlElementCollection * projectCollection() const
ElementsLocation::projectCollection.
Definition: elementslocation.cpp:519
XmlElementCollection::importCategory
QDomElement importCategory() const
XmlElementCollection::importCategory.
Definition: xmlelementcollection.cpp:119
qetxml.h
XmlElementCollection::removeElement
bool removeElement(const QString &path)
XmlElementCollection::removeElement Remove the element at path path.
Definition: xmlelementcollection.cpp:516
XmlElementCollection::elements
QList< QDomElement > elements(const QDomElement &parent_element) const
XmlElementCollection::elements.
Definition: xmlelementcollection.cpp:247
XmlElementCollection::XmlElementCollection
XmlElementCollection(QETProject *project)
XmlElementCollection::XmlElementCollection Build an empty collection. The collection start by :
Definition: xmlelementcollection.cpp:37
ElementsLocation::project
QETProject * project() const
ElementsLocation::project.
Definition: elementslocation.cpp:365
XmlElementCollection::cleanUnusedDirectory
void cleanUnusedDirectory()
XmlElementCollection::cleanUnusedDirectory Remove the empty directories of this collection.
Definition: xmlelementcollection.cpp:721
XmlElementCollection::elementsLocation
QList< ElementsLocation > elementsLocation(QDomElement dom_element=QDomElement(), bool childs=true) const
XmlElementCollection::elementsLocation Return all locations stored in dom_element (element and direct...
Definition: xmlelementcollection.cpp:642
ElementsLocation::setPath
void setPath(const QString &path)
ElementsLocation::setPath Set the path of this item. The path can be relative to a collection (start ...
Definition: elementslocation.cpp:217
XmlElementCollection::elementChanged
void elementChanged(QString collection_path)
elementChanged This signal is emited when the defintion of the element at path was changed
NamesList::toXml
QDomElement toXml(QDomDocument &, const QHash< QString, QString > &=QHash< QString, QString >()) const
Definition: nameslist.cpp:169
XmlElementCollection::removeDir
bool removeDir(const QString &path)
XmlElementCollection::removeDir Remove the directory at path path.
Definition: xmlelementcollection.cpp:621