QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 QWidget *parent SIP_TRANSFERTHIS = nullptr,
79 );
80
86
93 void setOptionVisible( CrsOption option, bool visible );
94
99 bool optionVisible( CrsOption option ) const;
100
105 void setNotSetText( const QString &text );
106
112 void setMessage( const QString &text );
113
121
129 bool showAccuracyWarnings() const;
130
138 void setShowAccuracyWarnings( bool show );
139
149 void setSourceEnsemble( const QString &ensemble );
150
160 QString sourceEnsemble() const;
161
167 void setDialogTitle( const QString &title );
168
174 QString dialogTitle() const;
175
181 void setFilter( const QList<QgsCoordinateReferenceSystem> &crses );
182
190
198
199 signals:
200
205
209 void cleared();
210
211 public slots:
212
218
225
229 void selectCrs();
230
231 protected:
232 void dragEnterEvent( QDragEnterEvent *event ) override;
233 void dragLeaveEvent( QDragLeaveEvent *event ) override;
234 void dropEvent( QDropEvent *event ) override;
235
236 private:
237 CombinedCoordinateReferenceSystemsProxyModel *mModel = nullptr;
238
239 QgsHighlightableComboBox *mCrsComboBox = nullptr;
240 QToolButton *mButton = nullptr;
241
242 QString mMessage;
243
244 bool mShowAccuracyWarnings = false;
245 QString mSourceEnsemble;
246
247 QWidget *mWarningLabelContainer = nullptr;
248 QLabel *mWarningLabel = nullptr;
249
250 QPointer<QgsCrsSelectionWidget> mActivePanel;
251 int mIgnorePanelSignals = 0;
252
253 QString mDialogTitle;
254
255 void updateTooltip();
256
257 QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
258
259 private slots:
260
261 void comboIndexChanged( int idx );
262 void updateWarning();
263};
264
266
268
269class StandardCoordinateReferenceSystemsModel : public QAbstractItemModel SIP_SKIP
270{
271 Q_OBJECT
272
273 public:
274 enum Role
275 {
276 // values copied from QgsRecentCoordinateReferenceSystemsModel
277 RoleCrs = Qt::UserRole,
278 // new values
279 RoleOption = RoleCrs + 100,
280 };
281
282 StandardCoordinateReferenceSystemsModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
283
284 Qt::ItemFlags flags( const QModelIndex &index ) const override;
285 QVariant data( const QModelIndex &index, int role ) const override;
286 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
287 int columnCount( const QModelIndex & = QModelIndex() ) const override;
288 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
289 QModelIndex parent( const QModelIndex &index ) const override;
290
291 QgsCoordinateReferenceSystem crs( const QModelIndex &index ) const;
292 QgsProjectionSelectionWidget::CrsOption optionForIndex( const QModelIndex &index ) const;
293 QModelIndex indexForOption( QgsProjectionSelectionWidget::CrsOption option ) const;
294
295 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
296 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
297 void setNotSetText( const QString &text );
298 QString notSetText() const { return mNotSetText; }
299 QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
300
301 private:
303 QgsCoordinateReferenceSystem mCurrentCrs;
304 QgsCoordinateReferenceSystem mProjectCrs;
305 QgsCoordinateReferenceSystem mDefaultCrs;
306 QgsCoordinateReferenceSystem mLayerCrs;
307
308 QString mNotSetText;
309};
310
311class CombinedCoordinateReferenceSystemsModel : public QConcatenateTablesProxyModel SIP_SKIP
312{
313 Q_OBJECT
314
315 public:
316 CombinedCoordinateReferenceSystemsModel( QObject *parent );
317 void setNotSetText( const QString &text );
318 QString notSetText() const;
319 QgsCoordinateReferenceSystem currentCrs() const;
320 StandardCoordinateReferenceSystemsModel *standardModel() { return mStandardModel; }
321
322 private:
323 StandardCoordinateReferenceSystemsModel *mStandardModel = nullptr;
324 QgsRecentCoordinateReferenceSystemsProxyModel *mRecentModel = nullptr;
325};
326
327class CombinedCoordinateReferenceSystemsProxyModel : public QSortFilterProxyModel SIP_SKIP
328{
329 Q_OBJECT
330
331 public:
332 CombinedCoordinateReferenceSystemsProxyModel( QObject *parent );
333 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
334 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
335 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
336 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
338
339 void setFilteredCrs( const QList<QgsCoordinateReferenceSystem> &crses );
340 QList<QgsCoordinateReferenceSystem> filteredCrs() const { return mFilteredCrs; }
341
342 void setOption( QgsProjectionSelectionWidget::CrsOption option, bool enabled );
343 CombinedCoordinateReferenceSystemsModel *combinedModel() const { return mModel; }
344
345 private:
346 CombinedCoordinateReferenceSystemsModel *mModel = nullptr;
348
349 QList<QgsCoordinateReferenceSystem> mFilteredCrs;
350
352};
353
355
356#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:83
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:52
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_SKIP
Definition qgis_sip.h:133
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)