1 /***************************************************************************
2 * Copyright (C) 2005-2019 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include "uisupport-export.h"
25 #include <QAbstractProxyModel>
27 class UISUPPORT_EXPORT FlatProxyModel : public QAbstractProxyModel
32 FlatProxyModel(QObject* parent = nullptr);
34 QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override;
35 QModelIndex mapToSource(const QModelIndex& proxyIndex) const override;
37 QItemSelection mapSelectionFromSource(const QItemSelection& sourceSelection) const override;
38 QItemSelection mapSelectionToSource(const QItemSelection& proxySelection) const override;
40 void setSourceModel(QAbstractItemModel* sourceModel) override;
42 QModelIndex index(int row, int column, const QModelIndex& parent) const override;
43 QModelIndex parent(const QModelIndex& index) const override;
45 int rowCount(const QModelIndex& index) const override;
46 int columnCount(const QModelIndex& index) const override;
49 void linkTest() const;
50 void completenessTest() const;
53 void on_columnsAboutToBeInserted(const QModelIndex& parent, int start, int end);
54 void on_columnsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
55 void on_columnsInserted(const QModelIndex& parent, int start, int end);
56 void on_columnsRemoved(const QModelIndex& parent, int start, int end);
58 void on_dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
59 // void on_headerDataChanged(Qt::Orientation orientation, int first, int last);
61 void on_layoutAboutToBeChanged();
62 void on_layoutChanged();
64 inline void on_modelAboutToBeReset()
69 // void on_modelReset();
71 void on_rowsAboutToBeInserted(const QModelIndex& parent, int start, int end);
72 void on_rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
73 void on_rowsInserted(const QModelIndex& parent, int start, int end);
74 void on_rowsRemoved(const QModelIndex& parent, int start, int end);
77 QList<int> _childCount;
80 SourceItem* _rootSourceItem{nullptr};
82 void insertSubTree(const QModelIndex& source_idx, bool emitInsert = true);
83 SourceItem* insertSubTreeHelper(SourceItem* parentItem, SourceItem* lastItem_, const QModelIndex& source_idx);
85 void removeSubTree(const QModelIndex& source_idx, bool emitRemove = true);
87 SourceItem* sourceToInternal(const QModelIndex& sourceIndex) const;
89 void checkChildCount(const QModelIndex& index, const SourceItem* item, int& pos) const;
94 int left, right, top, bottom;
95 SourceItem *topItem, *bottomItem;
96 bool operator<(const _RangeRect& other) const;
100 class FlatProxyModel::SourceItem
103 SourceItem(int row = 0, SourceItem* parent = nullptr);
106 inline SourceItem* parent() const { return _parent; }
107 inline SourceItem* child(int i) const { return _childs[i]; }
108 inline int childCount() const { return _childs.count(); }
110 inline int pos() const { return _pos; }
111 inline SourceItem* next() const { return _next; }
113 int sourceRow() const;
114 SourceItem* findChild(int proxyPos) const;
117 inline void removeChild(SourceItem* item) { _childs.removeAt(_childs.indexOf(item)); }
118 inline void setPos(int i) { _pos = i; }
119 inline void setNext(SourceItem* next) { _next = next; }
122 QList<SourceItem*> _childs;
124 SourceItem* _next{nullptr};
126 friend class FlatProxyModel;