src: Mark symbols to be exported where needed
[quassel.git] / src / uisupport / flatproxymodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #pragma once
22
23 #include "uisupport-export.h"
24
25 #include <QAbstractProxyModel>
26
27 class UISUPPORT_EXPORT FlatProxyModel : public QAbstractProxyModel
28 {
29     Q_OBJECT
30
31 public:
32     FlatProxyModel(QObject *parent = 0);
33
34     virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
35     virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
36
37     virtual QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const;
38     virtual QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const;
39
40     virtual void setSourceModel(QAbstractItemModel *sourceModel);
41
42     virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
43     virtual QModelIndex parent(const QModelIndex &index) const;
44
45     virtual int rowCount(const QModelIndex &index) const;
46     virtual int columnCount(const QModelIndex &index) const;
47
48 public slots:
49     void linkTest() const;
50     void completenessTest() const;
51
52 private slots:
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);
57
58     void on_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
59 //   void on_headerDataChanged(Qt::Orientation orientation, int first, int last);
60
61     void on_layoutAboutToBeChanged();
62     void on_layoutChanged();
63
64     inline void on_modelAboutToBeReset() { beginResetModel(); endResetModel(); }
65     // void on_modelReset();
66
67     void on_rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
68     void on_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
69     void on_rowsInserted(const QModelIndex &parent, int start, int end);
70     void on_rowsRemoved(const QModelIndex &parent, int start, int end);
71
72 private:
73     QList<int> _childCount;
74
75     class SourceItem;
76     SourceItem *_rootSourceItem;
77
78     void insertSubTree(const QModelIndex &source_idx, bool emitInsert = true);
79     SourceItem *insertSubTreeHelper(SourceItem *parentItem, SourceItem *lastItem_, const QModelIndex &source_idx);
80
81     void removeSubTree(const QModelIndex &source_idx, bool emitRemove = true);
82
83     SourceItem *sourceToInternal(const QModelIndex &sourceIndex) const;
84
85     void checkChildCount(const QModelIndex &index, const SourceItem *item, int &pos) const;
86
87     class _RangeRect
88     {
89 public:
90         int left, right, top, bottom;
91         SourceItem *topItem, *bottomItem;
92         bool operator<(const _RangeRect &other) const;
93     };
94 };
95
96
97 class FlatProxyModel::SourceItem
98 {
99 public:
100     SourceItem(int row = 0, SourceItem *parent = 0);
101     ~SourceItem();
102
103     inline SourceItem *parent() const { return _parent; }
104     inline SourceItem *child(int i) const { return _childs[i]; }
105     inline int childCount() const { return _childs.count(); }
106
107     inline int pos() const { return _pos; }
108     inline SourceItem *next() const { return _next; }
109
110     int sourceRow() const;
111     SourceItem *findChild(int proxyPos) const;
112
113 private:
114     inline void removeChild(SourceItem *item) { _childs.removeAt(_childs.indexOf(item)); }
115     inline void setPos(int i) { _pos = i; }
116     inline void setNext(SourceItem *next) { _next = next; }
117
118     SourceItem *_parent;
119     QList<SourceItem *> _childs;
120     int _pos;
121     SourceItem *_next;
122
123     friend class FlatProxyModel;
124 };