File: xmlelementcollection.h

package info (click to toggle)
qelectrotech 1%3A0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 91,680 kB
  • sloc: cpp: 62,335; xml: 750; sh: 264; perl: 258; makefile: 6
file content (106 lines) | stat: -rw-r--r-- 4,206 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
	Copyright 2006-2019 The QElectroTech Team
	This file is part of QElectroTech.

	QElectroTech is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	QElectroTech is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with QElectroTech.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMLELEMENTCOLLECTION_H
#define XMLELEMENTCOLLECTION_H

#include <QObject>
#include <QDomElement>
#include "elementslocation.h"

class QDomElement;
class QFile;
class QETProject;

/**
 * @brief The XmlElementCollection class
 * This class represent a collection of elements stored to xml
 */
class XmlElementCollection : public QObject
{
		Q_OBJECT

	public:
		XmlElementCollection (QETProject *project);
		XmlElementCollection (const QDomElement &dom_element, QETProject *project);
		QDomElement root() const;
		QDomElement importCategory() const;
		QDomNodeList childs(const QDomElement &parent_element) const;
		QDomElement child(const QDomElement &parent_element, const QString &child_name) const;
		QDomElement child(const QString &path) const;
		QList<QDomElement> directories(const QDomElement &parent_element) const;
		QStringList directoriesNames(const QDomElement &parent_element) const;
		QList<QDomElement> elements(const QDomElement &parent_element) const;
		QStringList elementsNames(const QDomElement &parent_element) const;
		QDomElement element(const QString &path) const;
		QDomElement directory(const QString &path) const;
		QString addElement (ElementsLocation &location);
		bool addElementDefinition (const QString &dir_path, const QString &elmt_name, const QDomElement &xml_definition);
		bool removeElement(const QString& path);
		ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, const QString& rename = QString(), bool deep_copy = true);
		bool exist (const QString &path) const;
		bool createDir (const QString& path, const QString& name, const NamesList &name_list);
		bool removeDir (const QString& path);

		QList <ElementsLocation> elementsLocation (QDomElement dom_element = QDomElement(), bool childs = true) const;
		ElementsLocation domToLocation(QDomElement dom_element) const;

		void cleanUnusedElement();
		void cleanUnusedDirectory();

	private:
		ElementsLocation copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString& rename = QString(), bool deep_copy = true);
		ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, const QString& rename = QString());

	signals:
			/**
			 * @brief elementAdded
			 * This signal is emited when a element is added to this collection
			 * @param collection_path, the path of element in this collection
			 */
		void elementAdded(QString collection_path);
			/**
			 * @brief elementChanged
			 * This signal is emited when the defintion of the element at path was changed
			 * @param collection_path, the path of this element in this collection
			 */
		void elementChanged (QString collection_path);
			/**
			 * @brief elementRemoved
			 * This signal is emited when an element is removed to this collection
			 * @param collection_path, the path of the removed element in this collection
			 */
		void elementRemoved(QString collection_path);
			/**
			 * @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);
			/**
			 * @brief directoryRemoved
			 * This signal is emited when a directory is removed to this collection
			 * @param collection_path, the path of the removed directory
			 */
		void directoryRemoved(QString collection_path);

	private:
		QDomDocument m_dom_document;
		QETProject *m_project = nullptr;
};

#endif // XMLELEMENTCOLLECTION_H