QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
113
117 QgsCoordinateReferenceSystemModelGroupNode( const QString &name, const QIcon &icon, const QString &id );
118
122 QString id() const { return mId; }
123
127 QString name() const { return mName; }
128
132 QIcon icon() const { return mIcon; }
133
134 NodeType nodeType() const override { return NodeGroup; }
135
136 private:
137 QString mId;
138 QString mName;
139 QIcon mIcon;
140};
141
148class GUI_EXPORT QgsCoordinateReferenceSystemModelCrsNode : public QgsCoordinateReferenceSystemModelNode
149{
150 public:
151
156 QgsCoordinateReferenceSystemModelCrsNode( const QgsCrsDbRecord &record );
157
158 NodeType nodeType() const override { return NodeCrs; }
159
163 const QgsCrsDbRecord &record() const { return mRecord; }
164
172 void setWkt( const QString &wkt ) { mWkt = wkt; }
173
181 QString wkt() const { return mWkt; }
182
190 void setProj( const QString &proj ) { mProj = proj; }
191
199 QString proj() const { return mProj; }
200
207 void setGroup( const QString &group ) { mGroup = group; }
208
215 QString group() const { return mGroup; }
216
223 void setProjection( const QString &projection ) { mProjection = projection; }
224
231 QString projection() const { return mProjection; }
232
233 private:
234 const QgsCrsDbRecord mRecord;
235 QString mWkt;
236 QString mProj;
237 QString mGroup;
238 QString mProjection;
239};
240
241#endif
243
250class GUI_EXPORT QgsCoordinateReferenceSystemModel : public QAbstractItemModel
251{
252 Q_OBJECT
253
254 public:
255 // *INDENT-OFF*
256
264 {
265 NodeType SIP_MONKEYPATCH_COMPAT_NAME( RoleNodeType ) = Qt::UserRole,
266 Name SIP_MONKEYPATCH_COMPAT_NAME( RoleName ) = Qt::UserRole + 1,
267 AuthId SIP_MONKEYPATCH_COMPAT_NAME( RoleAuthId ) = Qt::UserRole + 2,
268 Deprecated SIP_MONKEYPATCH_COMPAT_NAME( RoleDeprecated ) = Qt::UserRole + 3,
269 Type SIP_MONKEYPATCH_COMPAT_NAME( RoleType ) = Qt::UserRole + 4,
270 GroupId SIP_MONKEYPATCH_COMPAT_NAME( RoleGroupId ) = Qt::UserRole + 5,
271 Wkt SIP_MONKEYPATCH_COMPAT_NAME( RoleWkt ) = Qt::UserRole + 6,
272 Proj SIP_MONKEYPATCH_COMPAT_NAME( RoleProj ) = Qt::UserRole + 7,
273 Group = Qt::UserRole + 8,
274 Projection = Qt::UserRole + 9,
275 };
276 Q_ENUM( CustomRole )
277 // *INDENT-ON*
278
279
282 QgsCoordinateReferenceSystemModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
283
284 Qt::ItemFlags flags( const QModelIndex &index ) const override;
285 QVariant data( const QModelIndex &index, int role ) const override;
286 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
287 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
288 int columnCount( const QModelIndex & = QModelIndex() ) const override;
289 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
290 QModelIndex parent( const QModelIndex &index ) const override;
291
298 QModelIndex addCustomCrs( const QgsCoordinateReferenceSystem &crs );
299
305 QModelIndex authIdToIndex( const QString &authId ) const;
306
307 private slots:
308
309 void rebuild();
310 void userCrsAdded( const QString &id );
311 void userCrsRemoved( long id );
312 void userCrsChanged( const QString &id );
313
314 private:
315 QgsCoordinateReferenceSystemModelCrsNode *addRecord( const QgsCrsDbRecord &record );
316
317 QgsCoordinateReferenceSystemModelNode *index2node( const QModelIndex &index ) const;
318 QModelIndex node2index( QgsCoordinateReferenceSystemModelNode *node ) const;
319 QModelIndex indexOfParentTreeNode( QgsCoordinateReferenceSystemModelNode *parentNode ) const;
320
321
322 std::unique_ptr<QgsCoordinateReferenceSystemModelGroupNode> mRootNode;
323
324 QList<QgsCrsDbRecord> mCrsDbRecords;
325};
326
327
334class GUI_EXPORT QgsCoordinateReferenceSystemProxyModel : public QSortFilterProxyModel
335{
336 Q_OBJECT
337
338 public:
340 enum Filter SIP_ENUM_BASETYPE( IntFlag )
341 {
343 FilterVertical = 1 << 2,
344 FilterCompound = 1 << 3,
345 };
346 Q_DECLARE_FLAGS( Filters, Filter )
347 Q_FLAG( Filters )
348
349
352 explicit QgsCoordinateReferenceSystemProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
353
358
364
370
375 Filters filters() const { return mFilters; }
376
383 void setFilterString( const QString &filter );
384
390 QString filterString() const { return mFilterString; }
391
398 void setFilterAuthIds( const QSet<QString> &filter );
399
405 QSet<QString> filterAuthIds() const { return mFilterAuthIds; }
406
412 void setFilterDeprecated( bool filter );
413
419 bool filterDeprecated() const { return mFilterDeprecated; }
420
421 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
422 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
423
424 private:
425 QgsCoordinateReferenceSystemModel *mModel = nullptr;
426 QString mFilterString;
427 QSet<QString> mFilterAuthIds;
428 bool mFilterDeprecated = false;
429 Filters mFilters = Filters();
430};
431
433
434
435#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)