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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #ifndef HYDROGUI_ListModel_H
20 #define HYDROGUI_ListModel_H
23 #include <HYDROData_Entity.h>
24 #include <QAbstractListModel>
27 const int HYDROGUI_VisibleRole = Qt::UserRole + 1;
28 const int HYDROGUI_EntryRole = Qt::UserRole + 2;
31 * \class HYDROGUI_ListModel
32 * \brief The class representing custom list model for the Z levels
34 class HYDRO_EXPORT HYDROGUI_ListModel : public QAbstractListModel
39 enum OpType { Top, Up, Down, Bottom, DragAndDrop };
41 typedef QPair<Handle(HYDROData_Entity), bool> Object2Visible;
42 typedef QList<Object2Visible> Object2VisibleList;
43 typedef QList<Handle(HYDROData_Entity)> ObjectList;
46 HYDROGUI_ListModel( QObject* theParent = 0 );
47 virtual ~HYDROGUI_ListModel();
49 virtual QVariant data( const QModelIndex &theIndex, int theRole = Qt::DisplayRole ) const;
51 virtual int rowCount( const QModelIndex &theParent = QModelIndex() ) const;
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;
63 QList<int> getIds( const QModelIndexList& theIndexes, bool theIsToSort = true ) const;
65 void setObjects( const Object2VisibleList& theObjects );
66 ObjectList getObjects() const;
68 void addObject( const Object2Visible& theObject );
69 void removeObjectByName( const QString& theObjectName );
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 );
76 void setDecorationEnabled( const bool theIsToEnable );
81 bool isObjectVisible( int theIndex ) const;
82 bool isDragAndDropAllowed( const QList<int>& theItems, const int theDropItem ) const;
85 friend class test_HYDROGUI_ListModel;
87 Object2VisibleList myObjects, myPrevObjects;
88 QPixmap myEmpty, myEye;
90 bool myIsDecorationEnabled;