QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 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
83 void addChildNode( QgsCoordinateReferenceSystemModelNode *node );
84
88 void deleteChildren();
89
95 QgsCoordinateReferenceSystemModelGroupNode *getChildGroupNode( const QString &id );
96
97 private:
98 QgsCoordinateReferenceSystemModelNode *mParent = nullptr;
99 QList<QgsCoordinateReferenceSystemModelNode *> mChildren;
100};
101
108class GUI_EXPORT QgsCoordinateReferenceSystemModelGroupNode : public QgsCoordinateReferenceSystemModelNode
109{
110 public:
114 QgsCoordinateReferenceSystemModelGroupNode( const QString &name, const QIcon &icon, const QString &id );
115
119 QString id() const { return mId; }
120
124 QString name() const { return mName; }
125
129 QIcon icon() const { return mIcon; }
130
131 NodeType nodeType() const override { return NodeGroup; }
132
133 private:
134 QString mId;
135 QString mName;
136 QIcon mIcon;
137};
138
145class GUI_EXPORT QgsCoordinateReferenceSystemModelCrsNode : public QgsCoordinateReferenceSystemModelNode
146{
147 public:
152 QgsCoordinateReferenceSystemModelCrsNode( const QgsCrsDbRecord &record );
153
154 NodeType nodeType() const override { return NodeCrs; }
155
159 const QgsCrsDbRecord &record() const { return mRecord; }
160
168 void setWkt( const QString &wkt ) { mWkt = wkt; }
169
177 QString wkt() const { return mWkt; }
178
186 void setProj( const QString &proj ) { mProj = proj; }
187
195 QString proj() const { return mProj; }
196
203 void setGroup( const QString &group ) { mGroup = group; }
204
211 QString group() const { return mGroup; }
212
219 void setProjection( const QString &projection ) { mProjection = projection; }
220
227 QString projection() const { return mProjection; }
228
229 private:
230 const QgsCrsDbRecord mRecord;
231 QString mWkt;
232 QString mProj;
233 QString mGroup;
234 QString mProjection;
235};
236
237#endif
239
246class GUI_EXPORT QgsCoordinateReferenceSystemModel : public QAbstractItemModel
247{
248 Q_OBJECT
249
250 public:
251 // *INDENT-OFF*
252
260 {
261 NodeType SIP_MONKEYPATCH_COMPAT_NAME( RoleNodeType ) = Qt::UserRole,
262 Name SIP_MONKEYPATCH_COMPAT_NAME( RoleName ) = Qt::UserRole + 1,
263 AuthId SIP_MONKEYPATCH_COMPAT_NAME( RoleAuthId ) = Qt::UserRole + 2,
264 Deprecated SIP_MONKEYPATCH_COMPAT_NAME( RoleDeprecated ) = Qt::UserRole + 3,
265 Type SIP_MONKEYPATCH_COMPAT_NAME( RoleType ) = Qt::UserRole + 4,
266 GroupId SIP_MONKEYPATCH_COMPAT_NAME( RoleGroupId ) = Qt::UserRole + 5,
267 Wkt SIP_MONKEYPATCH_COMPAT_NAME( RoleWkt ) = Qt::UserRole + 6,
268 Proj SIP_MONKEYPATCH_COMPAT_NAME( RoleProj ) = Qt::UserRole + 7,
269 Group = Qt::UserRole + 8,
270 Projection = Qt::UserRole + 9,
271 };
272 Q_ENUM( CustomRole )
273 // *INDENT-ON*
274
275
278 QgsCoordinateReferenceSystemModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
279
280 Qt::ItemFlags flags( const QModelIndex &index ) const override;
281 QVariant data( const QModelIndex &index, int role ) const override;
282 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
283 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
284 int columnCount( const QModelIndex & = QModelIndex() ) const override;
285 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
286 QModelIndex parent( const QModelIndex &index ) const override;
287
294 QModelIndex addCustomCrs( const QgsCoordinateReferenceSystem &crs );
295
301 QModelIndex authIdToIndex( const QString &authId ) const;
302
303 private slots:
304
305 void rebuild();
306 void userCrsAdded( const QString &id );
307 void userCrsRemoved( long id );
308 void userCrsChanged( const QString &id );
309
310 private:
311 QgsCoordinateReferenceSystemModelCrsNode *addRecord( const QgsCrsDbRecord &record );
312
313 QgsCoordinateReferenceSystemModelNode *index2node( const QModelIndex &index ) const;
314 QModelIndex node2index( QgsCoordinateReferenceSystemModelNode *node ) const;
315 QModelIndex indexOfParentTreeNode( QgsCoordinateReferenceSystemModelNode *parentNode ) const;
316
317
318 std::unique_ptr<QgsCoordinateReferenceSystemModelGroupNode> mRootNode;
319
320 QList<QgsCrsDbRecord> mCrsDbRecords;
321};
322
323
330class GUI_EXPORT QgsCoordinateReferenceSystemProxyModel : public QSortFilterProxyModel
331{
332 Q_OBJECT
333
334 public:
336 enum Filter SIP_ENUM_BASETYPE( IntFlag )
337 {
338 FilterHorizontal = 1 << 1,
339 FilterVertical = 1 << 2,
340 FilterCompound = 1 << 3,
341 };
342 Q_DECLARE_FLAGS( Filters, Filter )
343 Q_FLAG( Filters )
344
345
348 explicit QgsCoordinateReferenceSystemProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
349
353 QgsCoordinateReferenceSystemModel *coordinateReferenceSystemModel();
354
359 const QgsCoordinateReferenceSystemModel *coordinateReferenceSystemModel() const SIP_SKIP;
360
365 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
366
371 Filters filters() const { return mFilters; }
372
379 void setFilterString( const QString &filter );
380
386 QString filterString() const { return mFilterString; }
387
394 void setFilterAuthIds( const QSet<QString> &filter );
395
401 QSet<QString> filterAuthIds() const { return mFilterAuthIds; }
402
408 void setFilterDeprecated( bool filter );
409
415 bool filterDeprecated() const { return mFilterDeprecated; }
416
417 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
418 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
419
420 private:
421 QgsCoordinateReferenceSystemModel *mModel = nullptr;
422 QString mFilterString;
423 QSet<QString> mFilterAuthIds;
424 bool mFilterDeprecated = false;
425 Filters mFilters = Filters();
426};
427
429
430
431#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_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs