1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: SUIT_TreeModel.h
23 // Author: Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #ifndef SUIT_TREEMODEL_H
26 #define SUIT_TREEMODEL_H
32 #include <QAbstractItemModel>
33 #include <QSortFilterProxyModel>
34 #include <QModelIndex>
35 #include <QItemDelegate>
39 #pragma warning( disable:4251 )
42 class SUIT_DataObject;
45 class SUIT_EXPORT SUIT_AbstractModel
50 operator const QAbstractItemModel*() const;
51 operator QAbstractItemModel*();
52 operator const QObject*() const;
54 virtual SUIT_DataObject* root() const = 0;
55 virtual void setRoot( SUIT_DataObject* ) = 0;
56 virtual SUIT_DataObject* object( const QModelIndex& = QModelIndex() ) const = 0;
57 virtual QModelIndex index( const SUIT_DataObject*, int = 0 ) const = 0;
58 virtual bool autoDeleteTree() const = 0;
59 virtual void setAutoDeleteTree( const bool ) = 0;
60 virtual bool autoUpdate() const = 0;
61 virtual void setAutoUpdate( const bool ) = 0;
62 virtual QAbstractItemDelegate* delegate() const = 0;
63 virtual bool customSorting( const int ) const = 0;
64 virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const = 0;
66 virtual void updateTree( const QModelIndex& ) = 0;
67 virtual void updateTree( SUIT_DataObject* = 0 ) = 0;
69 virtual void registerColumn( const int group_id, const QString& name, const int custom_id ) = 0;
70 virtual void unregisterColumn( const int group_id, const QString& name ) = 0;
71 virtual void setColumnIcon( const QString& name, const QPixmap& icon ) = 0;
72 virtual QPixmap columnIcon( const QString& name ) const = 0;
73 virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr ) = 0;
74 virtual Qtx::Appropriate appropriate( const QString& name ) const = 0;
78 class SUIT_EXPORT SUIT_TreeModel : public QAbstractItemModel, public SUIT_AbstractModel
85 typedef SUIT_DataObject* ObjPtr;
86 typedef SUIT_TreeModel::TreeItem* ItemPtr;
91 DisplayRole = Qt::DisplayRole, //!< text label
92 DecorationRole = Qt::DecorationRole, //!< icon
93 EditRole = Qt::EditRole, //!< edit mode
94 ToolTipRole = Qt::ToolTipRole, //!< tooltip
95 StatusTipRole = Qt::StatusTipRole, //!< status tip
96 WhatsThisRole = Qt::WhatsThisRole, //!< what's this info
97 FontRole = Qt::FontRole, //!< font
98 TextAlignmentRole = Qt::TextAlignmentRole, //!< text alignment
99 BackgroundRole = Qt::BackgroundRole, //!< background color
100 ForegroundRole = Qt::ForegroundRole, //!< text color
101 CheckStateRole = Qt::CheckStateRole, //!< check state
102 SizeHintRole = Qt::SizeHintRole, //!< size hint
103 BaseColorRole = Qt::UserRole, //!< (editor) background color
104 TextColorRole, //!< (editor) text color (Qt::UserRole + 1)
105 HighlightRole, //!< highlight color (Qt::UserRole + 2)
106 HighlightedTextRole, //!< highlighted text color (Qt::UserRole + 3)
107 AppropriateRole = Qtx::AppropriateRole //!< appropriate flag (Qt::UserRole + 100)
110 SUIT_TreeModel( QObject* = 0 );
111 SUIT_TreeModel( SUIT_DataObject*, QObject* = 0 );
114 SUIT_DataObject* root() const;
115 void setRoot( SUIT_DataObject* );
117 virtual QVariant data( const QModelIndex&, int = DisplayRole ) const;
118 virtual bool setData( const QModelIndex&, const QVariant&, int = EditRole );
119 virtual Qt::ItemFlags flags( const QModelIndex& ) const;
120 virtual QVariant headerData( int, Qt::Orientation, int = Qt::DisplayRole ) const;
122 virtual QModelIndex index( int, int, const QModelIndex& = QModelIndex() ) const;
123 virtual QModelIndex parent( const QModelIndex& ) const;
125 virtual int columnCount( const QModelIndex& = QModelIndex() ) const;
126 virtual int rowCount( const QModelIndex& = QModelIndex() ) const;
127 virtual void registerColumn( const int group_id, const QString& name, const int custom_id );
128 virtual void unregisterColumn( const int group_id, const QString& name );
129 virtual void setColumnIcon( const QString& name, const QPixmap& icon );
130 virtual QPixmap columnIcon( const QString& name ) const;
131 virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr );
132 virtual Qtx::Appropriate appropriate( const QString& name ) const;
134 SUIT_DataObject* object( const QModelIndex& = QModelIndex() ) const;
135 QModelIndex index( const SUIT_DataObject*, int = 0 ) const;
137 bool autoDeleteTree() const;
138 void setAutoDeleteTree( const bool );
140 bool autoUpdate() const;
141 void setAutoUpdate( const bool );
143 virtual bool customSorting( const int ) const;
144 virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const;
146 QAbstractItemDelegate* delegate() const;
149 virtual void updateTree( const QModelIndex& );
150 virtual void updateTree( SUIT_DataObject* = 0 );
158 TreeItem* rootItem() const;
159 TreeItem* treeItem( const QModelIndex& ) const;
160 TreeItem* treeItem( const SUIT_DataObject* ) const;
161 SUIT_DataObject* object( const TreeItem* ) const;
163 TreeItem* createItem( SUIT_DataObject*, TreeItem* = 0, TreeItem* = 0 );
164 void updateItem( TreeItem* );
165 void removeItem( TreeItem* );
168 void onInserted( SUIT_DataObject*, SUIT_DataObject* );
169 void onRemoved( SUIT_DataObject*, SUIT_DataObject* );
172 typedef QMap<SUIT_DataObject*, TreeItem*> ItemMap;
178 Qtx::Appropriate myAppropriate;
182 SUIT_DataObject* myRoot;
183 TreeItem* myRootItem;
185 bool myAutoDeleteTree;
187 QVector<ColumnInfo> myColumns;
189 friend class SUIT_TreeModel::TreeSync;
192 class SUIT_EXPORT SUIT_ProxyModel : public QSortFilterProxyModel, public SUIT_AbstractModel
197 SUIT_ProxyModel( QObject* = 0 );
198 SUIT_ProxyModel( SUIT_DataObject*, QObject* = 0 );
199 SUIT_ProxyModel( SUIT_AbstractModel*, QObject* = 0 );
202 SUIT_DataObject* root() const;
203 void setRoot( SUIT_DataObject* );
205 SUIT_DataObject* object( const QModelIndex& = QModelIndex() ) const;
206 QModelIndex index( const SUIT_DataObject*, int = 0 ) const;
208 bool autoDeleteTree() const;
209 void setAutoDeleteTree( const bool );
211 bool autoUpdate() const;
212 void setAutoUpdate( const bool );
214 bool isSortingEnabled() const;
215 bool customSorting( const int ) const;
217 virtual bool lessThan( const QModelIndex&, const QModelIndex& ) const;
218 virtual void registerColumn( const int group_id, const QString& name, const int custom_id );
219 virtual void unregisterColumn( const int group_id, const QString& name );
220 virtual void setColumnIcon( const QString& name, const QPixmap& icon );
221 virtual QPixmap columnIcon( const QString& name ) const;
222 virtual void setAppropriate( const QString& name, const Qtx::Appropriate appr );
223 virtual Qtx::Appropriate appropriate( const QString& name ) const;
225 QAbstractItemDelegate* delegate() const;
228 virtual void updateTree( const QModelIndex& );
229 virtual void updateTree( SUIT_DataObject* = 0 );
230 void setSortingEnabled( bool );
236 SUIT_AbstractModel* treeModel() const;
239 bool mySortingEnabled;
242 class SUIT_EXPORT SUIT_ItemDelegate : public QItemDelegate
247 SUIT_ItemDelegate( QObject* = 0 );
249 virtual void paint( QPainter*, const QStyleOptionViewItem&,
250 const QModelIndex& ) const;
254 #pragma warning( default:4251 )
257 #endif // SUIT_TREEMODEL_H