QgsProjectionSelectionWidget class

A widget for selecting a projection.

Public types

enum CrsOption { LayerCrs, ProjectCrs, CurrentCrs, DefaultCrs, RecentCrs, CrsNotSet }
Predefined CRS options shown in widget.

Constructors, destructors, conversion operators

QgsProjectionSelectionWidget(QWidget* parent = nullptr) explicit
Constructor for QgsProjectionSelectionWidget.

Public functions

auto crs() const -> QgsCoordinateReferenceSystem
Returns the currently selected CRS for the widget.
auto optionVisible(CrsOption option) const -> bool
Returns whether the specified CRS option is visible in the widget.
void setMessage(const QString& text)
Sets a message to show in the dialog.
void setNotSetText(const QString& text)
Sets the text to show for the not set option.
void setOptionVisible(CrsOption option, bool visible)
Sets whether a predefined CRS option should be shown in the widget.

Signals

void cleared()
Emitted when the not set option is selected.
void crsChanged(const QgsCoordinateReferenceSystem&)
Emitted when the selected CRS is changed.

Public slots

void selectCrs()
Opens the dialog for selecting a new CRS.
void setCrs(const QgsCoordinateReferenceSystem& crs)
Sets the current CRS for the widget.
void setLayerCrs(const QgsCoordinateReferenceSystem& crs)
Sets the layer CRS for the widget.

Enum documentation

enum QgsProjectionSelectionWidget::CrsOption

Predefined CRS options shown in widget.

Enumerators
LayerCrs

Optional layer CRS.

ProjectCrs

Current project CRS (if OTF reprojection enabled)

CurrentCrs

Current user selected CRS.

DefaultCrs

Global default QGIS CRS.

RecentCrs

Recently used CRS.

CrsNotSet

Not set (hidden by default)

Function documentation

QgsCoordinateReferenceSystem QgsProjectionSelectionWidget::crs() const

Returns the currently selected CRS for the widget.

Returns current CRS

bool QgsProjectionSelectionWidget::optionVisible(CrsOption option) const

Returns whether the specified CRS option is visible in the widget.

void QgsProjectionSelectionWidget::setMessage(const QString& text)

Sets a message to show in the dialog.

If an empty string is passed, the message will be a generic 'define the CRS for this layer'.

void QgsProjectionSelectionWidget::setNotSetText(const QString& text)

Sets the text to show for the not set option.

Note that this option is not shown by default and must be set visible by calling setOptionVisible().

void QgsProjectionSelectionWidget::setOptionVisible(CrsOption option, bool visible)

Sets whether a predefined CRS option should be shown in the widget.

Parameters
option CRS option to show/hide
visible whether the option should be shown

void QgsProjectionSelectionWidget::cleared() signal

Emitted when the not set option is selected.

void QgsProjectionSelectionWidget::setCrs(const QgsCoordinateReferenceSystem& crs) public slot

Sets the current CRS for the widget.

Parameters
crs new CRS

void QgsProjectionSelectionWidget::setLayerCrs(const QgsCoordinateReferenceSystem& crs) public slot

Sets the layer CRS for the widget.

Parameters
crs layer CRS

If set, this will be added as an option to the preset CRSes shown in the widget.