Salome HOME
Initial merge of branch 'BR_HYDRO_IMPS_2016' into BR_PORTING_OCCT_7
[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 #include <QMap>
27 #include <QColor>
28
29 const int HYDROGUI_VisibleRole = Qt::UserRole + 1;
30 const int HYDROGUI_EntryRole   = Qt::UserRole + 2;
31
32 /** 
33  * \class HYDROGUI_ListModel
34  * \brief The class representing custom list model for the Z levels
35  */
36 class HYDRO_EXPORT HYDROGUI_ListModel : public QAbstractListModel
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   virtual Qt::DropActions supportedDragActions() const;
63
64   QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
65
66   void setObjects( const Object2VisibleList& theObjects );
67   ObjectList getObjects() const;
68
69   void addObject( const Object2Visible& theObject );
70   void removeObjectByName( const QString& theObjectName );
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   void setDecorationEnabled( const bool theIsToEnable );
78
79   void undoLastMove();
80
81   void setBackgroundColor(int theInd, const QColor theColor);
82   QColor getBackgroundColor(int theInd) const;
83   void clearAllBackgroundColors ();
84
85 protected:
86   bool isObjectVisible( int theIndex ) const;
87   bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
88
89 private:
90   friend class test_HYDROGUI_ListModel;
91
92   Object2VisibleList myObjects, myPrevObjects;
93   QPixmap myEmpty, myEye;
94   QMap<int, QColor> myColoredRow;
95
96   bool myIsDecorationEnabled;
97 };
98
99 #endif