QGIS API Documentation 4.3.0-Master (bf28115e945)
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
6 Email : denis.rouzaud@gmail.com
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
206 void setAllowTopocentricCrs( bool allow );
207
208 signals:
209
214
218 void cleared();
219
220 public slots:
221
227
234
238 void selectCrs();
239
240 protected:
241 void dragEnterEvent( QDragEnterEvent *event ) override;
242 void dragLeaveEvent( QDragLeaveEvent *event ) override;
243 void dropEvent( QDropEvent *event ) override;
244
245 private:
246 CombinedCoordinateReferenceSystemsProxyModel *mModel = nullptr;
247
248 QgsHighlightableComboBox *mCrsComboBox = nullptr;
249 QToolButton *mButton = nullptr;
250
251 QString mMessage;
252
253 bool mAllowTopocentricCrs = true;
254 bool mShowAccuracyWarnings = false;
255 QString mSourceEnsemble;
256
257 QWidget *mWarningLabelContainer = nullptr;
258 QLabel *mWarningLabel = nullptr;
259
260 QPointer<QgsCrsSelectionWidget> mActivePanel;
261 int mIgnorePanelSignals = 0;
262
263 QString mDialogTitle;
264
265 void updateTooltip();
266
267 QgsMapLayer *mapLayerFromMimeData( const QMimeData *data ) const;
268
269 private slots:
270
271 void comboIndexChanged( int idx );
272 void updateWarning();
273};
274
276
278
279class StandardCoordinateReferenceSystemsModel : public QAbstractItemModel SIP_SKIP
280{
281 Q_OBJECT
282
283 public:
284 enum Role
285 {
286 // values copied from QgsRecentCoordinateReferenceSystemsModel
287 RoleCrs = Qt::UserRole,
288 // new values
289 RoleOption = RoleCrs + 100,
290 };
291
292 StandardCoordinateReferenceSystemsModel( QObject *parent SIP_TRANSFERTHIS = nullptr );
293
294 Qt::ItemFlags flags( const QModelIndex &index ) const override;
295 QVariant data( const QModelIndex &index, int role ) const override;
296 int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
297 int columnCount( const QModelIndex & = QModelIndex() ) const override;
298 QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const override;
299 QModelIndex parent( const QModelIndex &index ) const override;
300
301 QgsCoordinateReferenceSystem crs( const QModelIndex &index ) const;
302 QgsProjectionSelectionWidget::CrsOption optionForIndex( const QModelIndex &index ) const;
303 QModelIndex indexForOption( QgsProjectionSelectionWidget::CrsOption option ) const;
304
305 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
306 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
307 void setNotSetText( const QString &text );
308 QString notSetText() const { return mNotSetText; }
309 QgsCoordinateReferenceSystem currentCrs() const { return mCurrentCrs; }
310
311 private:
313 QgsCoordinateReferenceSystem mCurrentCrs;
314 QgsCoordinateReferenceSystem mProjectCrs;
315 QgsCoordinateReferenceSystem mDefaultCrs;
316 QgsCoordinateReferenceSystem mLayerCrs;
317
318 QString mNotSetText;
319};
320
321class CombinedCoordinateReferenceSystemsModel : public QConcatenateTablesProxyModel SIP_SKIP
322{
323 Q_OBJECT
324
325 public:
326 CombinedCoordinateReferenceSystemsModel( QObject *parent );
327 void setNotSetText( const QString &text );
328 QString notSetText() const;
329 QgsCoordinateReferenceSystem currentCrs() const;
330 StandardCoordinateReferenceSystemsModel *standardModel() { return mStandardModel; }
331
332 private:
333 StandardCoordinateReferenceSystemsModel *mStandardModel = nullptr;
334 QgsRecentCoordinateReferenceSystemsProxyModel *mRecentModel = nullptr;
335};
336
337class CombinedCoordinateReferenceSystemsProxyModel : public QSortFilterProxyModel SIP_SKIP
338{
339 Q_OBJECT
340
341 public:
342 CombinedCoordinateReferenceSystemsProxyModel( QObject *parent );
343 bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
344 void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
345 void setCurrentCrs( const QgsCoordinateReferenceSystem &crs );
346 void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
348
349 void setFilteredCrs( const QList<QgsCoordinateReferenceSystem> &crses );
350 QList<QgsCoordinateReferenceSystem> filteredCrs() const { return mFilteredCrs; }
351
352 void setOption( QgsProjectionSelectionWidget::CrsOption option, bool enabled );
353 CombinedCoordinateReferenceSystemsModel *combinedModel() const { return mModel; }
354
355 private:
356 CombinedCoordinateReferenceSystemsModel *mModel = nullptr;
358
359 QList<QgsCoordinateReferenceSystem> mFilteredCrs;
360
362};
363
365
366#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.
void setAllowTopocentricCrs(bool allow)
Sets whether the topocentric CRS option is allowed in the CRS selector dialog opened by the widget's ...
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:272
#define SIP_SKIP
Definition qgis_sip.h:133
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)