23#include <QDialogButtonBox>
24#include <QApplication>
40 mNotSetText = tr(
"No CRS (or unknown/non-Earth projection)" );
41 mLabelNoCrs->setText( tr(
"Use this option to treat all coordinates as Cartesian coordinates in an unknown reference system." ) );
43 mComboCrsType->addItem( tr(
"Predefined CRS" ),
static_cast< int >( CrsType::Predefined ) );
44 mComboCrsType->addItem( tr(
"Custom CRS" ),
static_cast< int >( CrsType::Custom ) );
46 mStackedWidget->setCurrentWidget( mPageDatabase );
47 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int >( CrsType::Predefined ) ) );
49 connect( mComboCrsType, qOverload< int >( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
51 if ( !mComboCrsType->currentData().isValid() )
52 mStackedWidget->setCurrentWidget( mPageNoCrs );
55 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
57 case QgsCrsSelectionWidget::CrsType::Predefined:
58 mStackedWidget->setCurrentWidget( mPageDatabase );
60 case QgsCrsSelectionWidget::CrsType::Custom:
61 mStackedWidget->setCurrentWidget( mPageCustom );
91 mDeferredInvalidCrsSet =
false;
107 mSplitter->restoreState( settings.value( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ) ).toByteArray() );
113 settings.
setValue( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ), mSplitter->saveState() );
125 if ( mShowNoCrsOption == show )
129 mShowNoCrsOption = show;
130 if ( mShowNoCrsOption )
132 mComboCrsType->insertItem( 0, mNotSetText );
136 mComboCrsType->removeItem( 0 );
139 if ( show && mDeferredInvalidCrsSet )
141 mComboCrsType->setCurrentIndex( 0 );
146 if ( mDeferredInvalidCrsSet )
149 mDeferredInvalidCrsSet =
false;
156 return mShowNoCrsOption;
163 if ( mShowNoCrsOption )
165 mComboCrsType->setItemText( 0, mNotSetText );
168 mLabelNoCrs->setText( description.isEmpty() ? text : description );
173 if ( !mComboCrsType->currentData().isValid() )
175 else if ( mDeferredInvalidCrsSet )
179 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
181 case QgsCrsSelectionWidget::CrsType::Predefined:
182 return projectionSelector->hasValidSelection();
183 case QgsCrsSelectionWidget::CrsType::Custom:
184 return mCrsDefinitionWidget->crs().isValid();
192 if ( !mComboCrsType->currentData().isValid() )
196 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
198 case QgsCrsSelectionWidget::CrsType::Predefined:
199 return projectionSelector->crs();
200 case QgsCrsSelectionWidget::CrsType::Custom:
201 return mCrsDefinitionWidget->crs();
212 if ( mShowNoCrsOption )
213 mComboCrsType->setCurrentIndex( 0 );
215 mDeferredInvalidCrsSet =
true;
219 projectionSelector->setCrs(
crs );
220 mCrsDefinitionWidget->setCrs(
crs );
223 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Custom ) ) );
224 mStackedWidget->setCurrentWidget( mPageCustom );
228 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Predefined ) ) );
229 mStackedWidget->setCurrentWidget( mPageDatabase );
240 projectionSelector->setOgcWmsCrsFilter( crsFilter );
251 : QDialog( parent, fl )
253 QVBoxLayout *vlayout =
new QVBoxLayout();
256 vlayout->addWidget( mCrsWidget, 1 );
258 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
259 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
260 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
261 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
263 vlayout->addWidget( mButtonBox );
265 setLayout( vlayout );
280 setMessage( tr(
"This layer appears to have no projection specification." )
282 + tr(
"By default, this layer will now have its projection set to that of the project, "
283 "but you may override this by selecting a different projection below." ) );
303 mRequireValidSelection =
true;
308 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
319 return mCrsWidget->
crs();
326 if ( mRequireValidSelection )
335void QgsProjectionSelectionDialog::showHelp()
337 QgsHelp::openHelp( QStringLiteral(
"working_with_projections/working_with_projections.html" ) );
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
void showNoCrsForLayerMessage()
When called, the dialog will show a default "layer has no CRS set" message above the projection selec...
void setShowNoProjection(bool show)
Sets whether a "no/invalid" projection option should be shown.
bool showNoProjection() const
Returns whether the "no/invalid" projection option is shown.
bool hasValidSelection() const
Returns true if the dialog has a valid CRS defined.
void setNotSetText(const QString &text, const QString &description=QString())
Sets the text to show for the not set option.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the initial crs to show within the dialog.
void setMessage(const QString &message)
Sets a message to show in the dialog.
QgsCoordinateReferenceSystem crs() const
Returns the CRS currently selected in the widget.
QgsProjectionSelectionDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags)
Constructor for QgsProjectionSelectionDialog.
void setRequireValidSelection()
Sets the dialog to require a valid selection only, preventing users from accepting the dialog if no s...
void setOgcWmsCrsFilter(const QSet< QString > &crsFilter)
filters this dialog by the given CRSs
This class is a composition of two QSettings instances:
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define BUILTIN_UNREACHABLE
const QgsCoordinateReferenceSystem & crs