Salome HOME
Renaming, add selector for selection synchronization.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ListModel.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_ListModel_H
24 #define HYDROGUI_ListModel_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 const int HYDROGUI_EntryRole   = Qt::UserRole + 2;
33
34 /** 
35  * \class HYDROGUI_ListModel
36  * \brief The class representing custom list model for the Z levels
37  */
38 class HYDRO_EXPORT HYDROGUI_ListModel : public QAbstractListModel
39 {
40   Q_OBJECT
41
42 public:
43   enum OpType { Top, Up, Down, Bottom, DragAndDrop };
44
45   typedef QPair<Handle(HYDROData_Entity), bool> Object2Visible;
46   typedef QList<Object2Visible> Object2VisibleList;
47   typedef QList<Handle(HYDROData_Entity)> ObjectList;
48
49 public:
50   HYDROGUI_ListModel( QObject* theParent = 0 );
51   virtual ~HYDROGUI_ListModel();
52
53   virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;  
54
55   virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
56
57   virtual QVariant headerData( int theSection,
58                                Qt::Orientation theOrientation,
59                                int theRole = Qt::DisplayRole ) const;
60   virtual Qt::ItemFlags flags( const QModelIndex& theIndex ) const;
61   virtual QMimeData* mimeData( const QModelIndexList& theIndexes ) const;
62   virtual QStringList mimeTypes() const;
63   virtual bool dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
64                              int theRow, int theColumn, const QModelIndex& theParent );
65   virtual Qt::DropActions supportedDropActions() const;
66
67   QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
68
69   void setObjects( const Object2VisibleList& theObjects );
70   ObjectList getObjects() const;
71
72   bool move( const int theItem, const OpType theType, bool theIsVisibleOnly,
73              const int theDropItem = -1 );
74   bool move( const QList<int>& theItems, const OpType theType, bool theIsVisibleOnly,
75              const int theDropItem = -1 );
76
77 protected:
78   bool isObjectVisible( int theIndex ) const;
79   bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
80
81 private:
82   friend class test_HYDROGUI_ListModel;
83
84   Object2VisibleList myObjects;
85   QPixmap myEmpty, myEye;
86 };
87
88 #endif