QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
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 SIP_SKIP Q_DECLARE_FLAGS( CrsOptions, CrsOption )
69
70
78
84
91 void setOptionVisible( CrsOption option, bool visible );
92
97 bool optionVisible( CrsOption option ) const;
98
103 void setNotSetText( const QString &text );
104
110 void setMessage( const QString &text );
111
119
127 bool showAccuracyWarnings() const;
128
136 void setShowAccuracyWarnings( bool show );
137
147 void setSourceEnsemble( const QString &ensemble );
148
158 QString sourceEnsemble() const;
159
165 void setDialogTitle( const QString &title );
166
172 QString dialogTitle() const;
173
179 void setFilter( const QList<QgsCoordinateReferenceSystem> &crses );
180
188
196
197 signals:
198
203
207 void cleared();
208
209 public slots:
210
216
223
227 void selectCrs();
228
229 protected:
230 void dragEnterEvent( QDragEnterEvent *event ) override;
231 void dragLeaveEvent( QDragLeaveEvent *event ) override;
232 void dropEvent( QDropEvent *event ) override;
233
234 private:
235 CombinedCoordinateReferenceSystemsProxyModel *mModel = nullptr;
236
237 QgsHighlightableComboBox *mCrsComboBox = nullptr;
238 QToolButton *mButton = nullptr;
239
240 QString mMessage;
241
242 bool mShowAccuracyWarnings = false;
243 QString mSourceEnsemble;
244
245 QWidget *mWarningLabelContainer = nullptr;
246 QLabel *mWarningLabel = nullptr;
247
248 QPointer<QgsCrsSelectionWidget> mActivePanel;
249 int mIgnorePanelSignals = 0;
250
251 QString mDialogTitle;
252
253 void updateTooltip();
254
255 QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
256
257 private slots:
258
259 void comboIndexChanged( int idx );
260 void updateWarning();
261};
262
264
266
267class StandardCoordinateReferenceSystemsModel : public QAbstractItemModel SIP_SKIP
268{
269 Q_OBJECT
270
271 public:
272 enum Role
273 {
274 // values copied from QgsRecentCoordinateReferenceSystemsModel
275 RoleCrs = Qt::UserRole,
276 // new values
277 RoleOption = RoleCrs + 100,
278 };
279
280 StandardCoordinateReferenceSystemsModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
281
282 Qt::ItemFlags flags( const QModelIndex &index ) const override;
283 QVariant data( const QModelIndex &index, int role ) const override;
284 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
285 int columnCount( const QModelIndex & = QModelIndex() ) const override;
286 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
287 QModelIndex parent( const QModelIndex &index ) const override;
288
289 QgsCoordinateReferenceSystem crs( const QModelIndex &index ) const;
290 QgsProjectionSelectionWidget::CrsOption optionForIndex( const QModelIndex &index ) const;
291 QModelIndex indexForOption( QgsProjectionSelectionWidget::CrsOption option ) const;
292
293 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
294 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
295 void setNotSetText( const QString &text );
296 QString notSetText() const { return mNotSetText; }
297 QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
298
299 private:
301 QgsCoordinateReferenceSystem mCurrentCrs;
302 QgsCoordinateReferenceSystem mProjectCrs;
303 QgsCoordinateReferenceSystem mDefaultCrs;
304 QgsCoordinateReferenceSystem mLayerCrs;
305
306 QString mNotSetText;
307};
308
309class CombinedCoordinateReferenceSystemsModel : public QConcatenateTablesProxyModel SIP_SKIP
310{
311 Q_OBJECT
312
313 public:
314 CombinedCoordinateReferenceSystemsModel( QObject *parent );
315 void setNotSetText( const QString &text );
316 QString notSetText() const;
317 QgsCoordinateReferenceSystem currentCrs() const;
318 StandardCoordinateReferenceSystemsModel *standardModel() { return mStandardModel; }
319
320 private:
321 StandardCoordinateReferenceSystemsModel *mStandardModel = nullptr;
322 QgsRecentCoordinateReferenceSystemsProxyModel *mRecentModel = nullptr;
323};
324
325class CombinedCoordinateReferenceSystemsProxyModel : public QSortFilterProxyModel SIP_SKIP
326{
327 Q_OBJECT
328
329 public:
330 CombinedCoordinateReferenceSystemsProxyModel( QObject *parent );
331 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
332 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
333 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
334 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
336
337 void setFilteredCrs( const QList<QgsCoordinateReferenceSystem> &crses );
338 QList<QgsCoordinateReferenceSystem> filteredCrs() const { return mFilteredCrs; }
339
340 void setOption( QgsProjectionSelectionWidget::CrsOption option, bool enabled );
341 CombinedCoordinateReferenceSystemsModel *combinedModel() const { return mModel; }
342
343 private:
344 CombinedCoordinateReferenceSystemsModel *mModel = nullptr;
346
347 QList<QgsCoordinateReferenceSystem> mFilteredCrs;
348
350};
351
353
354#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)