Salome HOME
bug fixes/improvements (678, 681, 679, etc..)
[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 public:
37   enum OpType { Top, Up, Down, Bottom, DragAndDrop };
38
39   typedef QPair<Handle(HYDROData_Entity), bool> Object2Visible;
40   typedef QList<Object2Visible> Object2VisibleList;
41   typedef QList<Handle(HYDROData_Entity)> ObjectList;
42
43 public:
44   HYDROGUI_ListModel( QObject* theParent = 0 );
45   virtual ~HYDROGUI_ListModel();
46
47   virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;  
48
49   virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
50
51   virtual QVariant headerData( int theSection,
52                                Qt::Orientation theOrientation,
53                                int theRole = Qt::DisplayRole ) const;
54   virtual Qt::ItemFlags flags( const QModelIndex& theIndex ) const;
55   virtual QMimeData* mimeData( const QModelIndexList& theIndexes ) const;
56   virtual QStringList mimeTypes() const;
57   virtual bool dropMimeData( const QMimeData* theData, Qt::DropAction theAction,
58                              int theRow, int theColumn, const QModelIndex& theParent );
59   virtual Qt::DropActions supportedDropActions() const;
60
61   QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
62
63   void setObjects( const Object2VisibleList& theObjects );
64   ObjectList getObjects() const;
65
66   void addObject( const Object2Visible& theObject );
67   void removeObjectByName( const QString& theObjectName );
68
69   bool move( const int theItem, const OpType theType, bool theIsVisibleOnly,
70              const int theDropItem = -1 );
71   bool move( const QList<int>& theItems, const OpType theType, bool theIsVisibleOnly,
72              const int theDropItem = -1 );
73
74   void setDecorationEnabled( const bool theIsToEnable );
75
76   void undoLastMove();
77
78 protected:
79   bool isObjectVisible( int theIndex ) const;
80   bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
81
82 private:
83   friend class test_HYDROGUI_ListModel;
84
85   Object2VisibleList myObjects, myPrevObjects;
86   QPixmap myEmpty, myEye;
87
88   bool myIsDecorationEnabled;
89 };
90
91 #endif