QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgis_gui.h"
21#include "qgis_sip.h"
24
25#include <QComboBox>
26#include <QConcatenateTablesProxyModel>
27#include <QLineEdit>
28#include <QPointer>
29#include <QToolButton>
30#include <QWidget>
31
32class QgsMapLayer;
35class QLabel;
36class QgsMapLayer;
38class CombinedCoordinateReferenceSystemsProxyModel;
39
45class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
46{
47 Q_OBJECT
48 public:
53 {
54 Invalid = 1 << 0,
55 LayerCrs = 1 << 1,
56 ProjectCrs = 1 << 2,
57 CurrentCrs = 1 << 3,
58 DefaultCrs = 1 << 4,
59 RecentCrs = 1 << 5,
60 CrsNotSet = 1 << 6,
61 };
62
67 SIP_SKIP Q_DECLARE_FLAGS( CrsOptions, CrsOption )
68
69
77
83
90 void setOptionVisible( CrsOption option, bool visible );
91
96 bool optionVisible( CrsOption option ) const;
97
102 void setNotSetText( const QString &text );
103
109 void setMessage( const QString &text );
110
118
126 bool showAccuracyWarnings() const;
127
135 void setShowAccuracyWarnings( bool show );
136
146 void setSourceEnsemble( const QString &ensemble );
147
157 QString sourceEnsemble() const;
158
164 void setDialogTitle( const QString &title );
165
171 QString dialogTitle() const;
172
178 void setFilter( const QList<QgsCoordinateReferenceSystem> &crses );
179
187
195
196 signals:
197
202
206 void cleared();
207
208 public slots:
209
215
222
226 void selectCrs();
227
228 protected:
229 void dragEnterEvent( QDragEnterEvent *event ) override;
230 void dragLeaveEvent( QDragLeaveEvent *event ) override;
231 void dropEvent( QDropEvent *event ) override;
232
233 private:
234 CombinedCoordinateReferenceSystemsProxyModel *mModel = nullptr;
235
236 QgsHighlightableComboBox *mCrsComboBox = nullptr;
237 QToolButton *mButton = nullptr;
238
239 QString mMessage;
240
241 bool mShowAccuracyWarnings = false;
242 QString mSourceEnsemble;
243
244 QWidget *mWarningLabelContainer = nullptr;
245 QLabel *mWarningLabel = nullptr;
246
247 QPointer<QgsCrsSelectionWidget> mActivePanel;
248 int mIgnorePanelSignals = 0;
249
250 QString mDialogTitle;
251
252 void updateTooltip();
253
254 QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
255
256 private slots:
257
258 void comboIndexChanged( int idx );
259 void updateWarning();
260};
261
263
265
266class StandardCoordinateReferenceSystemsModel : public QAbstractItemModel SIP_SKIP
267{
268 Q_OBJECT
269
270 public:
271 enum Role
272 {
273 // values copied from QgsRecentCoordinateReferenceSystemsModel
274 RoleCrs = Qt::UserRole,
275 // new values
276 RoleOption = RoleCrs + 100,
277 };
278
279 StandardCoordinateReferenceSystemsModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
280
281 Qt::ItemFlags flags( const QModelIndex &index ) const override;
282 QVariant data( const QModelIndex &index, 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
288 QgsCoordinateReferenceSystem crs( const QModelIndex &index ) const;
289 QgsProjectionSelectionWidget::CrsOption optionForIndex( const QModelIndex &index ) const;
290 QModelIndex indexForOption( QgsProjectionSelectionWidget::CrsOption option ) const;
291
292 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
293 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
294 void setNotSetText( const QString &text );
295 QString notSetText() const { return mNotSetText; }
296 QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
297
298 private:
300 QgsCoordinateReferenceSystem mCurrentCrs;
301 QgsCoordinateReferenceSystem mProjectCrs;
302 QgsCoordinateReferenceSystem mDefaultCrs;
303 QgsCoordinateReferenceSystem mLayerCrs;
304
305 QString mNotSetText;
306};
307
308class CombinedCoordinateReferenceSystemsModel : public QConcatenateTablesProxyModel SIP_SKIP
309{
310 Q_OBJECT
311
312 public:
313 CombinedCoordinateReferenceSystemsModel( QObject *parent );
314 void setNotSetText( const QString &text );
315 QString notSetText() const;
316 QgsCoordinateReferenceSystem currentCrs() const;
317 StandardCoordinateReferenceSystemsModel *standardModel() { return mStandardModel; }
318
319 private:
320 StandardCoordinateReferenceSystemsModel *mStandardModel = nullptr;
321 QgsRecentCoordinateReferenceSystemsProxyModel *mRecentModel = nullptr;
322};
323
324class CombinedCoordinateReferenceSystemsProxyModel : public QSortFilterProxyModel SIP_SKIP
325{
326 Q_OBJECT
327
328 public:
329 CombinedCoordinateReferenceSystemsProxyModel( QObject *parent );
330 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
331 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
332 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
333 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
335
336 void setFilteredCrs( const QList<QgsCoordinateReferenceSystem> &crses );
337 QList<QgsCoordinateReferenceSystem> filteredCrs() const { return mFilteredCrs; }
338
339 void setOption( QgsProjectionSelectionWidget::CrsOption option, bool enabled );
340 CombinedCoordinateReferenceSystemsModel *combinedModel() const { return mModel; }
341
342 private:
343 CombinedCoordinateReferenceSystemsModel *mModel = nullptr;
345
346 QList<QgsCoordinateReferenceSystem> mFilteredCrs;
347
349};
350
352
353#endif // QGSPROJECTIONSELECTIONWIDGET_H
@ FilterHorizontal
Include horizontal CRS (excludes compound CRS containing a horizontal component).
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:80
void setFilter(const QList< QgsCoordinateReferenceSystem > &crses)
Sets a filtered list of CRSes to show in the widget.
bool showAccuracyWarnings() const
Returns true if the widget will show a warning to users when they select a CRS which has low accuracy...
void cleared()
Emitted when the not set option is selected.
void selectCrs()
Opens the dialog for selecting a new CRS.
CrsOption
Predefined CRS options shown in widget.
@ CrsNotSet
Not set (hidden by default).
@ ProjectCrs
Current project CRS (if OTF reprojection enabled).
@ Invalid
Invalid option, since QGIS 3.36.
@ CurrentCrs
Current user selected CRS.
bool optionVisible(CrsOption option) const
Returns whether the specified CRS option is visible in the widget.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the current CRS for the widget.
void setNotSetText(const QString &text)
Sets the text to show for the not set option.
void setLayerCrs(const QgsCoordinateReferenceSystem &crs)
Sets the layer CRS for the widget.
void setOptionVisible(CrsOption option, bool visible)
Sets whether a predefined CRS option should be shown in the widget.
QString sourceEnsemble() const
Returns the original source ensemble datum name.
QgsCoordinateReferenceSystem crs() const
Returns the currently selected CRS for the widget.
QString dialogTitle() const
Returns the title for the CRS selector dialog window.
void setFilters(QgsCoordinateReferenceSystemProxyModel::Filters filters)
Sets filters for the available CRS.
void dragEnterEvent(QDragEnterEvent *event) override
void setMessage(const QString &text)
Sets a message to show in the dialog.
static QString crsOptionText(const QgsCoordinateReferenceSystem &crs)
Returns display text for the specified crs.
void dragLeaveEvent(QDragLeaveEvent *event) override
void setShowAccuracyWarnings(bool show)
Sets whether the widget will show warnings to users when they select a CRS which has low accuracy.
void setDialogTitle(const QString &title)
Sets the title for the CRS selector dialog window.
void crsChanged(const QgsCoordinateReferenceSystem &crs)
Emitted when the selected CRS is changed.
QFlags< CrsOption > CrsOptions
Flags for predefined CRS options shown in widget.
void setSourceEnsemble(const QString &ensemble)
Sets the original source ensemble datum name.
QgsCoordinateReferenceSystemProxyModel::Filters filters() const
Returns the filters set on the available CRS.
QgsProjectionSelectionWidget(QWidget *parent=nullptr, QgsCoordinateReferenceSystemProxyModel::Filters filters=QgsCoordinateReferenceSystemProxyModel::FilterHorizontal|QgsCoordinateReferenceSystemProxyModel::FilterCompound)
Constructor for QgsProjectionSelectionWidget, with the specified parent widget.
void dropEvent(QDropEvent *event) override
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:275
#define SIP_SKIP
Definition qgis_sip.h:134
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)