QElectroTech  0.8-dev
elementscollectionmodel.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ELEMENTSCOLLECTIONMODEL2_H
19 #define ELEMENTSCOLLECTIONMODEL2_H
20 
21 #include <QStandardItemModel>
22 #include "elementslocation.h"
23 
26 template<> class QList<QETProject>;
27 template<> class QHash<QETProject, XmlProjectElementCollectionItem>;
28 template<> class QList<ElementCollectionItem>;
29 
30 
31 class ElementsCollectionModel : public QStandardItemModel
32 {
33  Q_OBJECT
34 
35  public:
36  ElementsCollectionModel(QObject *parent = Q_NULLPTR);
37 
38  QVariant data(const QModelIndex &index, int role) const override;
39  QMimeData *mimeData(const QModelIndexList &indexes) const override;
40  QStringList mimeTypes() const override;
41  bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
42  bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
43 
44  void loadCollections(bool common_collection, bool custom_collection, QList<QETProject *> projects);
45 
46  void addCommonCollection(bool set_data = true);
47  void addCustomCollection(bool set_data = true);
48  void addLocation(const ElementsLocation& location);
49 
50  void addProject(QETProject *project, bool set_data = true);
52  QList<QETProject *> project() const;
54 
55 
56  QList <ElementCollectionItem *> items() const;
57  QList <ElementCollectionItem *> projectItems(QETProject *project) const;
58  void hideElement();
59  bool isHideElement() {return m_hide_element;}
60  QModelIndex indexFromLocation(const ElementsLocation &location);
61 
62  signals:
66 
67  private:
68  void elementIntegratedToCollection (const QString& path);
69  void itemRemovedFromCollection (const QString& path);
70  void updateItem (const QString& path);
71 
72  private:
73  QList <QETProject *> m_project_list;
74  QHash <QETProject *, XmlProjectElementCollectionItem *> m_project_hash;
75  bool m_hide_element = false;
76  QFuture<void> m_future;
77  QList <ElementCollectionItem *> m_items_list_to_setUp;
78 };
79 
80 #endif // ELEMENTSCOLLECTIONMODEL2_H
ElementsLocation::exist
bool exist() const
ElementsLocation::exist.
Definition: elementslocation.cpp:472
ElementsCollectionModel::itemRemovedFromCollection
void itemRemovedFromCollection(const QString &path)
ElementsCollectionModel::itemRemovedFromCollection This method must be called by a signal,...
Definition: elementscollectionmodel.cpp:618
ElementCollectionItem::items
QList< ElementCollectionItem * > items() const
ElementCollectionItem::items.
Definition: elementcollectionitem.cpp:237
setUpData
void setUpData(ElementCollectionItem *eci)
Definition: elementcollectionitem.cpp:250
FileElementCollectionItem::setRootPath
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...
Definition: fileelementcollectionitem.cpp:42
ElementsCollectionModel::addLocation
void addLocation(const ElementsLocation &location)
ElementsCollectionModel::addLocation Add the element or directory to this model. If the location is a...
Definition: elementscollectionmodel.cpp:336
ElementsCollectionModel::updateItem
void updateItem(const QString &path)
ElementsCollectionModel::updateItem Update the item at path.
Definition: elementscollectionmodel.cpp:647
QETProject::embeddedElementCollection
XmlElementCollection * embeddedElementCollection() const
QETProject::embeddedCollection.
Definition: qetproject.cpp:236
ElementsCollectionModel::ElementsCollectionModel
ElementsCollectionModel(QObject *parent=Q_NULLPTR)
ElementsCollectionModel::ElementsCollectionModel Constructor.
Definition: elementscollectionmodel.cpp:35
ElementCollectionHandler::copy
ElementsLocation copy(ElementsLocation &source, ElementsLocation &destination)
ElementCollectionHandler::copy Copy the content of collection represented by source to the collection...
Definition: elementcollectionhandler.cpp:321
XmlProjectElementCollectionItem::isElement
bool isElement() const override
XmlProjectElementCollectionItem::isElement.
Definition: xmlprojectelementcollectionitem.cpp:44
ElementsLocation::fileName
QString fileName() const
ElementLocation::fileName.
Definition: elementslocation.cpp:793
ElementsCollectionModel::loadCollections
void loadCollections(bool common_collection, bool custom_collection, QList< QETProject * > projects)
ElementsCollectionModel::loadCollections Load the several collections in this model....
Definition: elementscollectionmodel.cpp:259
ElementsCollectionModel::removeProject
void removeProject(QETProject *project)
ElementsCollectionModel::removeProject Remove project from this model.
Definition: elementscollectionmodel.cpp:424
elementscollectionmodel.h
ElementsCollectionModel::items
QList< ElementCollectionItem * > items() const
ElementsCollectionModel::items.
Definition: elementscollectionmodel.cpp:490
ElementCollectionItem::lastItemForPath
ElementCollectionItem * lastItemForPath(const QString &path, QString &no_found_path)
ElementCollectionItem::lastItemForPath Return the last existing item in this ElementCollectionItem hi...
Definition: elementcollectionitem.cpp:52
ElementsCollectionModel::projectItems
QList< ElementCollectionItem * > projectItems(QETProject *project) const
ElementsCollectionModel::projectItems.
Definition: elementscollectionmodel.cpp:508
ElementCollectionItem::collectionPath
virtual QString collectionPath() const =0
elementcollectionitem.h
XmlElementCollection
The XmlElementCollection class This class represent a collection of elements stored to xml.
Definition: xmlelementcollection.h:34
XmlProjectElementCollectionItem::collectionPath
QString collectionPath() const override
XmlProjectElementCollectionItem::collectionPath.
Definition: xmlprojectelementcollectionitem.cpp:86
ElementCollectionItem::clearData
virtual void clearData()
ElementCollectionItem::clearData Reset the data.
Definition: elementcollectionitem.cpp:32
xmlelementcollection.h
ElementsCollectionModel::addProject
void addProject(QETProject *project, bool set_data=true)
ElementsCollectionModel::addProject Add project to this model.
Definition: elementscollectionmodel.cpp:391
ElementsCollectionModel::project
QList< QETProject * > project() const
ElementsCollectionModel::project.
Definition: elementscollectionmodel.cpp:455
FileElementCollectionItem::Type
@ Type
Definition: fileelementcollectionitem.h:34
ElementCollectionItem
The ElementCollectionItem class This class represent a item (a directory or an element) in a element ...
Definition: elementcollectionitem.h:30
XmlElementCollection::elementAdded
void elementAdded(QString collection_path)
elementAdded This signal is emited when a element is added to this collection
ElementCollectionItem::addChildAtPath
virtual void addChildAtPath(const QString &collection_name)=0
ElementsCollectionModel::m_items_list_to_setUp
QList< ElementCollectionItem * > m_items_list_to_setUp
Definition: elementscollectionmodel.h:77
qetapp.h
ElementsCollectionModel::loadingProgressValueChanged
void loadingProgressValueChanged(int)
ElementsCollectionModel::m_future
QFuture< void > m_future
Definition: elementscollectionmodel.h:76
ElementCollectionHandler
The ElementCollectionHandler class Provide several method to copy element or directory from a collect...
Definition: elementcollectionhandler.h:109
FileElementCollectionItem::type
int type() const override
Definition: fileelementcollectionitem.h:35
ElementCollectionItem::setUpData
virtual void setUpData()=0
ElementsCollectionModel::elementIntegratedToCollection
void elementIntegratedToCollection(const QString &path)
ElementsCollectionModel::elementIntegratedToCollection When an element is added to embedded collectio...
Definition: elementscollectionmodel.cpp:583
FileElementCollectionItem::fileSystemPath
QString fileSystemPath() const
FileElementCollectionItem::fileSystemPath.
Definition: fileelementcollectionitem.cpp:61
elementcollectionhandler.h
ElementsCollectionModel::addCustomCollection
void addCustomCollection(bool set_data=true)
ElementsCollectionModel::addCustomCollection Add the custom elements collection to this model.
Definition: elementscollectionmodel.cpp:316
ElementsCollectionModel::mimeData
QMimeData * mimeData(const QModelIndexList &indexes) const override
ElementsCollectionModel::mimeData Reimplemented from QStandardItemModel.
Definition: elementscollectionmodel.cpp:67
ElementsCollectionModel::m_hide_element
bool m_hide_element
Definition: elementscollectionmodel.h:75
XmlProjectElementCollectionItem::setUpData
void setUpData() override
XmlProjectElementCollectionItem::setUpData SetUp the data of this item.
Definition: xmlprojectelementcollectionitem.cpp:191
XmlElementCollection::directoryRemoved
void directoryRemoved(QString collection_path)
directoryRemoved This signal is emited when a directory is removed to this collection
ElementsCollectionModel::hideElement
void hideElement()
ElementsCollectionModel::hideElement Hide element in this model, only directory is managed.
Definition: elementscollectionmodel.cpp:526
elementslocation.h
ElementsCollectionModel::isHideElement
bool isHideElement()
Definition: elementscollectionmodel.h:59
ElementCollectionItem::itemAtPath
ElementCollectionItem * itemAtPath(const QString &path)
ElementCollectionItem::itemAtPath.
Definition: elementcollectionitem.cpp:151
FileElementCollectionItem
The FileElementCollectionItem class This class specialise ElementCollectionItem for manage a collecti...
Definition: fileelementcollectionitem.h:30
XmlProjectElementCollectionItem::Type
@ Type
Definition: xmlprojectelementcollectionitem.h:36
ElementsCollectionModel::addCommonCollection
void addCommonCollection(bool set_data=true)
ElementsCollectionModel::addCommonCollection Add the common elements collection to this model.
Definition: elementscollectionmodel.cpp:297
XmlElementCollection::elementRemoved
void elementRemoved(QString collection_path)
elementRemoved This signal is emited when an element is removed to this collection
QETApp::customElementsDirN
static QString customElementsDirN()
QETApp::customElementsDirN like QString QETApp::customElementsDir but without "/" at the end.
Definition: qetapp.cpp:705
ElementsCollectionModel::loadingFinished
void loadingFinished()
ElementsLocation::isProject
bool isProject() const
ElementsLocation::isProject.
Definition: elementslocation.cpp:459
qetproject.h
xmlprojectelementcollectionitem.h
ElementsLocation::collectionPath
QString collectionPath(bool protocol=true) const
ElementsLocation::collectionPath Return the path of the represented element relative to collection if...
Definition: elementslocation.cpp:160
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
ElementsLocation::isCommonCollection
bool isCommonCollection() const
ElementsLocation::isCommonCollection.
Definition: elementslocation.cpp:440
ElementsCollectionModel::loadingProgressRangeChanged
void loadingProgressRangeChanged(int, int)
QETProject
Definition: qetproject.h:51
QETApp::commonElementsDirN
static QString commonElementsDirN()
QETApp::commonElementsDirN like QString QETApp::commonElementsDir but without "/" at the end.
Definition: qetapp.cpp:693
ElementsCollectionModel::indexFromLocation
QModelIndex indexFromLocation(const ElementsLocation &location)
ElementsCollectionModel::indexFromLocation Return the index who represent location....
Definition: elementscollectionmodel.cpp:543
FileElementCollectionItem::setUpData
void setUpData() override
FileElementCollectionItem::setUpData SetUp the data of this item.
Definition: fileelementcollectionitem.cpp:264
XmlProjectElementCollectionItem::setProject
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...
Definition: xmlprojectelementcollectionitem.cpp:175
FileElementCollectionItem::collectionPath
QString collectionPath() const override
FileElementCollectionItem::collectionPath.
Definition: fileelementcollectionitem.cpp:191
ElementsCollectionModel::data
QVariant data(const QModelIndex &index, int role) const override
ElementsCollectionModel::data Reimplemented from QStandardItemModel.
Definition: elementscollectionmodel.cpp:47
ElementCollectionItem::type
int type() const override
Definition: elementcollectionitem.h:35
FileElementCollectionItem::isCustomCollection
bool isCustomCollection() const
FileElementCollectionItem::isCustomCollection.
Definition: fileelementcollectionitem.cpp:238
ElementsCollectionModel
Definition: elementscollectionmodel.h:32
XmlProjectElementCollectionItem
The XmlProjectElementCollectionItem class This class specialise ElementCollectionItem for manage an x...
Definition: xmlprojectelementcollectionitem.h:32
FileElementCollectionItem::isElement
bool isElement() const override
FileElementCollectionItem::isElement.
Definition: fileelementcollectionitem.cpp:106
ElementsCollectionModel::mimeTypes
QStringList mimeTypes() const override
ElementsCollectionModel::mimeTypes Reimplemented from QStandardItemModel.
Definition: elementscollectionmodel.cpp:94
ElementsLocation::project
QETProject * project() const
ElementsLocation::project.
Definition: elementslocation.cpp:365
ElementCollectionItem::isElement
virtual bool isElement() const =0
XmlProjectElementCollectionItem::type
int type() const override
Definition: xmlprojectelementcollectionitem.h:37
XmlElementCollection::elementChanged
void elementChanged(QString collection_path)
elementChanged This signal is emited when the defintion of the element at path was changed
ElementsLocation::isCustomCollection
bool isCustomCollection() const
ElementsLocation::isCustomCollection.
Definition: elementslocation.cpp:450
FileElementCollectionItem::addChildAtPath
void addChildAtPath(const QString &collection_name) override
FileElementCollectionItem::addChildAtPath Ask to this item item to add a child with collection name c...
Definition: fileelementcollectionitem.cpp:249
ElementsCollectionModel::m_project_list
QList< QETProject * > m_project_list
Definition: elementscollectionmodel.h:73
ElementsCollectionModel::m_project_hash
QHash< QETProject *, XmlProjectElementCollectionItem * > m_project_hash
Definition: elementscollectionmodel.h:74
fileelementcollectionitem.h
FileElementCollectionItem::isCommonCollection
bool isCommonCollection() const
FileElementCollectionItem::isCommonCollection.
Definition: fileelementcollectionitem.cpp:229
ElementsCollectionModel::canDropMimeData
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
ElementsCollectionModel::canDropMimeData Reimplemented from QStandardItemModel.
Definition: elementscollectionmodel.cpp:112
ElementsCollectionModel::highlightUnusedElement
void highlightUnusedElement()
ElementsCollectionModel::highlightUnusedElement Highlight every unused element of managed project.
Definition: elementscollectionmodel.cpp:465
ElementsCollectionModel::dropMimeData
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
ElementsCollectionModel::dropMimeData Reimplemented from QStandardItemModel.
Definition: elementscollectionmodel.cpp:163
XmlProjectElementCollectionItem::setUpIcon
void setUpIcon() override
XmlProjectElementCollectionItem::setUpIcon SetUp the icon of this item. Because icon use several memo...
Definition: xmlprojectelementcollectionitem.cpp:223