Salome HOME
Merge remote-tracking branch 'origin/BR_IMPROVEMENTS' into BR_v14_rc
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ListModel.h
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #ifndef HYDROGUI_ListModel_H
20 #define HYDROGUI_ListModel_H
21
22 #include <HYDROGUI.h>
23 #include <HYDROData_Entity.h>
24 #include <QAbstractListModel>
25 #include <QPixmap>
26
27 const int HYDROGUI_VisibleRole = Qt::UserRole + 1;
28 const int HYDROGUI_EntryRole   = Qt::UserRole + 2;
29
30 /** 
31  * \class HYDROGUI_ListModel
32  * \brief The class representing custom list model for the Z levels
33  */
34 class HYDRO_EXPORT HYDROGUI_ListModel : public QAbstractListModel
35 {
36   Q_OBJECT
37
38 public:
39   enum OpType { Top, Up, Down, Bottom, DragAndDrop };
40
41   typedef QPair<Handle(HYDROData_Entity), bool> Object2Visible;
42   typedef QList<Object2Visible> Object2VisibleList;
43   typedef QList<Handle(HYDROData_Entity)> ObjectList;
44
45 public:
46   HYDROGUI_ListModel( QObject* theParent = 0 );
47   virtual ~HYDROGUI_ListModel();
48
49   virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;  
50
51   virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
52
53   virtual QVariant headerData( int theSection,
54                                Qt::Orientation theOrientation,
55                                int theRole = Qt::DisplayRole ) const;
56   virtual Qt::ItemFlags flags( const QModelIndex& theIndex ) const;
57   virtual QMimeData* mimeData( const QModelIndexList& theIndexes ) const;
58   virtual QStringList mimeTypes() const;
59   virtual bool dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
60                              int theRow, int theColumn, const QModelIndex& theParent );
61   virtual Qt::DropActions supportedDropActions() const;
62
63   QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
64
65   void setObjects( const Object2VisibleList& theObjects );
66   ObjectList getObjects() const;
67
68   void addObject( const Object2Visible& theObject );
69   void removeObjectByName( const QString& theObjectName );
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   void setDecorationEnabled( const bool theIsToEnable );
77
78   void undoLastMove();
79
80 protected:
81   bool isObjectVisible( int theIndex ) const;
82   bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
83
84 private:
85   friend class test_HYDROGUI_ListModel;
86
87   Object2VisibleList myObjects, myPrevObjects;
88   QPixmap myEmpty, myEye;
89
90   bool myIsDecorationEnabled;
91 };
92
93 #endif