QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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.h"
21#include "qgis_gui.h"
22#include "qgis_sip.h"
24
25#include <QAbstractItemModel>
26#include <QIcon>
27#include <QSortFilterProxyModel>
28
30class QgsCoordinateReferenceSystemModelGroupNode;
31
33#ifndef SIP_RUN
34
41class GUI_EXPORT QgsCoordinateReferenceSystemModelNode
42{
43 public:
45 enum NodeType
46 {
47 NodeGroup,
48 NodeCrs,
49 };
50
51 virtual ~QgsCoordinateReferenceSystemModelNode();
52
56 virtual NodeType nodeType() const = 0;
57
61 QgsCoordinateReferenceSystemModelNode *parent() { return mParent; }
62
66 QList<QgsCoordinateReferenceSystemModelNode *> children() { return mChildren; }
67
71 QList<QgsCoordinateReferenceSystemModelNode *> children() const { return mChildren; }
72
77 QgsCoordinateReferenceSystemModelNode *takeChild( QgsCoordinateReferenceSystemModelNode *node );
78
85 QgsCoordinateReferenceSystemModelNode *addChildNode( std::unique_ptr< QgsCoordinateReferenceSystemModelNode > node );
86
90 void deleteChildren();
91
97 QgsCoordinateReferenceSystemModelGroupNode *getChildGroupNode( const QString &id );
98
99 private:
100 QgsCoordinateReferenceSystemModelNode *mParent = nullptr;
101 QList<QgsCoordinateReferenceSystemModelNode *> mChildren;
102};
103
110class GUI_EXPORT QgsCoordinateReferenceSystemModelGroupNode : public QgsCoordinateReferenceSystemModelNode
111{
112 public:
116 QgsCoordinateReferenceSystemModelGroupNode( const QString &name, const QIcon &icon, const QString &id );
117
121 QString id() const { return mId; }
122
126 QString name() const { return mName; }
127
131 QIcon icon() const { return mIcon; }
132
133 NodeType nodeType() const override { return NodeGroup; }
134
135 private:
136 QString mId;
137 QString mName;
138 QIcon mIcon;
139};
140
147class GUI_EXPORT QgsCoordinateReferenceSystemModelCrsNode : public QgsCoordinateReferenceSystemModelNode
148{
149 public:
154 QgsCoordinateReferenceSystemModelCrsNode( const QgsCrsDbRecord &record );
155
156 NodeType nodeType() const override { return NodeCrs; }
157
161 const QgsCrsDbRecord &record() const { return mRecord; }
162
170 void setWkt( const QString &wkt ) { mWkt = wkt; }
171
179 QString wkt() const { return mWkt; }
180
188 void setProj( const QString &proj ) { mProj = proj; }
189
197 QString proj() const { return mProj; }
198
205 void setGroup( const QString &group ) { mGroup = group; }
206
213 QString group() const { return mGroup; }
214
221 void setProjection( const QString &projection ) { mProjection = projection; }
222
229 QString projection() const { return mProjection; }
230
231 private:
232 const QgsCrsDbRecord mRecord;
233 QString mWkt;
234 QString mProj;
235 QString mGroup;
236 QString mProjection;
237};
238
239#endif
241
248class GUI_EXPORT QgsCoordinateReferenceSystemModel : public QAbstractItemModel
249{
250 Q_OBJECT
251
252 public:
253 // *INDENT-OFF*
254
262 {
263 NodeType SIP_MONKEYPATCH_COMPAT_NAME( RoleNodeType ) = Qt::UserRole,
264 Name SIP_MONKEYPATCH_COMPAT_NAME( RoleName ) = Qt::UserRole + 1,
265 AuthId SIP_MONKEYPATCH_COMPAT_NAME( RoleAuthId ) = Qt::UserRole + 2,
266 Deprecated SIP_MONKEYPATCH_COMPAT_NAME( RoleDeprecated ) = Qt::UserRole + 3,
267 Type SIP_MONKEYPATCH_COMPAT_NAME( RoleType ) = Qt::UserRole + 4,
268 GroupId SIP_MONKEYPATCH_COMPAT_NAME( RoleGroupId ) = Qt::UserRole + 5,
269 Wkt SIP_MONKEYPATCH_COMPAT_NAME( RoleWkt ) = Qt::UserRole + 6,
270 Proj SIP_MONKEYPATCH_COMPAT_NAME( RoleProj ) = Qt::UserRole + 7,
271 Group = Qt::UserRole + 8,
272 Projection = Qt::UserRole + 9,
273 };
274 Q_ENUM( CustomRole )
275 // *INDENT-ON*
276
277
280 QgsCoordinateReferenceSystemModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
281
282 Qt::ItemFlags flags( const QModelIndex &index ) const override;
283 QVariant data( const QModelIndex &index, int role ) const override;
284 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
285 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
286 int columnCount( const QModelIndex & = QModelIndex() ) const override;
287 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
288 QModelIndex parent( const QModelIndex &index ) const override;
289
296 QModelIndex addCustomCrs( const QgsCoordinateReferenceSystem &crs );
297
303 QModelIndex authIdToIndex( const QString &authId ) const;
304
305 private slots:
306
307 void rebuild();
308 void userCrsAdded( const QString &id );
309 void userCrsRemoved( long id );
310 void userCrsChanged( const QString &id );
311
312 private:
313 QgsCoordinateReferenceSystemModelCrsNode *addRecord( const QgsCrsDbRecord &record );
314
315 QgsCoordinateReferenceSystemModelNode *index2node( const QModelIndex &index ) const;
316 QModelIndex node2index( QgsCoordinateReferenceSystemModelNode *node ) const;
317 QModelIndex indexOfParentTreeNode( QgsCoordinateReferenceSystemModelNode *parentNode ) const;
318
319
320 std::unique_ptr<QgsCoordinateReferenceSystemModelGroupNode> mRootNode;
321
322 QList<QgsCrsDbRecord> mCrsDbRecords;
323};
324
325
332class GUI_EXPORT QgsCoordinateReferenceSystemProxyModel : public QSortFilterProxyModel
333{
334 Q_OBJECT
335
336 public:
338 enum Filter SIP_ENUM_BASETYPE( IntFlag )
339 {
341 FilterVertical = 1 << 2,
342 FilterCompound = 1 << 3,
343 };
344 Q_DECLARE_FLAGS( Filters, Filter )
345 Q_FLAG( Filters )
346
347
350 explicit QgsCoordinateReferenceSystemProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
351
356
362
368
373 Filters filters() const { return mFilters; }
374
381 void setFilterString( const QString &filter );
382
388 QString filterString() const { return mFilterString; }
389
396 void setFilterAuthIds( const QSet<QString> &filter );
397
403 QSet<QString> filterAuthIds() const { return mFilterAuthIds; }
404
410 void setFilterDeprecated( bool filter );
411
417 bool filterDeprecated() const { return mFilterDeprecated; }
418
419 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
420 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
421
422 private:
423 QgsCoordinateReferenceSystemModel *mModel = nullptr;
424 QString mFilterString;
425 QSet<QString> mFilterAuthIds;
426 bool mFilterDeprecated = false;
427 Filters mFilters = Filters();
428};
429
431
432
433#endif // QGSCOORDINATEREFERENCESYSTEMMODEL_H
A tree model for display of known coordinate reference systems.
QgsCoordinateReferenceSystemModel(QObject *parent=nullptr)
Constructor for QgsCoordinateReferenceSystemModel, with the specified parent object.
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.
QgsCoordinateReferenceSystemProxyModel(QObject *parent=nullptr)
Constructor for QgsCoordinateReferenceSystemProxyModel, with the given parent object.
Filters filters() const
Returns any filters that affect how CRS are filtered.
Filter
Available filter flags for filtering the model.
@ FilterVertical
Include vertical CRS (excludes compound CRS containing a vertical component).
@ FilterHorizontal
Include horizontal CRS (excludes compound CRS containing a horizontal component).
QgsCoordinateReferenceSystemModel * coordinateReferenceSystemModel()
Returns the underlying source model.
QString filterString() const
Returns the current filter string, if set.
void setFilters(QgsCoordinateReferenceSystemProxyModel::Filters filters)
Set filters that affect how CRS are filtered.
Represents a coordinate reference system (CRS).
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:268
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)