27 #include <QtConcurrent> 35 QStandardItemModel(parent)
48 if (role == Qt::DecorationRole) {
49 QStandardItem *item = itemFromIndex(index);
52 static_cast<FileElementCollectionItem*>(item)->setUpIcon();
54 static_cast<XmlProjectElementCollectionItem*>(item)->setUpIcon();
57 return QStandardItemModel::data(index, role);
68 QModelIndex index = indexes.first();
73 QMimeData *mime_data =
new QMimeData();
77 mime_data->setData(
"application/x-qet-element-uri", item->
collectionPath().toLatin1());
79 mime_data->setData(
"application/x-qet-category-uri", item->
collectionPath().toLatin1());
84 return new QMimeData();
94 QStringList mime_list = QAbstractItemModel::mimeTypes();
95 mime_list <<
"application/x-qet-element-uri" <<
"application/x-qet-category-uri";
111 if (!(QStandardItemModel::canDropMimeData(
data, action, row, column, parent) && parent.isValid()))
114 QStandardItem *qsi = itemFromIndex(parent.child(row, column));
116 qsi = itemFromIndex(parent);
120 if (static_cast<FileElementCollectionItem *>(qsi)->isCommonCollection())
125 if (
data->hasFormat(
"application/x-qet-element-uri") ||
data->hasFormat(
"application/x-qet-category-uri"))
129 for (
int i=0 ; i<eci->rowCount() ; i++)
130 if (static_cast<ElementCollectionItem *>(eci->child(i))->collectionPath() == drop_location.collectionPath())
153 QStandardItem *qsi = itemFromIndex(parent.child(row, column));
155 qsi = itemFromIndex(parent);
165 feci = static_cast<FileElementCollectionItem *>(feci->parent());
173 if (location.exist())
177 for (
int i=0 ; i<feci->rowCount() ; i++) {
178 if (static_cast<FileElementCollectionItem *>(feci->child(i))->collectionPath() == location.collectionPath())
191 xpeci = static_cast<XmlProjectElementCollectionItem *>(xpeci->parent());
199 QList <QString> child_path_list;
200 for (
int i=0 ; i<xpeci->rowCount() ; i++)
201 child_path_list.append(static_cast<XmlProjectElementCollectionItem *>(xpeci->child(i, 0))->collectionPath());
209 return location.
exist();
228 QList <ElementCollectionItem *> list;
230 if (common_collection)
232 if (custom_collection)
235 if (common_collection || custom_collection)
236 list.append(
items());
244 QFuture<void> futur = QtConcurrent::map(list,
setUpData);
246 while (futur.isRunning()) {
259 invisibleRootItem()->appendRow(feci);
275 invisibleRootItem()->appendRow(feci);
296 QString collection_name;
308 QList <ElementCollectionItem *> child_list;
310 for (
int i=0 ; i<rowCount() ; i++)
311 child_list.append(static_cast<ElementCollectionItem *>(item(i)));
348 insertRow(row, xpeci);
368 if (removeRows(row, 1, QModelIndex())) {
394 QList <ElementsLocation> unused;
397 unused.append(
project->unusedElements());
400 brush.setStyle(Qt::Dense4Pattern);
401 brush.setColor(Qt::red);
405 if (index.isValid()) {
406 QStandardItem *qsi = itemFromIndex(index);
408 qsi->setBackground(brush);
419 QList <ElementCollectionItem *> list;
421 for (
int i=0 ; i<rowCount() ; i++) {
424 list.append(eci->
items());
437 QList <ElementCollectionItem *> list;
442 list.append(eci->
items());
457 removeRow(eci->row(), indexFromItem(eci).parent());
471 QList <ElementCollectionItem *> child_list;
473 for (
int i=0 ; i<rowCount() ; i++)
474 child_list.append(static_cast<ElementCollectionItem *>(item(i)));
495 return indexFromItem(match_eci);
498 return QModelIndex();
509 QObject *
object = sender();
526 QString collection_name;
542 QObject *
object = sender();
559 removeRow(index.row(), index.parent());
570 QObject *
object = sender();
The ElementCollectionItem class This class represent a item (a directory or an element) in a element ...
virtual void clearData()
ElementCollectionItem::clearData Reset the data.
bool isProject() const
ElementsLocation::isProject.
virtual void addChildAtPath(const QString &collection_name)=0
void addCommonCollection(bool set_data=true)
ElementsCollectionModel::addCommonCollection Add the common elements collection to this model...
int type() const override
QVariant data(const QModelIndex &index, int role) const override
ElementsCollectionModel::data Reimplemented from QStandardItemModel.
ElementsLocation copy(ElementsLocation &source, ElementsLocation &destination)
ElementCollectionHandler::copy Copy the content of collection represented by source to the collection...
bool isCustomCollection() const
FileElementCollectionItem::isCustomCollection.
QString collectionPath() const override
XmlProjectElementCollectionItem::collectionPath.
QList< ElementCollectionItem * > projectItems(QETProject *project) const
ElementsCollectionModel::projectItems.
void highlightUnusedElement()
ElementsCollectionModel::highlightUnusedElement Highlight every unused element of managed project...
void setUpData() override
XmlProjectElementCollectionItem::setUpData SetUp the data of this item.
void elementAdded(QString collection_path)
elementAdded This signal is emited when a element is added to this collection
ElementsCollectionModel(QObject *parent=Q_NULLPTR)
ElementsCollectionModel::ElementsCollectionModel Constructor.
QList< ElementCollectionItem * > items() const
ElementCollectionItem::items.
void loadingProgressValue(int)
QHash< QETProject *, XmlProjectElementCollectionItem * > m_project_hash
QList< QETProject * > project() const
ElementsCollectionModel::project.
void setUpData(ElementCollectionItem *eci)
QStringList mimeTypes() const override
ElementsCollectionModel::mimeTypes Reimplemented from QStandardItemModel.
The XmlProjectElementCollectionItem class This class specialise ElementCollectionItem for manage an x...
XmlElementCollection * embeddedElementCollection() const
QETProject::embeddedCollection.
void removeProject(QETProject *project)
ElementsCollectionModel::removeProject Remove project from this model.
ElementCollectionItem * itemAtPath(const QString &path)
ElementCollectionItem::itemAtPath.
int type() const override
void addChildAtPath(const QString &collection_name) override
FileElementCollectionItem::addChildAtPath Ask to this item item to add a child with collection name ...
void loadCollections(bool common_collection, bool custom_collection, QList< QETProject *> projects)
ElementsCollectionModel::loadCollections Load the several collections in this model. Prefer use this method instead of addCommonCollection, addCustomCollection and addProject, because it use multithreading to speed up the loading. This method emit loadingMaxValue(int) for know the maximum progress value This method emit loadingProgressValue(int) for know the current progress value.
ElementCollectionItem * lastItemForPath(const QString &path, QString &no_found_path)
ElementCollectionItem::lastItemForPath Return the last existing item in this ElementCollectionItem hi...
void elementChanged(QString collection_path)
elementChanged This signal is emited when the defintion of the element at path was changed ...
void elementIntegratedToCollection(const QString &path)
ElementsCollectionModel::elementIntegratedToCollection When an element is added to embedded collectio...
QList< ElementCollectionItem * > items() const
ElementsCollectionModel::items.
QETProject * project() const
QString collectionPath(bool protocol=true) const
bool isCommonCollection() const
FileElementCollectionItem::isCommonCollection.
void elementRemoved(QString collection_path)
elementRemoved This signal is emited when an element is removed to this collection ...
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
ElementsCollectionModel::canDropMimeData Reimplemented from QStandardItemModel.
void addLocation(const ElementsLocation &location)
ElementsCollectionModel::addLocation Add the element or directory to this model. If the location is a...
void hideElement()
ElementsCollectionModel::hideElement Hide element in this model, only directory is managed...
QList< QETProject * > m_project_list
void itemRemovedFromCollection(const QString &path)
ElementsCollectionModel::itemRemovedFromCollection This method must be called by a signal...
void updateItem(const QString &path)
ElementsCollectionModel::updateItem Update the item at path.
bool exist() const
ElementsLocation::exist.
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
ElementsCollectionModel::dropMimeData Reimplemented from QStandardItemModel.
void addProject(QETProject *project, bool set_data=true)
ElementsCollectionModel::addProject Add project to this model.
void loadingMaxValue(int)
void setProject(QETProject *project, bool set_data=true, bool hide_element=false)
XmlProjectElementCollectionItem::setProject Set the project for this item. Use this method for set th...
QMimeData * mimeData(const QModelIndexList &indexes) const override
ElementsCollectionModel::mimeData Reimplemented from QStandardItemModel.
virtual bool isElement() const =0
void setUpData() override
FileElementCollectionItem::setUpData SetUp the data of this item.
The FileElementCollectionItem class This class specialise ElementCollectionItem for manage a collecti...
void addCustomCollection(bool set_data=true)
ElementsCollectionModel::addCustomCollection Add the custom elements collection to this model...
void directoryRemoved(QString collection_path)
directoryRemoved This signal is emited when a directory is removed to this collection ...
virtual QString collectionPath() const =0
bool setRootPath(const QString &path, bool set_data=true, bool hide_element=false)
FileElementCollectionItem::setRootPath Set path has root path for this file item. Use this function o...
static QString customElementsDirN()
QETApp::customElementsDirN like QString QETApp::customElementsDir but without "/" at the end...
QString fileSystemPath() const
FileElementCollectionItem::fileSystemPath.
bool isCommonCollection() const
ElementsLocation::isCommonCollection.
bool isCustomCollection() const
ElementsLocation::isCustomCollection.
static QString commonElementsDirN()
QETApp::commonElementsDirN like QString QETApp::commonElementsDir but without "/" at the end...
virtual void setUpData()=0
int type() const override
bool isElement() const override
FileElementCollectionItem::isElement.
bool isElement() const override
XmlProjectElementCollectionItem::isElement.
The XmlElementCollection class This class represent a collection of elements stored to xml...
The ElementCollectionHandler class Provide several method to copy element or directory from a collect...
QModelIndex indexFromLocation(const ElementsLocation &location)
ElementsCollectionModel::indexFromLocation Return the index who represent . Index can be non valid...