Salome HOME
Start using new display order from the data model.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ZLevelsModel.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef HYDROGUI_ZLEVELSMODEL_H
24 #define HYDROGUI_ZLEVELSMODEL_H
25
26 #include <HYDROGUI.h>
27 #include <HYDROData_Entity.h>
28 #include <QAbstractListModel>
29 #include <QPixmap>
30
31 const int HYDROGUI_VisibleRole = Qt::UserRole + 1;
32
33 /** 
34  * \class HYDROGUI_ZLevelsModel
35  * \brief The class representing custom list model for the Z levels
36  */
37 class HYDRO_EXPORT HYDROGUI_ZLevelsModel : public QAbstractListModel
38 {
39   Q_OBJECT
40
41 public:
42   enum OpType { Top, Up, Down, Bottom, DragAndDrop };
43
44   typedef QPair<Handle(HYDROData_Entity), bool> Object2Visible;
45   typedef QList<Object2Visible> Object2VisibleList;
46   typedef QList<Handle(HYDROData_Entity)> ObjectList;
47
48 public:
49   HYDROGUI_ZLevelsModel( QObject* theParent = 0 );
50   virtual ~HYDROGUI_ZLevelsModel();
51
52   virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;  
53
54   virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
55
56   virtual QVariant headerData( int theSection,
57                                Qt::Orientation theOrientation,
58                                int theRole = Qt::DisplayRole ) const;
59   virtual Qt::ItemFlags flags( const QModelIndex& theIndex ) const;
60   virtual QMimeData* mimeData( const QModelIndexList& theIndexes ) const;
61   virtual QStringList mimeTypes() const;
62   virtual bool dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
63                              int theRow, int theColumn, const QModelIndex& theParent );
64   virtual Qt::DropActions supportedDropActions() const;
65
66   QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
67
68   void setObjects( const Object2VisibleList& theObjects );
69   ObjectList getObjects() const;
70
71   bool move( const int theItem, const OpType theType, bool theIsVisibleOnly,
72              const int theDropItem = -1 );
73   bool move( const QList<int>& theItems, const OpType theType, bool theIsVisibleOnly,
74              const int theDropItem = -1 );
75
76 protected:
77   bool isObjectVisible( int theIndex ) const;
78   bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
79
80 private:
81   friend class test_HYDROGUI_ZLevelsModel;
82
83   Object2VisibleList myObjects;
84   QPixmap myEmpty, myEye;
85 };
86
87 #endif