QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgsprojectionselectionwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprojectionselectionwidget.h
3 --------------------------------------
4 Date : 05.01.2015
5 Copyright : (C) 2015 Denis Rouzaud
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16
17#ifndef QGSPROJECTIONSELECTIONWIDGET_H
18#define QGSPROJECTIONSELECTIONWIDGET_H
19
20#include <QWidget>
21#include "qgis_sip.h"
22#include <QLineEdit>
23#include <QToolButton>
24#include <QComboBox>
25#include <QPointer>
26#include <QConcatenateTablesProxyModel>
27
30#include "qgis_gui.h"
31
32class QgsMapLayer;
35class QLabel;
36class QgsMapLayer;
38class CombinedCoordinateReferenceSystemsProxyModel;
39
45class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
46{
47 Q_OBJECT
48 public:
49
54 {
55 Invalid = 1 << 0,
56 LayerCrs = 1 << 1,
57 ProjectCrs = 1 << 2,
58 CurrentCrs = 1 << 3,
59 DefaultCrs = 1 << 4,
60 RecentCrs = 1 << 5,
61 CrsNotSet = 1 << 6,
62 };
63
68 Q_DECLARE_FLAGS( CrsOptions, CrsOption ) SIP_SKIP;
69
77 explicit QgsProjectionSelectionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr,
79
85
92 void setOptionVisible( CrsOption option, bool visible );
93
98 bool optionVisible( CrsOption option ) const;
99
104 void setNotSetText( const QString &text );
105
111 void setMessage( const QString &text );
112
119 static QString crsOptionText( const QgsCoordinateReferenceSystem &crs ) SIP_SKIP;
120
128 bool showAccuracyWarnings() const;
129
137 void setShowAccuracyWarnings( bool show );
138
148 void setSourceEnsemble( const QString &ensemble );
149
159 QString sourceEnsemble() const;
160
166 void setDialogTitle( const QString &title );
167
173 QString dialogTitle() const;
174
180 void setFilter( const QList< QgsCoordinateReferenceSystem > &crses );
181
189
196 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
197
198 signals:
199
204
208 void cleared();
209
210 public slots:
211
216 void setCrs( const QgsCoordinateReferenceSystem &crs );
217
223 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
224
228 void selectCrs();
229
230 protected:
231
232 void dragEnterEvent( QDragEnterEvent *event ) override;
233 void dragLeaveEvent( QDragLeaveEvent *event ) override;
234 void dropEvent( QDropEvent *event ) override;
235
236 private:
237
238 CombinedCoordinateReferenceSystemsProxyModel *mModel = nullptr;
239
240 QgsHighlightableComboBox *mCrsComboBox = nullptr;
241 QToolButton *mButton = nullptr;
242
243 QString mMessage;
244
245 bool mShowAccuracyWarnings = false;
246 QString mSourceEnsemble;
247
248 QWidget *mWarningLabelContainer = nullptr;
249 QLabel *mWarningLabel = nullptr;
250
251 QPointer< QgsCrsSelectionWidget > mActivePanel;
252 int mIgnorePanelSignals = 0;
253
254 QString mDialogTitle;
255
256 void updateTooltip();
257
258 QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
259
260 private slots:
261
262 void comboIndexChanged( int idx );
263 void updateWarning();
264
265};
266
268
269
271
272class StandardCoordinateReferenceSystemsModel : public QAbstractItemModel SIP_SKIP
273{
274 Q_OBJECT
275
276 public:
277
278 enum Role
279 {
280 // values copied from QgsRecentCoordinateReferenceSystemsModel
281 RoleCrs = Qt::UserRole,
282 // new values
283 RoleOption = RoleCrs + 100,
284 };
285
286 StandardCoordinateReferenceSystemsModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
287
288 Qt::ItemFlags flags( const QModelIndex &index ) const override;
289 QVariant data( const QModelIndex &index, int role ) const override;
290 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
291 int columnCount( const QModelIndex & = QModelIndex() ) const override;
292 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
293 QModelIndex parent( const QModelIndex &index ) const override;
294
295 QgsCoordinateReferenceSystem crs( const QModelIndex &index ) const;
296 QgsProjectionSelectionWidget::CrsOption optionForIndex( const QModelIndex &index ) const;
297 QModelIndex indexForOption( QgsProjectionSelectionWidget::CrsOption option ) const;
298
299 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
300 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
301 void setNotSetText( const QString &text );
302 QString notSetText() const { return mNotSetText; }
303 QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
304 private:
305
311
312 QString mNotSetText;
313};
314
315class CombinedCoordinateReferenceSystemsModel : public QConcatenateTablesProxyModel SIP_SKIP
316{
317 Q_OBJECT
318
319 public:
320 CombinedCoordinateReferenceSystemsModel( QObject *parent );
321 void setNotSetText( const QString &text );
322 QString notSetText() const;
323 QgsCoordinateReferenceSystem currentCrs() const;
324 StandardCoordinateReferenceSystemsModel *standardModel() { return mStandardModel; }
325 private:
326
327 StandardCoordinateReferenceSystemsModel *mStandardModel = nullptr;
328 QgsRecentCoordinateReferenceSystemsProxyModel *mRecentModel = nullptr;
329};
330
331class CombinedCoordinateReferenceSystemsProxyModel : public QSortFilterProxyModel SIP_SKIP
332{
333 Q_OBJECT
334
335 public:
336
337 CombinedCoordinateReferenceSystemsProxyModel( QObject *parent );
338 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
339 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
340 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
341 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
343
344 void setFilteredCrs( const QList< QgsCoordinateReferenceSystem > &crses );
345 QList< QgsCoordinateReferenceSystem > filteredCrs() const { return mFilteredCrs; }
346
347 void setOption( QgsProjectionSelectionWidget::CrsOption option, bool enabled );
348 CombinedCoordinateReferenceSystemsModel *combinedModel() const { return mModel; }
349 private:
350
351 CombinedCoordinateReferenceSystemsModel *mModel = nullptr;
353
354 QList<QgsCoordinateReferenceSystem> mFilteredCrs;
355
357
358};
359
361
362#endif // QGSPROJECTIONSELECTIONWIDGET_H
@ FilterHorizontal
Include horizontal CRS (excludes compound CRS containing a horizontal component)
This class represents a coordinate reference system (CRS).
A generic widget allowing users to pick a Coordinate Reference System (or define their own).
A QComboBox subclass with the ability to "highlight" the edges of the widget.
Base class for all map layer types.
Definition: qgsmaplayer.h:75
A widget for selecting a projection.
void cleared()
Emitted when the not set option is selected.
void crsChanged(const QgsCoordinateReferenceSystem &)
Emitted when the selected CRS is changed.
CrsOption
Predefined CRS options shown in widget.
QFlags< CrsOption > CrsOptions
Flags for predefined CRS options shown in widget.
A sort/filter proxy model for recent coordinate reference systems.
#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
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs