QElectroTech  0.70
Signals | Public Member Functions | Private Attributes | List of all members
XmlElementCollection Class Reference

The XmlElementCollection class This class represent a collection of elements stored to xml. More...

#include <xmlelementcollection.h>

Signals

void elementAdded (QString collection_path)
 elementAdded This signal is emited when a element is added to this collection More...
 
void elementChanged (QString collection_path)
 elementChanged This signal is emited when the defintion of the element at path was changed More...
 
void elementRemoved (QString collection_path)
 elementRemoved This signal is emited when an element is removed to this collection More...
 
void directorieAdded (QString collection_path)
 directorieAdded This signal is emited when a directorie is added to this collection More...
 
void directoryRemoved (QString collection_path)
 directoryRemoved This signal is emited when a directory is removed to this collection More...
 

Public Member Functions

 XmlElementCollection (QETProject *project)
 XmlElementCollection::XmlElementCollection Build an empty collection. The collection start by : <collection> <category name="import> </category> </collection> All elements and category are stored as child of <category name="import> More...
 
 XmlElementCollection (const QDomElement &dom_element, QETProject *project)
 XmlElementCollection::XmlElementCollection Constructor with an collection. The tagName of must be "collection". More...
 
QDomElement root () const
 XmlElementCollection::root The root is the first DOM-Element the xml collection, the tag name of the dom element is : collection. More...
 
QDomElement importCategory () const
 XmlElementCollection::importCategory. More...
 
QDomNodeList childs (const QDomElement &parent_element) const
 XmlElementCollection::childs. More...
 
QDomElement child (const QDomElement &parent_element, const QString &child_name) const
 XmlElementCollection::child If parent_element have child element with an attribute name = , return it, else return a null QDomElement. Only search for element with tag-name "category" and "element" (if child_name end with ".elmt") More...
 
QDomElement child (const QString &path) const
 XmlElementCollection::child. More...
 
QList< QDomElement > directories (const QDomElement &parent_element) const
 XmlElementCollection::directories. More...
 
QStringList directoriesNames (const QDomElement &parent_element) const
 XmlElementCollection::directoriesNames. More...
 
QList< QDomElement > elements (const QDomElement &parent_element) const
 XmlElementCollection::elements. More...
 
QStringList elementsNames (const QDomElement &parent_element) const
 XmlElementCollection::elementsNames. More...
 
QDomElement element (const QString &path) const
 XmlElementCollection::element. More...
 
QDomElement directory (const QString &path) const
 XmlElementCollection::directory. More...
 
QString addElement (ElementsLocation &location)
 XmlElementCollection::addElement Add the element at location to this collection. The element is copied in this collection in "import" dir with the same path, in other word if the path is dir1/dir2/dir3/myElement.elmt, myElement is copied to this collection at the path : import/dir1/dir2/dir3/myElement.elmt If the path doesn't exist, he was created. If the element already exist, do nothing. More...
 
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 the name . More...
 
bool removeElement (const QString &path)
 XmlElementCollection::removeElement Remove the element at path . More...
 
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 destination. Destination must be a directory of this collection. If the destination already have an item at the same path of source, he will be replaced by source. More...
 
bool exist (const QString &path) const
 XmlElementCollection::exist Return true if the path exist in this collection. More...
 

Private Attributes

QDomDocument m_dom_document
 
QETProjectm_project = nullptr
 

.

XmlElementCollection::createDir Create a child directorie at path with the name Emit directorieAdded if success.

Parameters
path: path of parent diectorie
name: name of the directori to create.
name_list: translation of the directorie name.
Returns
true if creation success, if directorie already exist return true.
bool createDir (const QString &path, const QString &name, const NamesList &name_list)
 
bool removeDir (const QString &path)
 XmlElementCollection::removeDir Remove the directory at path . More...
 
QList< ElementsLocationelementsLocation (QDomElement dom_element=QDomElement(), bool childs=true) const
 XmlElementCollection::elementsLocation Return all locations stored in dom_element (element and directory). If dom_element is null, return all location owned by this collection dom_element must be a child of this collection. More...
 
ElementsLocation domToLocation (QDomElement dom_element) const
 XmlElementCollection::domToLocation Return the element location who represent the xml element : dom_element dom_element must be owned by this collection. More...
 
void cleanUnusedElement ()
 XmlElementCollection::cleanUnusedElement Remove elements in this collection which is not used in the owner project. More...
 
void cleanUnusedDirectory ()
 XmlElementCollection::cleanUnusedDirectory Remove the empty directories of this collection. More...
 
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. More...
 
ElementsLocation copyElement (ElementsLocation &source, ElementsLocation &destination, const QString &rename=QString())
 XmlElementCollection::copyElement Copy the element represented by source to destination (must be a directory) If element already exist in destination he will be replaced by the new. More...
 

Detailed Description

The XmlElementCollection class This class represent a collection of elements stored to xml.

Definition at line 33 of file xmlelementcollection.h.

Constructor & Destructor Documentation

◆ XmlElementCollection() [1/2]

XmlElementCollection::XmlElementCollection ( QETProject project)

XmlElementCollection::XmlElementCollection Build an empty collection. The collection start by : <collection> <category name="import> </category> </collection> All elements and category are stored as child of <category name="import>

Parameters
project: the project of this collection

Definition at line 35 of file xmlelementcollection.cpp.

References NamesList::addName(), m_dom_document, and NamesList::toXml().

◆ XmlElementCollection() [2/2]

XmlElementCollection::XmlElementCollection ( const QDomElement &  dom_element,
QETProject project 
)

XmlElementCollection::XmlElementCollection Constructor with an collection. The tagName of must be "collection".

Parameters
dom_element-the collection in a dom_element (the dom element in cloned)
project: the project of this collection

Definition at line 79 of file xmlelementcollection.cpp.

References m_dom_document.

Member Function Documentation

◆ addElement()

QString XmlElementCollection::addElement ( ElementsLocation location)

XmlElementCollection::addElement Add the element at location to this collection. The element is copied in this collection in "import" dir with the same path, in other word if the path is dir1/dir2/dir3/myElement.elmt, myElement is copied to this collection at the path : import/dir1/dir2/dir3/myElement.elmt If the path doesn't exist, he was created. If the element already exist, do nothing.

Parameters
location,locationof the element
Returns
the collection path of the added item or a null QString if element can't be added.

Definition at line 301 of file xmlelementcollection.cpp.

References child(), ElementsLocation::collectionPath(), elementAdded(), exist(), ElementsLocation::exist(), QETXML::fileSystemDirToXmlCollectionDir(), QETXML::fileSystemElementToXmlCollectionElement(), ElementsLocation::fileSystemPath(), importCategory(), ElementsLocation::isElement(), ElementsLocation::isFileSystem(), ElementsLocation::isProject(), m_dom_document, ElementsLocation::nameList(), ElementsLocation::project(), ElementsLocation::projectCollection(), NamesList::toXml(), and ElementsLocation::xml().

Referenced by QETProject::importElement().

◆ addElementDefinition()

bool XmlElementCollection::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 the name .

Parameters
dir_path: the path of the directory where we must add the element. The path must be an existing directory of this collection.
elmt_name: The name used to store the element (the name must end with .elmt, if not, .elmt will be append to )
xml_definition: The xml definition of the element. The tag name of must be "definition".
Returns
True if the element is added with success.

Definition at line 435 of file xmlelementcollection.cpp.

References directory(), elementAdded(), and m_dom_document.

Referenced by ElementsLocation::setXml().

◆ child() [1/2]

QDomElement XmlElementCollection::child ( const QDomElement &  parent_element,
const QString &  child_name 
) const

XmlElementCollection::child If parent_element have child element with an attribute name = , return it, else return a null QDomElement. Only search for element with tag-name "category" and "element" (if child_name end with ".elmt")

Parameters
parent_element: the parent DomElement where we search for child. must be a child node of this XmlElementCollection.
child_name: name of child to search.
Returns
The child QDomElement or a null QDomElement if not found

Definition at line 128 of file xmlelementcollection.cpp.

References m_dom_document.

Referenced by addElement(), child(), copyDirectory(), copyElement(), directoriesNames(), directory(), element(), elementsNames(), and exist().

◆ child() [2/2]

QDomElement XmlElementCollection::child ( const QString &  path) const

XmlElementCollection::child.

Parameters
path
Returns
the DomElement at path if exist, else return a null QDomElement

Definition at line 156 of file xmlelementcollection.cpp.

References child(), and root().

◆ childs()

QDomNodeList XmlElementCollection::childs ( const QDomElement &  parent_element) const

XmlElementCollection::childs.

Parameters
parent_element
Returns
All childs element in the tree

Definition at line 113 of file xmlelementcollection.cpp.

References m_dom_document.

Referenced by directories(), directoriesNames(), elements(), elementsLocation(), and elementsNames().

◆ cleanUnusedDirectory()

void XmlElementCollection::cleanUnusedDirectory ( )

XmlElementCollection::cleanUnusedDirectory Remove the empty directories of this collection.

Definition at line 654 of file xmlelementcollection.cpp.

References domToLocation(), importCategory(), and removeDir().

Referenced by ProjectView::cleanProject().

◆ cleanUnusedElement()

void XmlElementCollection::cleanUnusedElement ( )

XmlElementCollection::cleanUnusedElement Remove elements in this collection which is not used in the owner project.

Definition at line 644 of file xmlelementcollection.cpp.

References ElementsLocation::collectionPath(), m_project, removeElement(), and QETProject::unusedElements().

Referenced by ProjectView::cleanProject().

◆ copy()

ElementsLocation XmlElementCollection::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 destination. Destination must be a directory of this collection. If the destination already have an item at the same path of source, he will be replaced by source.

Parameters
source: content to copy
destination: destination of the copy, must be a directory of this collection
rename: rename the copy with else use the name of source
deep_copy: if true copy all childs of source (only if source is directory)
Returns
the ElementLocation that represent the copy, if copy failed return a null ElementLocation

Definition at line 494 of file xmlelementcollection.cpp.

References copyDirectory(), copyElement(), ElementsLocation::exist(), ElementsLocation::isDirectory(), ElementsLocation::isElement(), ElementsLocation::isProject(), and ElementsLocation::projectCollection().

Referenced by ECHSToXml::copy(), QETProject::importElement(), and ElementCollectionHandler::importFromProject().

◆ copyDirectory()

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

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.

Parameters
source: directory to copy
destination: destination of the copy
rename: rename the copy with else use the name of source
deep_copy:if true copy all childs of source
Returns
the ElementLocation that represent the copy, if copy failed return a null ElementLocation

Definition at line 678 of file xmlelementcollection.cpp.

References child(), ElementsLocation::collectionPath(), copyElement(), directorieAdded(), directory(), directoryRemoved(), element(), ElementsLocation::fileName(), QETXML::fileSystemDirToXmlCollectionDir(), ElementsLocation::fileSystemPath(), ElementsLocation::isFileSystem(), m_dom_document, ElementsLocation::projectCollection(), ElementsLocation::projectCollectionPath(), and ElementsLocation::setPath().

Referenced by copy().

◆ copyElement()

ElementsLocation XmlElementCollection::copyElement ( ElementsLocation source,
ElementsLocation destination,
const QString &  rename = QString() 
)
private

XmlElementCollection::copyElement Copy the element represented by source to destination (must be a directory) If element already exist in destination he will be replaced by the new.

Parameters
source: element to copy
destination: destination of the copy
rename: rename the copy with else use the name of source
Returns
The ElementsLocation of the copy

Definition at line 765 of file xmlelementcollection.cpp.

References child(), ElementsLocation::collectionPath(), directory(), element(), elementAdded(), elementChanged(), ElementsLocation::fileName(), QETXML::fileSystemElementToXmlCollectionElement(), ElementsLocation::fileSystemPath(), ElementsLocation::isFileSystem(), m_dom_document, ElementsLocation::projectCollectionPath(), and ElementsLocation::xml().

Referenced by copy(), and copyDirectory().

◆ createDir()

bool XmlElementCollection::createDir ( const QString &  path,
const QString &  name,
const NamesList name_list 
)

◆ directorieAdded

void XmlElementCollection::directorieAdded ( QString  collection_path)
signal

directorieAdded This signal is emited when a directorie is added to this collection

Parameters
collection_path,thepath of the new directorie

Referenced by copyDirectory(), and createDir().

◆ directories()

QList< QDomElement > XmlElementCollection::directories ( const QDomElement &  parent_element) const

XmlElementCollection::directories.

Parameters
parent_element
Returns
A list of directory stored in

Definition at line 180 of file xmlelementcollection.cpp.

References childs().

Referenced by directoriesNames(), elementsLocation(), and XmlProjectElementCollectionItem::populate().

◆ directoriesNames()

QStringList XmlElementCollection::directoriesNames ( const QDomElement &  parent_element) const

XmlElementCollection::directoriesNames.

Parameters
parent_element
Returns
a list of names for every child directories of

Definition at line 201 of file xmlelementcollection.cpp.

References child(), childs(), and directories().

Referenced by ECHSXmlToFile::copyDirectory().

◆ directory()

QDomElement XmlElementCollection::directory ( const QString &  path) const

XmlElementCollection::directory.

Parameters
path: path of the directory in this collection
Returns
the QDomElement that represent the directory at path or a null QDomElement if not found.

Definition at line 281 of file xmlelementcollection.cpp.

References child().

Referenced by addElementDefinition(), ECHSXmlToFile::copyDirectory(), copyDirectory(), copyElement(), createDir(), ElementsLocation::nameList(), removeDir(), and ElementsLocation::xml().

◆ directoryRemoved

void XmlElementCollection::directoryRemoved ( QString  collection_path)
signal

directoryRemoved This signal is emited when a directory is removed to this collection

Parameters
collection_path,thepath of the removed directory

Referenced by ElementsCollectionModel::addProject(), copyDirectory(), removeDir(), and ElementsCollectionModel::removeProject().

◆ domToLocation()

ElementsLocation XmlElementCollection::domToLocation ( QDomElement  dom_element) const

XmlElementCollection::domToLocation Return the element location who represent the xml element : dom_element dom_element must be owned by this collection.

Parameters
dom_element: the dom_element of this collection that represent an element. The tag name of dom_element must be "element"
Returns
the element location, location can be null if fail.

Definition at line 622 of file xmlelementcollection.cpp.

References m_dom_document, and m_project.

Referenced by cleanUnusedDirectory(), and elementsLocation().

◆ element()

QDomElement XmlElementCollection::element ( const QString &  path) const

XmlElementCollection::element.

Parameters
path: path of the element in this collection
Returns
the QDomElement that represent the element at path or a null QDomElement if not found or doesn't represent an element

Definition at line 263 of file xmlelementcollection.cpp.

References child().

Referenced by copyDirectory(), copyElement(), removeElement(), and ElementsLocation::xml().

◆ elementAdded

void XmlElementCollection::elementAdded ( QString  collection_path)
signal

elementAdded This signal is emited when a element is added to this collection

Parameters
collection_path,thepath of element in this collection

Referenced by addElement(), addElementDefinition(), ElementsCollectionModel::addProject(), copyElement(), and ElementsCollectionModel::removeProject().

◆ elementChanged

void XmlElementCollection::elementChanged ( QString  collection_path)
signal

elementChanged This signal is emited when the defintion of the element at path was changed

Parameters
collection_path,thepath of this element in this collection

Referenced by ElementsCollectionModel::addProject(), copyElement(), and ElementsCollectionModel::removeProject().

◆ elementRemoved

void XmlElementCollection::elementRemoved ( QString  collection_path)
signal

elementRemoved This signal is emited when an element is removed to this collection

Parameters
collection_path,thepath of the removed element in this collection

Referenced by ElementsCollectionModel::addProject(), removeElement(), and ElementsCollectionModel::removeProject().

◆ elements()

QList< QDomElement > XmlElementCollection::elements ( const QDomElement &  parent_element) const

XmlElementCollection::elements.

Parameters
parent_element
Returns
A list of element stored in

Definition at line 221 of file xmlelementcollection.cpp.

References childs().

Referenced by elementsLocation(), elementsNames(), and XmlProjectElementCollectionItem::populate().

◆ elementsLocation()

QList< ElementsLocation > XmlElementCollection::elementsLocation ( QDomElement  dom_element = QDomElement(),
bool  childs = true 
) const

XmlElementCollection::elementsLocation Return all locations stored in dom_element (element and directory). If dom_element is null, return all location owned by this collection dom_element must be a child of this collection.

Parameters
dom_element: dom_element where we must to search location.
childs= if true return all childs location of dom_element, if false, only return the direct childs location of dom_element.
Returns

Definition at line 580 of file xmlelementcollection.cpp.

References childs(), directories(), domToLocation(), elements(), ElementsLocation::exist(), and m_dom_document.

Referenced by QETProject::unusedElements().

◆ elementsNames()

QStringList XmlElementCollection::elementsNames ( const QDomElement &  parent_element) const

XmlElementCollection::elementsNames.

Parameters
parent_element
Returns
A list of names fr every childs element of

Definition at line 242 of file xmlelementcollection.cpp.

References child(), childs(), and elements().

Referenced by ECHSXmlToFile::copyDirectory().

◆ exist()

bool XmlElementCollection::exist ( const QString &  path) const

XmlElementCollection::exist Return true if the path exist in this collection.

Parameters
path
Returns

Definition at line 511 of file xmlelementcollection.cpp.

References child().

Referenced by addElement(), ElementsLocation::exist(), and QETProject::importElement().

◆ importCategory()

QDomElement XmlElementCollection::importCategory ( ) const

XmlElementCollection::importCategory.

Returns
The QDomElement import (the begining of a xml collection) or a null QDomElement if doesn't exist.

Definition at line 104 of file xmlelementcollection.cpp.

References root().

Referenced by addElement(), and cleanUnusedDirectory().

◆ removeDir()

bool XmlElementCollection::removeDir ( const QString &  path)

XmlElementCollection::removeDir Remove the directory at path .

Parameters
path
Returns
true if successfuly removed and emit directoryRemoved(QString), else false.

Definition at line 560 of file xmlelementcollection.cpp.

References directory(), and directoryRemoved().

Referenced by cleanUnusedDirectory().

◆ removeElement()

bool XmlElementCollection::removeElement ( const QString &  path)

XmlElementCollection::removeElement Remove the element at path .

Parameters
path
Returns
True if element is removed and emit the signal elementRemoved. else false.

Definition at line 470 of file xmlelementcollection.cpp.

References element(), and elementRemoved().

Referenced by cleanUnusedElement().

◆ root()

QDomElement XmlElementCollection::root ( ) const

XmlElementCollection::root The root is the first DOM-Element the xml collection, the tag name of the dom element is : collection.

Returns
The root QDomElement of the collection

Definition at line 95 of file xmlelementcollection.cpp.

References m_dom_document.

Referenced by child(), importCategory(), XmlProjectElementCollectionItem::setProject(), and QETProject::toXml().

Member Data Documentation

◆ m_dom_document

QDomDocument XmlElementCollection::m_dom_document
private

◆ m_project

QETProject* XmlElementCollection::m_project = nullptr
private

Definition at line 103 of file xmlelementcollection.h.

Referenced by cleanUnusedElement(), and domToLocation().


The documentation for this class was generated from the following files: