Salome HOME
Updated copyright comment
[modules/yacs.git] / src / genericgui / SchemaModel.hxx
1 // Copyright (C) 2006-2024  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 _SCHEMAMODEL_HXX_
21 #define _SCHEMAMODEL_HXX_
22
23 #include <QAbstractItemModel>
24 #include <QItemSelection>
25 #include <QBrush>
26 #include "guiObservers.hxx"
27 #include <list>
28
29 namespace YACS
30 {
31   namespace HMI
32   {
33     typedef enum
34       {
35         YLabel = 0,
36         YType  = 1,
37         YValue = 2,
38         YState = 2,
39       } columnId;
40
41     class SchemaItem;
42     class SchemaNodeItem;
43     class SchemaComposedNodeItem;
44     class SchemaDirTypesItem;
45     class SchemaDirLinksItem;
46     class SchemaDirContainersItem;
47     class SchemaContainerItem;
48
49     class SchemaModel: public QAbstractItemModel, public GuiObserver
50     {
51       Q_OBJECT
52
53       friend class SchemaItem;
54       friend class SchemaNodeItem;
55       friend class SchemaComposedNodeItem;
56       friend class SchemaDirTypesItem;
57       friend class SchemaDirLinksItem;
58       friend class SchemaDirContainersItem;
59       friend class SchemaContainerItem;
60       friend class SchemaComponentItem;
61
62     public:
63       SchemaModel(YACS::HMI::Subject *context,
64                   QObject * parent = 0);
65       virtual ~SchemaModel();
66
67       virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
68       virtual QModelIndex parent(const QModelIndex &index) const;
69       virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
70       virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
71       virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
72       virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
73
74       virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
75       virtual Qt::ItemFlags flags(const QModelIndex &index) const;
76
77       virtual void update(GuiEvent event, int type, Subject* son);
78       inline SchemaItem * getRootItem() {return _rootItem; };
79       inline bool isEdition() {return _isEdition; };
80       void setEdition(bool isEdition = true);
81
82       const QBrush& stdBackBrush();
83       const QBrush& editedBackBrush();
84       const QBrush& emphasizeBackBrush();
85
86       virtual QMimeData* mimeData(const QModelIndexList &indexes) const;
87       virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action,
88                                 int row, int column, const QModelIndex& parent);
89       virtual Qt::DropActions supportedDropActions() const;
90       virtual QStringList mimeTypes() const;
91
92     public slots:
93     void updateSelection(const QItemSelection &selected, const QItemSelection &deselected);
94
95     signals:
96     void signalSelection(const QModelIndex &index);
97
98     protected:
99       void setNewRoot(YACS::HMI::Subject *root);
100
101       Subject *_context;
102       Subject *_root;
103       SchemaItem *_rootItem;
104
105       QBrush _stdBackBrush;
106       QBrush _editedBackBrush;
107       QBrush _emphasizeBackBrush;
108       bool _isEdition;
109     };
110
111   }
112 }
113
114 #endif