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.
23 class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel, public Events_Listener
27 XGUI_DataModel(QObject* theParent);
29 /// Event Listener method
30 /// \param theMessage an event message
31 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
33 //! Returns an object by the given Model index.
34 //! Returns 0 if the given index is not index of an object
35 virtual ObjectPtr object(const QModelIndex& theIndex) const;
37 //! Returns index of the object
38 //! \param theObject object to find
39 virtual QModelIndex objectIndex(const ObjectPtr theObject) const;
41 //! Clear internal data
45 virtual void rebuildDataTree();
48 /// Returns the data stored under the given role for the item referred to by the index.
49 /// \param theIndex a model index
50 /// \param theRole a data role (see Qt::ItemDataRole)
51 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
53 /// Returns the data for the given role and section in the header with the specified orientation.
54 /// \param theSection a section
55 /// \param theOrient an orientation
56 /// \param theRole a data role (see Qt::ItemDataRole)
57 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
58 Qt::DisplayRole) const;
60 /// Returns the number of rows under the given parent. When the parent is valid it means that
61 /// rowCount is returning the number of children of parent.
62 /// \param theParent a parent model index
63 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
65 /// Returns the number of columns for the children of the given parent.
66 /// It has a one column
67 /// \param theParent a parent model index
68 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
70 /// Returns the index of the item in the model specified by the given row, column and parent index.
71 /// \param theRow a row
72 /// \param theColumn a column
73 /// \param theParent a parent model index
74 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent =
77 /// Returns the parent of the model item with the given index.
78 /// If the item has no parent, an invalid QModelIndex is returned.
79 /// \param theIndex a model index
80 virtual QModelIndex parent(const QModelIndex& theIndex) const;
82 /// Returns true if parent has any children; otherwise returns false.
83 /// \param theParent a parent model index
84 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
86 /// Inserts count rows into the model before the given row.
87 /// Items in the new row will be children of the item represented by the parent model index.
88 /// \param theRow a start row
89 /// \param theCount a nember of rows to insert
90 /// \param theParent a parent model index
91 virtual bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
93 /// Removes count rows starting with the given row under parent parent from the model.
94 /// \param theRow a start row
95 /// \param theCount a nember of rows to remove
96 /// \param theParent a parent model index
97 virtual bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
101 Config_DataModelReader myXMLReader;