SHAPER 9.16.0
XGUI_DataModel.h
1// Copyright (C) 2014-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef XGUI_DataModel_H
21#define XGUI_DataModel_H
22
23#include "XGUI.h"
24#include <ModuleBase_Definitions.h>
25#include <ModelAPI_Object.h>
26#include <ModelAPI_Document.h>
27#include <Events_Listener.h>
28
29#include <QAbstractItemModel>
30
31class XGUI_Workshop;
33
45class XGUI_EXPORT XGUI_DataModel : public QAbstractItemModel, public Events_Listener
46{
47Q_OBJECT
48public:
51 XGUI_DataModel(QObject* theParent);
52
54 virtual ~XGUI_DataModel();
55
56
57 void setRoot(ModuleBase_ITreeNode* theRoot) { myRoot = theRoot; }
58
59 ModuleBase_ITreeNode* root() const { return myRoot; }
60
63 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
64
67 virtual ObjectPtr object(const QModelIndex& theIndex) const;
68
71 virtual QModelIndex objectIndex(const ObjectPtr theObject, int theColumn = 1) const;
72
74 virtual void clear();
75
77 virtual void rebuildDataTree();
78
82 virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
83
88 virtual QVariant headerData(int theSection, Qt::Orientation theOrient, int theRole =
89 Qt::DisplayRole) const;
90
94 virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
95
99 virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
100
106 virtual QModelIndex index(int theRow, int theColumn, const QModelIndex &theParent =
107 QModelIndex()) const;
108
112 virtual QModelIndex parent(const QModelIndex& theIndex) const;
113
116 virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
117
123 virtual bool insertRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
124
129 virtual bool removeRows(int theRow, int theCount, const QModelIndex& theParent = QModelIndex());
130
133 virtual Qt::ItemFlags flags(const QModelIndex& theIndex) const;
134
136 virtual bool canDropMimeData(const QMimeData *theData, Qt::DropAction theAction,
137 int theRow, int theColumn, const QModelIndex &theParent) const override;
138
140 virtual QMimeData* mimeData(const QModelIndexList &indexes) const override;
141
143 virtual bool dropMimeData(const QMimeData *theData, Qt::DropAction theAction,
144 int theRow, int theColumn, const QModelIndex &theParent) override;
145
148 QModelIndex documentRootIndex(DocumentPtr theDoc, int theColumn = 1) const;
149
153 bool hasHiddenState(const QModelIndex& theIndex);
154
157 bool hasIndex(const QModelIndex& theIndex) const;
158
161 bool hasNode(ModuleBase_ITreeNode* theNode) const;
162
165 DocumentPtr document(const QModelIndex& theIndex) const;
166
170 QModelIndex getIndex(ModuleBase_ITreeNode* theNode, int thCol) const;
171
173 virtual Qt::DropActions supportedDropActions() const override
174 {
175 return Qt::MoveAction;
176 }
177
178signals:
181
184
185private:
186 enum VisibilityState {
187 NoneState,
188 Visible,
189 SemiVisible,
190 Hidden };
191
192
193 QModelIndex getParentIndex(ModuleBase_ITreeNode* theNode, int thCol) const;
194
195 void updateSubTree(ModuleBase_ITreeNode* theParent);
196
197 XGUI_Workshop* myWorkshop;
198 QMap<DocumentPtr, QStringList> myShownFolders;
199
200 ModuleBase_ITreeNode* myRoot;
201};
202
203#endif
Base interface for any event listener.
Definition: Events_Listener.h:37
virtual EVENTS_EXPORT void processEvent(const std::shared_ptr< Events_Message > &theMessage)=0
This method is called by loop when the event is started to process.
Definition: ModuleBase_ITreeNode.h:44
This is a data model for Object Browser (QTreeView).
Definition: XGUI_DataModel.h:46
void beforeTreeRebuild()
Signal send before tree rebuild.
virtual Qt::DropActions supportedDropActions() const override
Allows to support drag and drop of some model items.
Definition: XGUI_DataModel.h:173
void treeRebuilt()
Signal about tree had been rebuilt.
Class which defines a configuration of the application (Workshop) and launches it.
Definition: XGUI_Workshop.h:83