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:
blacksun
2016-07-09 18:24:40 +00:00
parent b6816c9e49
commit 518f0efd46
5 changed files with 123 additions and 4 deletions

View File

@@ -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