tkdescendantsproxymodel.h - sailfish-safe - Sailfish frontend for safe(1)
(HTM) git clone git://git.z3bra.org/sailfish-safe.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
tkdescendantsproxymodel.h (6983B)
---
1 /*
2 Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18 */
19
20 #ifndef KDESCENDANTSPROXYMODEL_P_H
21 #define KDESCENDANTSPROXYMODEL_P_H
22
23 #include <QAbstractProxyModel>
24
25 class KDescendantsProxyModelPrivate;
26
27 /**
28 @class KDescendantsProxyModel kdescendantsproxymodel.h KDescendantsProxyModel
29
30 @brief Proxy Model for restructuring a Tree into a list.
31
32 A KDescendantsProxyModel may be used to alter how the items in the tree are presented.
33
34 Given a model which is represented as a tree:
35
36 \image html entitytreemodel.png "A plain EntityTreeModel in a view"
37
38 The KDescendantsProxyModel restructures the sourceModel to represent it as a flat list.
39
40 @code
41 // ... Create an entityTreeModel
42 KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this);
43 descProxy->setSourceModel(entityTree);
44 view->setModel(descProxy);
45 @endcode
46
47 \image html descendantentitiesproxymodel.png "A KDescendantsProxyModel."
48
49 KDescendantEntitiesProxyModel can also display the ancestors of the index in the source model as part of its display.
50
51 @code
52 // ... Create an entityTreeModel
53 KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this);
54 descProxy->setSourceModel(entityTree);
55
56 // #### This is new
57 descProxy->setDisplayAncestorData(true);
58 descProxy->setAncestorSeparator(QString(" / "));
59
60 view->setModel(descProxy);
61
62 @endcode
63
64 \image html descendantentitiesproxymodel-withansecnames.png "A KDescendantsProxyModel with ancestor names."
65
66 @since 4.6
67 @author Stephen Kelly <steveire@gmail.com>
68 */
69 class KDescendantsProxyModel : public QAbstractProxyModel
70 {
71 Q_OBJECT
72
73 public:
74
75 /**
76 * Creates a new descendant entities proxy model.
77 *
78 * @param parent The parent object.
79 */
80 explicit KDescendantsProxyModel(QObject *parent = nullptr);
81
82 /**
83 * Destroys the descendant entities proxy model.
84 */
85 ~KDescendantsProxyModel() override;
86
87 /**
88 * Sets the source @p model of the proxy.
89 */
90 void setSourceModel(QAbstractItemModel *model) override;
91
92 /**
93 * @deprecated
94 *
95 * This method does nothing.
96 */
97 void setRootIndex(const QModelIndex &index);
98
99 /**
100 * Set whether to show ancestor data in the model. If @p display is true, then
101 * a source model which is displayed as
102 *
103 * @code
104 * -> "Item 0-0" (this is row-depth)
105 * -> -> "Item 0-1"
106 * -> -> "Item 1-1"
107 * -> -> -> "Item 0-2"
108 * -> -> -> "Item 1-2"
109 * -> "Item 1-0"
110 * @endcode
111 *
112 * will be displayed as
113 *
114 * @code
115 * -> *Item 0-0"
116 * -> "Item 0-0 / Item 0-1"
117 * -> "Item 0-0 / Item 1-1"
118 * -> "Item 0-0 / Item 1-1 / Item 0-2"
119 * -> "Item 0-0 / Item 1-1 / Item 1-2"
120 * -> "Item 1-0"
121 * @endcode
122 *
123 * If @p display is false, the proxy will show
124 *
125 * @code
126 * -> *Item 0-0"
127 * -> "Item 0-1"
128 * -> "Item 1-1"
129 * -> "Item 0-2"
130 * -> "Item 1-2"
131 * -> "Item 1-0"
132 * @endcode
133 *
134 * Default is false.
135 */
136 void setDisplayAncestorData(bool display);
137
138 /**
139 * Whether ancestor data will be displayed.
140 */
141 bool displayAncestorData() const;
142
143 /**
144 * Sets the ancestor @p separator used between data of ancestors.
145 */
146 void setAncestorSeparator(const QString &separator);
147
148 /**
149 * Separator used between data of ancestors.
150 */
151 QString ancestorSeparator() const;
152
153 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
154 QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
155
156 Qt::ItemFlags flags(const QModelIndex &index) const override;
157 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
158 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
159 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
160
161 QMimeData *mimeData(const QModelIndexList &indexes) const override;
162 QStringList mimeTypes() const override;
163
164 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
165 QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const override;
166 QModelIndex parent(const QModelIndex &) const override;
167 int columnCount(const QModelIndex &index = QModelIndex()) const override;
168
169 Qt::DropActions supportedDropActions() const override;
170
171 /**
172 Reimplemented to match all descendants.
173 */
174 virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value,
175 int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override;
176
177 private:
178 Q_DECLARE_PRIVATE(KDescendantsProxyModel)
179 //@cond PRIVATE
180 KDescendantsProxyModelPrivate *d_ptr;
181
182 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeInserted(const QModelIndex &, int, int))
183 Q_PRIVATE_SLOT(d_func(), void sourceRowsInserted(const QModelIndex &, int, int))
184 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))
185 Q_PRIVATE_SLOT(d_func(), void sourceRowsRemoved(const QModelIndex &, int, int))
186 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))
187 Q_PRIVATE_SLOT(d_func(), void sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))
188 Q_PRIVATE_SLOT(d_func(), void sourceModelAboutToBeReset())
189 Q_PRIVATE_SLOT(d_func(), void sourceModelReset())
190 Q_PRIVATE_SLOT(d_func(), void sourceLayoutAboutToBeChanged())
191 Q_PRIVATE_SLOT(d_func(), void sourceLayoutChanged())
192 Q_PRIVATE_SLOT(d_func(), void sourceDataChanged(const QModelIndex &, const QModelIndex &))
193 Q_PRIVATE_SLOT(d_func(), void sourceModelDestroyed())
194
195 Q_PRIVATE_SLOT(d_func(), void processPendingParents())
196
197 // Make these private, they shouldn't be called by applications
198 // virtual bool insertRows(int , int, const QModelIndex & = QModelIndex());
199 // virtual bool insertColumns(int, int, const QModelIndex & = QModelIndex());
200 // virtual bool removeRows(int, int, const QModelIndex & = QModelIndex());
201 // virtual bool removeColumns(int, int, const QModelIndex & = QModelIndex());
202
203 //@endcond
204 };
205
206 #endif