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