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 <Config_DataModelReader.h>
14 #include <QAbstractItemModel>
15 #include <Events_Listener.h>
18 /**\class XGUI_DataModel
20 * \brief This is a data model for Object Browser (QTreeView).
21 * It uses XML file for definition of data tree.
22 * Some tips about organization of the model:
23 * - Non Valid Index - root index
24 * - An index with internal Id == -1 is a folder of root document
25 * - An index which contains internal pointer as ModelAPI_Object its the object
26 * - An index which contains internal pointer as ModelAPI_Document is a folder which belongs to this document
28 class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel, public Events_Listener
32 XGUI_DataModel(QObject* theParent);
34 /// Event Listener method
35 /// \param theMessage an event message
36 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
38 //! Returns an object by the given Model index.
39 //! Returns 0 if the given index is not index of an object
40 virtual ObjectPtr object(const QModelIndex& theIndex) const;
42 //! Returns index of the object
43 //! \param theObject object to find
44 virtual QModelIndex objectIndex(const ObjectPtr theObject) const;
46 //! Clear internal data
50 virtual void rebuildDataTree();
53 /// Returns the data stored under the given role for the item referred to by the index.
54 /// \param theIndex a model index
55 /// \param theRole a data role (see Qt::ItemDataRole)
56 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
58 /// Returns the data for the given role and section in the header with the specified orientation.
59 /// \param theSection a section
60 /// \param theOrient an orientation
61 /// \param theRole a data role (see Qt::ItemDataRole)
62 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
63 Qt::DisplayRole) const;
65 /// Returns the number of rows under the given parent. When the parent is valid it means that
66 /// rowCount is returning the number of children of parent.
67 /// \param theParent a parent model index
68 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
70 /// Returns the number of columns for the children of the given parent.
71 /// It has a one column
72 /// \param theParent a parent model index
73 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
75 /// Returns the index of the item in the model specified by the given row, column and parent index.
76 /// \param theRow a row
77 /// \param theColumn a column
78 /// \param theParent a parent model index
79 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent =
82 /// Returns the parent of the model item with the given index.
83 /// If the item has no parent, an invalid QModelIndex is returned.
84 /// \param theIndex a model index
85 virtual QModelIndex parent(const QModelIndex& theIndex) const;
87 /// Returns true if parent has any children; otherwise returns false.
88 /// \param theParent a parent model index
89 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
91 /// Inserts count rows into the model before the given row.
92 /// Items in the new row will be children of the item represented by the parent model index.
93 /// \param theRow a start row
94 /// \param theCount a nember of rows to insert
95 /// \param theParent a parent model index
96 virtual bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
98 /// Removes count rows starting with the given row under parent parent from the model.
99 /// \param theRow a start row
100 /// \param theCount a nember of rows to remove
101 /// \param theParent a parent model index
102 virtual bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
104 /// Returns the item flags for the given index.
105 /// \param theIndex a model index
106 virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
110 Config_DataModelReader myXMLReader;