1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef FLATPROXYMODEL_H
22 #define FLATPROXYMODEL_H
24 #include <QAbstractProxyModel>
26 class FlatProxyModel : public QAbstractProxyModel {
30 FlatProxyModel(QObject *parent = 0);
32 virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
33 virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
35 virtual QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const;
36 virtual QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const;
38 virtual void setSourceModel(QAbstractItemModel *sourceModel);
40 virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
41 virtual QModelIndex parent(const QModelIndex &index) const;
43 virtual int rowCount(const QModelIndex &index) const;
44 virtual int columnCount(const QModelIndex &index) const;
47 void linkTest() const;
48 void completenessTest() const;
51 void on_columnsAboutToBeInserted(const QModelIndex &parent, int start, int end);
52 void on_columnsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
53 void on_columnsInserted(const QModelIndex &parent, int start, int end);
54 void on_columnsRemoved(const QModelIndex &parent, int start, int end);
56 void on_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
57 // void on_headerDataChanged(Qt::Orientation orientation, int first, int last);
59 void on_layoutAboutToBeChanged();
60 void on_layoutChanged();
62 inline void on_modelAboutToBeReset() { reset(); }
63 // void on_modelReset();
65 void on_rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
66 void on_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
67 void on_rowsInserted(const QModelIndex &parent, int start, int end);
68 void on_rowsRemoved(const QModelIndex &parent, int start, int end);
71 QList<int> _childCount;
74 SourceItem *_rootSourceItem;
76 void insertSubTree(const QModelIndex &source_idx, bool emitInsert = true);
77 SourceItem *insertSubTreeHelper(SourceItem *parentItem, SourceItem *lastItem_, const QModelIndex &source_idx);
79 void removeSubTree(const QModelIndex &source_idx, bool emitRemove = true);
81 SourceItem *sourceToInternal(const QModelIndex &sourceIndex) const;
83 void checkChildCount(const QModelIndex &index, const SourceItem *item, int &pos) const;
87 int left, right, top, bottom;
88 SourceItem *topItem, *bottomItem;
89 bool operator<(const _RangeRect &other) const;
94 class FlatProxyModel::SourceItem {
96 SourceItem(int row = 0, SourceItem *parent = 0);
99 inline SourceItem *parent() const { return _parent; }
100 inline SourceItem *child(int i) const { return _childs[i]; }
101 inline int childCount() const { return _childs.count(); }
103 inline int pos() const { return _pos; }
104 inline SourceItem *next() const { return _next; }
106 int sourceRow() const;
107 SourceItem *findChild(int proxyPos) const;
110 inline void removeChild(SourceItem *item) { _childs.removeAt(_childs.indexOf(item)); }
111 inline void setPos(int i) { _pos = i; }
112 inline void setNext(SourceItem *next) { _next = next; }
115 QList<SourceItem *> _childs;
119 friend class FlatProxyModel;
123 #endif //FLATPROXYMODEL_H