QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
230 // *INDENT-OFF*
231
239 {
240 NodeType SIP_MONKEYPATCH_COMPAT_NAME(RoleNodeType) = Qt::UserRole,
241 Name SIP_MONKEYPATCH_COMPAT_NAME(RoleName) = Qt::UserRole + 1,
242 AuthId SIP_MONKEYPATCH_COMPAT_NAME(RoleAuthId) = Qt::UserRole + 2,
243 Deprecated SIP_MONKEYPATCH_COMPAT_NAME(RoleDeprecated) = Qt::UserRole + 3,
244 Type SIP_MONKEYPATCH_COMPAT_NAME(RoleType)= Qt::UserRole + 4,
245 GroupId SIP_MONKEYPATCH_COMPAT_NAME(RoleGroupId) = Qt::UserRole + 5,
246 Wkt SIP_MONKEYPATCH_COMPAT_NAME(RoleWkt) = Qt::UserRole + 6,
247 Proj SIP_MONKEYPATCH_COMPAT_NAME(RoleProj) = Qt::UserRole + 7,
248 };
249 Q_ENUM( CustomRole )
250 // *INDENT-ON*
251
252
255 QgsCoordinateReferenceSystemModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
256
257 Qt::ItemFlags flags( const QModelIndex &index ) const override;
258 QVariant data( const QModelIndex &index, int role ) const override;
259 QVariant headerData( int section, Qt::Orientation orientation, int role ) const override;
260 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
261 int columnCount( const QModelIndex & = QModelIndex() ) const override;
262 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
263 QModelIndex parent( const QModelIndex &index ) const override;
264
271 QModelIndex addCustomCrs( const QgsCoordinateReferenceSystem &crs );
272
278 QModelIndex authIdToIndex( const QString &authId ) const;
279
280 private slots:
281
282 void rebuild();
283 void userCrsAdded( const QString &id );
284 void userCrsRemoved( long id );
285 void userCrsChanged( const QString &id );
286
287 private:
288
289 QgsCoordinateReferenceSystemModelCrsNode *addRecord( const QgsCrsDbRecord &record );
290
291 QgsCoordinateReferenceSystemModelNode *index2node( const QModelIndex &index ) const;
292 QModelIndex node2index( QgsCoordinateReferenceSystemModelNode *node ) const;
293 QModelIndex indexOfParentTreeNode( QgsCoordinateReferenceSystemModelNode *parentNode ) const;
294
295
296 std::unique_ptr< QgsCoordinateReferenceSystemModelGroupNode > mRootNode;
297
298 QList< QgsCrsDbRecord > mCrsDbRecords;
299
300};
301
302
309class GUI_EXPORT QgsCoordinateReferenceSystemProxyModel: public QSortFilterProxyModel
310{
311 Q_OBJECT
312
313 public:
314
316 enum Filter SIP_ENUM_BASETYPE( IntFlag )
317 {
318 FilterHorizontal = 1 << 1,
319 FilterVertical = 1 << 2,
320 FilterCompound = 1 << 3,
321 };
322 Q_DECLARE_FLAGS( Filters, Filter )
323 Q_FLAG( Filters )
324
325
328 explicit QgsCoordinateReferenceSystemProxyModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
329
333 QgsCoordinateReferenceSystemModel *coordinateReferenceSystemModel();
334
339 const QgsCoordinateReferenceSystemModel *coordinateReferenceSystemModel() const SIP_SKIP;
340
345 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
346
351 Filters filters() const { return mFilters; }
352
359 void setFilterString( const QString &filter );
360
366 QString filterString() const { return mFilterString; }
367
374 void setFilterAuthIds( const QSet< QString > &filter );
375
381 QSet< QString > filterAuthIds() const { return mFilterAuthIds; }
382
388 void setFilterDeprecated( bool filter );
389
395 bool filterDeprecated() const { return mFilterDeprecated; }
396
397 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
398 bool lessThan( const QModelIndex &left, const QModelIndex &right ) const override;
399
400 private:
401
402 QgsCoordinateReferenceSystemModel *mModel = nullptr;
403 QString mFilterString;
404 QSet< QString > mFilterAuthIds;
405 bool mFilterDeprecated = false;
406 Filters mFilters = Filters();
407};
408
410
411
412#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