QAdvanced Item View  0.4
The QAIV (Qt Advanced Item Views) library provides GUI and utility classes extending the capabilities of the Qt item views.
 All Classes Functions Variables Enumerations Enumerator Properties Groups Pages
qgroupingproxymodel.h
1 /******************************************************************************
2 ** This file is part of qadvanceditemviews.
3 **
4 ** Copyright (c) 2011-2012 Martin Hoppe martin@2x2hoppe.de
5 **
6 ** qadvanceditemviews is free software: you can redistribute it
7 ** and/or modify it under the terms of the GNU Lesser General
8 ** Public License as published by the Free Software Foundation,
9 ** either version 3 of the License, or (at your option) any
10 ** later version.
11 **
12 ** qadvanceditemviews is distributed in the hope that it will be
13 ** useful, but WITHOUT ANY WARRANTY; without even the implied
14 ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 ** See the GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU Lesser General Public
18 ** License along with qadvanceditemviews.
19 ** If not, see <http://www.gnu.org/licenses/>.
20 ******************************************************************************/
21 #ifndef QGROUPINGPROXYMODEL_H
22 #define QGROUPINGPROXYMODEL_H
23 
24 #include <QAbstractProxyModel>
25 #include <qaivlib_global.h>
26 
27 class QGroupingProxyModelGroup;
28 class QGroupingProxyModelPrivate;
29 
31 
96 class QAIVLIBSHARED_EXPORT QGroupingProxyModel : public QAbstractItemModel
97 {
98  Q_OBJECT
100  Q_PROPERTY(bool groupsSpanned READ groupsSpanned WRITE setGroupsSpanned)
102 
108  Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn)
109 public:
113  explicit QGroupingProxyModel(QObject *parent = 0);
122  void addGroup(const QString & text, const QVariant & value = QVariant());
127  void addGroup(const QIcon & icon, const QString & text, const QVariant & value = QVariant());
132  int columnCount(const QModelIndex & parent = QModelIndex()) const;
136  QVariant data(const QModelIndex & proxyIndex, int role) const;
140  Qt::ItemFlags flags(const QModelIndex & index) const;
141  bool groupsSpanned() const;
145  QVariant headerData(int section, Qt::Orientation orientation, int role) const;
149  QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
150 
151  int findText(const QString & text) const;
156  QModelIndex mapFromSource(const QModelIndex & sourceIndex) const;
161  QModelIndex mapToSource(const QModelIndex & proxyIndex) const;
166  int modelColumn() const;
170  QModelIndex parent(const QModelIndex & child) const;
174  bool removeGroup(int index);
185  bool restoreGroups(const QByteArray & data);
190  int rowCount(const QModelIndex & parent = QModelIndex()) const;
200  QByteArray saveGroups() const;
204  bool setData(const QModelIndex & index, const QVariant &value, int role);
205 
206  void setGroupSectionHeader(const QString & header);
207  void setGroupsSpanned(bool on);
212  void setModelColumn(int column);
216  virtual void setSourceModel( QAbstractItemModel* sourceModel );
217  void setUngroupedItemTitle(const QString & title);
218  void setUngroupedItemTitle(const QString & title, const QIcon & icon);
219  virtual QSize span(const QModelIndex & index) const;
220 private slots:
221  void dataChangedHandler(const QModelIndex & topLeft, const QModelIndex & bottomRight);
222  void sourceModelResetHandler();
223  void rowsAboutToBeInsertedHandler( const QModelIndex & parent, int start, int end );
224  void rowsInsertedHandler(const QModelIndex & parent, int first, int last);
225 private:
226  void buildGroups();
227 
228  int groupAt(int sourceModelRow);
229  void moveRows(int row, int count);
230  void removeSourceModelRow(int sourceModelRow);
231 
232  QString m_groupSectionHeader;
233  QGroupingProxyModelGroup* m_groupUngroupedItem;
234  QGroupingProxyModelPrivate* d;
235 };
236 
237 #endif // QGROUPINGPROXYMODEL_H
The QGroupingProxyModel class implements a grouping proxy model.
Definition: qgroupingproxymodel.h:96