mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Project embedded collection, Clean unused elements and empty directory work again
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4568 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -311,6 +311,8 @@ void ElementsCollectionModel::addProject(QETProject *project, bool set_data)
|
||||
xpeci->setUpData();
|
||||
connect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
|
||||
connect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
|
||||
connect(project->embeddedElementCollection(), &XmlElementCollection::elementRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
|
||||
connect(project->embeddedElementCollection(), &XmlElementCollection::directoryRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -329,6 +331,8 @@ void ElementsCollectionModel::removeProject(QETProject *project)
|
||||
m_project_hash.remove(project);
|
||||
disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementAdded, this, &ElementsCollectionModel::elementIntegratedToCollection);
|
||||
disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementChanged, this, &ElementsCollectionModel::updateItem);
|
||||
disconnect(project->embeddedElementCollection(), &XmlElementCollection::elementRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
|
||||
disconnect(project->embeddedElementCollection(), &XmlElementCollection::directoryRemoved, this, &ElementsCollectionModel::itemRemovedFromCollection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,9 +411,6 @@ void ElementsCollectionModel::hideElement()
|
||||
*/
|
||||
QModelIndex ElementsCollectionModel::indexFromLocation(const ElementsLocation &location)
|
||||
{
|
||||
if (!location.exist())
|
||||
return QModelIndex();
|
||||
|
||||
QList <ElementCollectionItem *> child_list;
|
||||
|
||||
for (int i=0 ; i<rowCount() ; i++)
|
||||
@@ -474,6 +475,34 @@ void ElementsCollectionModel::elementIntegratedToCollection(QString path)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionModel::itemRemovedFromCollection
|
||||
* This method must be called by a signal, to get a sender.
|
||||
* @param path
|
||||
*/
|
||||
void ElementsCollectionModel::itemRemovedFromCollection(QString path)
|
||||
{
|
||||
QObject *object = sender();
|
||||
XmlElementCollection *collection = static_cast<XmlElementCollection *> (object);
|
||||
if (!collection)
|
||||
return;
|
||||
|
||||
QETProject *project = nullptr;
|
||||
|
||||
//Get the owner project of the collection
|
||||
foreach (QETProject *prj, m_project_list) {
|
||||
if (prj->embeddedElementCollection() == collection) {
|
||||
project = prj;
|
||||
}
|
||||
}
|
||||
|
||||
if (project) {
|
||||
QModelIndex index = indexFromLocation(ElementsLocation(path, project));
|
||||
if (index.isValid())
|
||||
removeRow(index.row(), index.parent());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ElementsCollectionModel::updateItem
|
||||
* Update the item at path
|
||||
|
||||
@@ -28,7 +28,6 @@ template<> class QHash<QETProject, XmlProjectElementCollectionItem>;
|
||||
template<> class QList<ElementCollectionItem>;
|
||||
|
||||
|
||||
|
||||
class ElementsCollectionModel : public QStandardItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -59,6 +58,7 @@ class ElementsCollectionModel : public QStandardItemModel
|
||||
|
||||
private:
|
||||
void elementIntegratedToCollection (QString path);
|
||||
void itemRemovedFromCollection (QString path);
|
||||
void updateItem (QString path);
|
||||
|
||||
private:
|
||||
|
||||
@@ -432,6 +432,26 @@ bool XmlElementCollection::addElementDefinition(const QString &dir_path, const Q
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::removeElement
|
||||
* Remove the element at path @path.
|
||||
* @param path
|
||||
* @return True if element is removed and emit the signal elementRemoved.
|
||||
* else false.
|
||||
*/
|
||||
bool XmlElementCollection::removeElement(QString path)
|
||||
{
|
||||
QDomElement elmt = element(path);
|
||||
|
||||
if (!elmt.isNull()) {
|
||||
elmt.parentNode().removeChild(elmt);
|
||||
emit elementRemoved(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::copy
|
||||
* Copy the content represented by source (an element or a directory) to destination.
|
||||
@@ -502,6 +522,24 @@ bool XmlElementCollection::createDir(QString path, QString name, const NamesList
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::removeDir
|
||||
* Remove the directory at path @path.
|
||||
* @param path
|
||||
* @return true if successfuly removed and emit directoryRemoved(QString),
|
||||
* else false.
|
||||
*/
|
||||
bool XmlElementCollection::removeDir(QString path)
|
||||
{
|
||||
QDomElement dir = directory(path);
|
||||
if (!dir.isNull()) {
|
||||
dir.parentNode().removeChild(dir);
|
||||
emit directoryRemoved(path);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::elementsLocation
|
||||
* Return all locations stored in dom_element (element and directory).
|
||||
@@ -571,6 +609,34 @@ ElementsLocation XmlElementCollection::domToLocation(QDomElement dom_element) co
|
||||
return ElementsLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::cleanUnusedElement
|
||||
* Remove elements in this collection which is not used in the owner project
|
||||
*/
|
||||
void XmlElementCollection::cleanUnusedElement()
|
||||
{
|
||||
foreach (ElementsLocation loc, m_project->unusedElements())
|
||||
removeElement(loc.collectionPath(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::cleanUnusedDirectory
|
||||
* Remove the empty directories of this collection
|
||||
*/
|
||||
void XmlElementCollection::cleanUnusedDirectory()
|
||||
{
|
||||
QDomNodeList lst = importCategory().elementsByTagName("category");
|
||||
|
||||
for(int i=0 ; i<lst.size() ; i++) {
|
||||
QDomElement dir = lst.item(i).toElement();
|
||||
//elmt haven't got child node "element" or "category", so he is emty, we can remove it
|
||||
if (dir.elementsByTagName("element").isEmpty() && dir.elementsByTagName("category").isEmpty()) {
|
||||
if (removeDir(domToLocation(dir).collectionPath(false)))
|
||||
i=-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief XmlElementCollection::copyDirectory
|
||||
* Copy the directory represented by source to destination.
|
||||
|
||||
@@ -50,13 +50,18 @@ class XmlElementCollection : public QObject
|
||||
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(QString path);
|
||||
ElementsLocation copy (ElementsLocation &source, ElementsLocation &destination, QString rename = QString(), bool deep_copy = true);
|
||||
bool exist (const QString &path) const;
|
||||
bool createDir (QString path, QString name, const NamesList &name_list);
|
||||
bool removeDir (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, QString rename = QString(), bool deep_copy = true);
|
||||
ElementsLocation copyElement(ElementsLocation &source, ElementsLocation &destination, QString rename = QString());
|
||||
@@ -74,12 +79,24 @@ class XmlElementCollection : public QObject
|
||||
* @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;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "qettemplateeditor.h"
|
||||
#include "diagramfoliolist.h"
|
||||
#include "projectpropertiesdialog.h"
|
||||
#include "xmlelementcollection.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@@ -806,6 +807,12 @@ int ProjectView::cleanProject() {
|
||||
if (clean_tbt -> isChecked()) {
|
||||
m_project->embeddedTitleBlockTemplatesCollection()->deleteUnusedTitleBlocKTemplates();
|
||||
}
|
||||
if (clean_elements->isChecked()) {
|
||||
m_project->embeddedElementCollection()->cleanUnusedElement();
|
||||
}
|
||||
if (clean_categories->isChecked()) {
|
||||
m_project->embeddedElementCollection()->cleanUnusedDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
return(clean_count);
|
||||
|
||||
Reference in New Issue
Block a user