-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsprovidersublayermodel.h
235 lines (192 loc) · 6.55 KB
/
qgsprovidersublayermodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/***************************************************************************
qgsprovidersublayermodel.h
----------------------
begin : June 2021
copyright : (C) 2021 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSPROVIDERSUBLAYERMODEL_H
#define QGSPROVIDERSUBLAYERMODEL_H
#include "qgstaskmanager.h"
#include <QAbstractItemModel>
#include <QSortFilterProxyModel>
class QgsProviderSublayerDetails;
/**
* \ingroup core
*
* \brief A model for representing the sublayers present in a URI.
*
* QgsProviderSublayerModel is designed to present a tree view of the sublayers
* available for a URI, including any vector, raster or mesh sublayers present.
*
* Additionally, QgsProviderSublayerModel can include some non-sublayer items,
* e.g. in order to represent other content available for a URI, such as
* embedded project items. The non-sublayer items can be added by calling
* addNonLayerItem().
*
* \since QGIS 3.22
*/
class CORE_EXPORT QgsProviderSublayerModel: public QAbstractItemModel
{
Q_OBJECT
public:
//! Custom model roles
enum class Role : int
{
ProviderKey = Qt::UserRole + 1, //!< Provider key
LayerType, //!< Layer type
Uri, //!< Layer URI
Name, //!< Layer name
Description, //!< Layer description
Path, //!< Layer path
FeatureCount, //!< Feature count (for vector sublayers)
WkbType, //!< WKB geometry type (for vector sublayers)
GeometryColumnName, //!< Geometry column name (for vector sublayers)
LayerNumber, //!< Layer number
IsNonLayerItem, //!< TRUE if item is a non-sublayer item (e.g. an embedded project)
NonLayerItemType, //!< Item type (for non-sublayer items)
};
//! Model columns
enum class Column : int
{
Name = 0, //!< Layer name
Description = 1, //!< Layer description
};
/**
* \ingroup core
*
* \brief Contains details for a non-sublayer item to include in a QgsProviderSublayerModel.
* \since QGIS 3.22
*/
class CORE_EXPORT NonLayerItem
{
public:
/**
* Returns the item's type.
* \see setType()
*/
QString type() const;
/**
* Sets the item's \a type.
* \see type()
*/
void setType( const QString &type );
/**
* Returns the item's name.
* \see setName()
*/
QString name() const;
/**
* Sets the item's \a name.
* \see setName()
*/
void setName( const QString &name );
/**
* Returns the item's description.
* \see setDescription()
*/
QString description() const;
/**
* Sets the item's \a description.
* \see setDescription()
*/
void setDescription( const QString &description );
/**
* Returns the item's URI.
* \see setUri()
*/
QString uri() const;
/**
* Set the item's \a uri.
* \see setUri()
*/
void setUri( const QString &uri );
/**
* Returns the item's icon.
* \see setIcon()
*/
QIcon icon() const;
/**
* Sets the item's \a icon.
* \see setIcon()
*/
void setIcon( const QIcon &icon );
private:
QString mType;
QString mName;
QString mDescription;
QString mUri;
QIcon mIcon;
};
/**
* Constructor for QgsProviderSublayerModel, with the specified \a parent object.
*/
QgsProviderSublayerModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
/**
* Sets the sublayer \a details to show in the model.
*
* \see sublayerDetails()
*/
void setSublayerDetails( const QList< QgsProviderSublayerDetails > &details );
/**
* Returns the sublayer details shown in the model.
*
* \see setSublayerDetails()
*/
QList< QgsProviderSublayerDetails > sublayerDetails() const;
/**
* Adds a non-layer item (e.g. an embedded QGIS project item) to the model.
*/
void addNonLayerItem( const QgsProviderSublayerModel::NonLayerItem &item );
QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
QModelIndex parent( const QModelIndex &index ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
int rowCount( const QModelIndex &parent ) const override;
QVariant data( const QModelIndex &index, int role ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
private:
QList<QgsProviderSublayerDetails> mSublayers;
QList<NonLayerItem> mNonLayerItems;
};
/**
* \ingroup core
*
* \brief A QSortFilterProxyModel for filtering and sorting a QgsProviderSublayerModel.
*
* \since QGIS 3.22
*/
class CORE_EXPORT QgsProviderSublayerProxyModel: public QSortFilterProxyModel
{
Q_OBJECT
public:
/**
* Constructor for QgsProviderSublayerProxyModel, with the specified \a parent object.
*/
QgsProviderSublayerProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
/**
* Returns the filter string used for filtering items in the model.
*
* \see setFilterString()
*/
QString filterString() const;
/**
* Sets the \a filter string used for filtering items in the model.
*
* \see filterString()
*/
void setFilterString( const QString &filter );
protected:
bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
bool lessThan( const QModelIndex &source_left, const QModelIndex &source_right ) const override;
private:
QString mFilterString;
};
#endif // QGSPROVIDERSUBLAYERMODEL_H