1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_DataModel.h
4 // Created: 21 Jul 2015
5 // Author: Vitaly SMETANNIKOV
8 #ifndef XGUI_DataModel_H
9 #define XGUI_DataModel_H
12 #include <ModelAPI_Object.h>
13 #include <ModelAPI_Document.h>
14 #include <Config_DataModelReader.h>
15 #include <QAbstractItemModel>
16 #include <Events_Listener.h>
19 /**\class XGUI_DataModel
21 * \brief This is a data model for Object Browser (QTreeView).
22 * It uses XML file for definition of data tree.
23 * Some tips about organization of the model:
24 * - Non Valid Index - root index
25 * - An index with internal Id == -1 is a folder of root document
26 * - An index which contains internal pointer as ModelAPI_Object its the object
27 * - An index which contains internal pointer as ModelAPI_Document is a folder which belongs to this document
29 class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel, public Events_Listener
33 XGUI_DataModel(QObject* theParent);
35 /// Event Listener method
36 /// \param theMessage an event message
37 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
39 //! Returns an object by the given Model index.
40 //! Returns 0 if the given index is not index of an object
41 virtual ObjectPtr object(const QModelIndex& theIndex) const;
43 //! Returns index of the object
44 //! \param theObject object to find
45 virtual QModelIndex objectIndex(const ObjectPtr theObject) const;
47 //! Clear internal data
51 virtual void rebuildDataTree();
54 /// Returns the data stored under the given role for the item referred to by the index.
55 /// \param theIndex a model index
56 /// \param theRole a data role (see Qt::ItemDataRole)
57 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
59 /// Returns the data for the given role and section in the header with the specified orientation.
60 /// \param theSection a section
61 /// \param theOrient an orientation
62 /// \param theRole a data role (see Qt::ItemDataRole)
63 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
64 Qt::DisplayRole) const;
66 /// Returns the number of rows under the given parent. When the parent is valid it means that
67 /// rowCount is returning the number of children of parent.
68 /// \param theParent a parent model index
69 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
71 /// Returns the number of columns for the children of the given parent.
72 /// It has a one column
73 /// \param theParent a parent model index
74 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
76 /// Returns the index of the item in the model specified by the given row, column and parent index.
77 /// \param theRow a row
78 /// \param theColumn a column
79 /// \param theParent a parent model index
80 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent =
83 /// Returns the parent of the model item with the given index.
84 /// If the item has no parent, an invalid QModelIndex is returned.
85 /// \param theIndex a model index
86 virtual QModelIndex parent(const QModelIndex& theIndex) const;
88 /// Returns true if parent has any children; otherwise returns false.
89 /// \param theParent a parent model index
90 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
92 /// Inserts count rows into the model before the given row.
93 /// Items in the new row will be children of the item represented by the parent model index.
94 /// \param theRow a start row
95 /// \param theCount a nember of rows to insert
96 /// \param theParent a parent model index
97 virtual bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
99 /// Removes count rows starting with the given row under parent parent from the model.
100 /// \param theRow a start row
101 /// \param theCount a nember of rows to remove
102 /// \param theParent a parent model index
103 virtual bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
105 /// Returns the item flags for the given index.
106 /// \param theIndex a model index
107 virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
109 /// Returns an index which is root of the given document
110 /// \param theDoc a document
111 QModelIndex documentRootIndex(DocumentPtr theDoc) const;
113 /// Returns last history object index
114 virtual QModelIndex lastHistoryIndex() const;
117 /// Find a root index which contains objects of the given document
118 /// \param theDoc the document object
119 QModelIndex findDocumentRootIndex(const ModelAPI_Document* theDoc) const;
121 /// Returns number of folders in document. Considered folders which has to be shown only if they are not empty.
122 /// \param theDoc document which has to be checked. If 0 then Root document will be considered
123 int foldersCount(ModelAPI_Document* theDoc = 0) const;
125 /// Returns list of folders types which can not be shown empty
126 /// \param fromRoot - root document flag
127 QStringList listOfShowNotEmptyFolders(bool fromRoot = true) const;
129 Config_DataModelReader myXMLReader;