Marble

kdescendantsproxymodel.h
1/*
2 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef MARBLE_KDESCENDANTSPROXYMODEL_H
8#define MARBLE_KDESCENDANTSPROXYMODEL_H
9
10#include <QAbstractProxyModel>
11
12#include "marble_export.h"
13
14// namespace added to avoid symbol clashes with KF6::ItemModels
15namespace Marble
16{
17
18class KDescendantsProxyModelPrivate;
19
20/**
21@brief Proxy Model for restructuring a Tree into a list.
22
23A KDescendantsProxyModel may be used to alter how the items in the tree are presented.
24
25Given a model which is represented as a tree:
26
27The KDescendantsProxyModel restructures the sourceModel to represent it as a flat list.
28
29@code
30// ... Create an entityTreeModel
31KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this);
32descProxy->setSourceModel(entityTree);
33view->setModel(descProxy);
34@endcode
35
36KDescendantEntitiesProxyModel can also display the ancestors of the index in the source model as part of its display.
37
38@code
39// ... Create an entityTreeModel
40KDescendantsProxyModel *descProxy = new KDescendantsProxyModel(this);
41descProxy->setSourceModel(entityTree);
42
43// #### This is new
44descProxy->setDisplayAncestorData(true);
45descProxy->setDisplayAncestorSeparator(QString(" / "));
46
47view->setModel(descProxy);
48
49@endcode
50
51@since 4.6
52@author Stephen Kelly <steveire@gmail.com>
53*/
54class MARBLE_EXPORT KDescendantsProxyModel : public QAbstractProxyModel
55{
56 Q_OBJECT
57
58public:
59 /**
60 * Creates a new descendant entities proxy model.
61 *
62 * @param parent The parent object.
63 */
64 explicit KDescendantsProxyModel(QObject *parent = nullptr);
65
66 /**
67 * Destroys the descendant entities proxy model.
68 */
69 ~KDescendantsProxyModel() override;
70
71 /**
72 * Sets the source @p model of the proxy.
73 */
74 void setSourceModel(QAbstractItemModel *model) Q_DECL_OVERRIDE;
75
76#if 0
77 /**
78 * @deprecated
79 *
80 * This method does nothing.
81 */
82 void setRootIndex(const QModelIndex &index);
83#endif
84
85 /**
86 * Set whether to show ancestor data in the model. If @p display is true, then
87 * a source model which is displayed as
88 *
89 * @code
90 * -> "Item 0-0" (this is row-depth)
91 * -> -> "Item 0-1"
92 * -> -> "Item 1-1"
93 * -> -> -> "Item 0-2"
94 * -> -> -> "Item 1-2"
95 * -> "Item 1-0"
96 * @endcode
97 *
98 * will be displayed as
99 *
100 * @code
101 * -> *Item 0-0"
102 * -> "Item 0-0 / Item 0-1"
103 * -> "Item 0-0 / Item 1-1"
104 * -> "Item 0-0 / Item 1-1 / Item 0-2"
105 * -> "Item 0-0 / Item 1-1 / Item 1-2"
106 * -> "Item 1-0"
107 * @endcode
108 *
109 * If @p display is false, the proxy will show
110 *
111 * @code
112 * -> *Item 0-0"
113 * -> "Item 0-1"
114 * -> "Item 1-1"
115 * -> "Item 0-2"
116 * -> "Item 1-2"
117 * -> "Item 1-0"
118 * @endcode
119 *
120 * Default is false.
121 */
122 void setDisplayAncestorData(bool display);
123
124 /**
125 * Whether ancestor data will be displayed.
126 */
127 bool displayAncestorData() const;
128
129 /**
130 * Sets the ancestor @p separator used between data of ancestors.
131 */
132 void setAncestorSeparator(const QString &separator);
133
134 /**
135 * Separator used between data of ancestors.
136 */
137 QString ancestorSeparator() const;
138
139 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const Q_DECL_OVERRIDE;
140 QModelIndex mapToSource(const QModelIndex &proxyIndex) const Q_DECL_OVERRIDE;
141
142 Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE;
143 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
144 int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
145 QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE;
146
147 QMimeData *mimeData(const QModelIndexList &indexes) const Q_DECL_OVERRIDE;
148 QStringList mimeTypes() const Q_DECL_OVERRIDE;
149
150 bool hasChildren(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
151 QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
152 QModelIndex parent(const QModelIndex &) const Q_DECL_OVERRIDE;
153 int columnCount(const QModelIndex &index = QModelIndex()) const Q_DECL_OVERRIDE;
154
155 Qt::DropActions supportedDropActions() const Q_DECL_OVERRIDE;
156
157 /**
158 Reimplemented to match all descendants.
159 */
160 QModelIndexList match(const QModelIndex &start,
161 int role,
162 const QVariant &value,
163 int hits = 1,
164 Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const Q_DECL_OVERRIDE;
165
166private:
167 Q_DECLARE_PRIVATE(KDescendantsProxyModel)
168 //@cond PRIVATE
169 KDescendantsProxyModelPrivate *const d_ptr;
170
171 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeInserted(const QModelIndex &, int, int))
172 Q_PRIVATE_SLOT(d_func(), void sourceRowsInserted(const QModelIndex &, int, int))
173 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeRemoved(const QModelIndex &, int, int))
174 Q_PRIVATE_SLOT(d_func(), void sourceRowsRemoved(const QModelIndex &, int, int))
175 Q_PRIVATE_SLOT(d_func(), void sourceRowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int))
176 Q_PRIVATE_SLOT(d_func(), void sourceRowsMoved(const QModelIndex &, int, int, const QModelIndex &, int))
177 Q_PRIVATE_SLOT(d_func(), void sourceModelAboutToBeReset())
178 Q_PRIVATE_SLOT(d_func(), void sourceModelReset())
179 Q_PRIVATE_SLOT(d_func(), void sourceLayoutAboutToBeChanged())
180 Q_PRIVATE_SLOT(d_func(), void sourceLayoutChanged())
181 Q_PRIVATE_SLOT(d_func(), void sourceDataChanged(const QModelIndex &, const QModelIndex &))
182 Q_PRIVATE_SLOT(d_func(), void sourceModelDestroyed())
183
184 Q_PRIVATE_SLOT(d_func(), void processPendingParents())
185
186 // Make these private, they shouldn't be called by applications
187 // virtual bool insertRows(int , int, const QModelIndex & = QModelIndex());
188 // virtual bool insertColumns(int, int, const QModelIndex & = QModelIndex());
189 // virtual bool removeRows(int, int, const QModelIndex & = QModelIndex());
190 // virtual bool removeColumns(int, int, const QModelIndex & = QModelIndex());
191
192 //@endcond
193};
194
195}
196
197#endif
Proxy Model for restructuring a Tree into a list.
Q_SCRIPTABLE Q_NOREPLY void start()
Binds a QML item to a specific geodetic location in screen coordinates.
typedef DropActions
DisplayRole
typedef ItemFlags
typedef MatchFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.