QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgscoordinatereferencesystemmodel.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscoordinatereferencesystemmodel.h
3 -------------------
4 begin : July 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSCOORDINATEREFERENCESYSTEMMODEL_H
18#define QGSCOORDINATEREFERENCESYSTEMMODEL_H
19
20#include "qgis_gui.h"
21#include "qgis_sip.h"
22#include "qgis.h"
24
25#include <QAbstractItemModel>
26#include <QSortFilterProxyModel>
27#include <QIcon>
28
30class QgsCoordinateReferenceSystemModelGroupNode;
31
33#ifndef SIP_RUN
34
41class GUI_EXPORT QgsCoordinateReferenceSystemModelNode
42{
43
44 public:
45
47 enum NodeType
48 {
49 NodeGroup,
50 NodeCrs,
51 };
52
53 virtual ~QgsCoordinateReferenceSystemModelNode();
54
58 virtual NodeType nodeType() const = 0;
59
63 QgsCoordinateReferenceSystemModelNode *parent() { return mParent; }
64
68 QList<QgsCoordinateReferenceSystemModelNode *> children() { return mChildren; }
69
73 QList<QgsCoordinateReferenceSystemModelNode *> children() const { return mChildren; }
74
79 QgsCoordinateReferenceSystemModelNode *takeChild( QgsCoordinateReferenceSystemModelNode *node );
80
85 void addChildNode( QgsCoordinateReferenceSystemModelNode *node );
86
90 void deleteChildren();
91
97 QgsCoordinateReferenceSystemModelGroupNode *getChildGroupNode( const QString &id );
98
99 private:
100
101 QgsCoordinateReferenceSystemModelNode *mParent = nullptr;
102 QList<QgsCoordinateReferenceSystemModelNode *> mChildren;
103
104};
105
112class GUI_EXPORT QgsCoordinateReferenceSystemModelGroupNode : public QgsCoordinateReferenceSystemModelNode
113{
114
115 public:
116
120 QgsCoordinateReferenceSystemModelGroupNode( const QString &name, const QIcon &icon, const QString &id );
121
125 QString id() const { return mId; }
126
130 QString name() const { return mName; }
131
135 QIcon icon() const { return mIcon; }
136
137 NodeType nodeType() const override { return NodeGroup; }
138
139 private:
140
141 QString mId;
142 QString mName;
143 QIcon mIcon;
144
145};
146
153class GUI_EXPORT QgsCoordinateReferenceSystemModelCrsNode : public QgsCoordinateReferenceSystemModelNode
154{
155
156 public:
157
162 QgsCoordinateReferenceSystemModelCrsNode( const QgsCrsDbRecord &record );
163
164 NodeType nodeType() const override { return NodeCrs; }
165
169 const QgsCrsDbRecord &record() const { return mRecord; }
170
178 void setWkt( const QString &wkt ) { mWkt = wkt; }
179
187 QString wkt() const { return mWkt; }
188
196 void setProj( const QString &proj ) { mProj = proj; }
197
205 QString proj() const { return mProj; }
206
207 private:
208
209 const QgsCrsDbRecord mRecord;
210 QString mWkt;
211 QString mProj;
212
213};
214
215#endif
217
224class GUI_EXPORT QgsCoordinateReferenceSystemModel : public QAbstractItemModel
225{
226 Q_OBJECT
227
228 public:
229
231 enum Roles
232 {
233 RoleNodeType = Qt::UserRole,
234 RoleName = Qt::UserRole + 1,
235 RoleAuthId = Qt::UserRole + 2,
236 RoleDeprecated = Qt::UserRole + 3,
237 RoleType = Qt::UserRole + 4,
238 RoleGroupId = Qt::UserRole + 5,
239 RoleWkt = Qt::UserRole + 6,
240 RoleProj = Qt::UserRole + 7,
241 };
242
246 QgsCoordinateReferenceSystemModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
247
248 Qt::ItemFlags flags( const QModelIndex &index ) const override;
249 QVariant data( const QModelIndex &index, int role ) const override;
250 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
251 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
252 int columnCount( const QModelIndex & = QModelIndex() ) const override;
253 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
254 QModelIndex parent( const QModelIndex &index ) const override;
255
262 QModelIndex addCustomCrs( const QgsCoordinateReferenceSystem &crs );
263
269 QModelIndex authIdToIndex( const QString &authId ) const;
270
271 private slots:
272
273 void rebuild();
274 void userCrsAdded( const QString &id );
275 void userCrsRemoved( long id );
276 void userCrsChanged( const QString &id );
277
278 private:
279
280 QgsCoordinateReferenceSystemModelCrsNode *addRecord( const QgsCrsDbRecord &record );
281
282 QgsCoordinateReferenceSystemModelNode *index2node( const QModelIndex &index ) const;
283 QModelIndex node2index( QgsCoordinateReferenceSystemModelNode *node ) const;
284 QModelIndex indexOfParentTreeNode( QgsCoordinateReferenceSystemModelNode *parentNode ) const;
285
286
287 std::unique_ptr< QgsCoordinateReferenceSystemModelGroupNode > mRootNode;
288
289 QList< QgsCrsDbRecord > mCrsDbRecords;
290
291};
292
293
300class GUI_EXPORT QgsCoordinateReferenceSystemProxyModel: public QSortFilterProxyModel
301{
302 Q_OBJECT
303
304 public:
305
308 {
309 FilterHorizontal = 1 << 1,
310 FilterVertical = 1 << 2,
311 FilterCompound = 1 << 3,
312 };
313 Q_DECLARE_FLAGS( Filters, Filter )
314 Q_FLAG( Filters )
315
316
319 explicit QgsCoordinateReferenceSystemProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
320
324 QgsCoordinateReferenceSystemModel *coordinateReferenceSystemModel();
325
330 const QgsCoordinateReferenceSystemModel *coordinateReferenceSystemModel() const SIP_SKIP;
331
336 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
337
342 Filters filters() const { return mFilters; }
343
350 void setFilterString( const QString &filter );
351
357 QString filterString() const { return mFilterString; }
358
365 void setFilterAuthIds( const QSet< QString > &filter );
366
372 QSet< QString > filterAuthIds() const { return mFilterAuthIds; }
373
379 void setFilterDeprecated( bool filter );
380
386 bool filterDeprecated() const { return mFilterDeprecated; }
387
388 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
389 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
390
391 private:
392
393 QgsCoordinateReferenceSystemModel *mModel = nullptr;
394 QString mFilterString;
395 QSet< QString > mFilterAuthIds;
396 bool mFilterDeprecated = false;
397 Filters mFilters = Filters();
398};
399
400Q_DECLARE_OPERATORS_FOR_FLAGS( QgsCoordinateReferenceSystemProxyModel::Filters )
401
402
403#endif // QGSCOORDINATEREFERENCESYSTEMMODEL_H
A tree model for display of known coordinate reference systems.
A sort/filter proxy model for coordinate reference systems.
bool filterDeprecated() const
Returns whether deprecated CRS will be filtered from the results.
QSet< QString > filterAuthIds() const
Returns the current filter list of auth ID strings, if set.
Filter
Available filter flags for filtering the model.
QString filterString() const
Returns the current filter string, if set.
This class represents a coordinate reference system (CRS).
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs