25#include <QApplication>
26#include <QDialogButtonBox>
30#include "moc_qgsprojectionselectiondialog.cpp"
32using namespace Qt::StringLiterals;
42 projectionSelector->setFilters(
filters );
47 mNotSetText = tr(
"No CRS (or unknown/non-Earth projection)" );
48 mLabelNoCrs->setText( tr(
"Use this option to treat all coordinates as Cartesian coordinates in an unknown reference system." ) );
50 mComboCrsType->addItem( tr(
"Predefined CRS" ),
static_cast<int>( CrsType::Predefined ) );
51 mComboCrsType->addItem( tr(
"Custom CRS" ),
static_cast<int>( CrsType::Custom ) );
53 mStackedWidget->setCurrentWidget( mPageDatabase );
54 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Predefined ) ) );
56 connect( mComboCrsType, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) {
57 if ( !mComboCrsType->currentData().isValid() )
58 mStackedWidget->setCurrentWidget( mPageNoCrs );
61 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
63 case QgsCrsSelectionWidget::CrsType::Predefined:
64 mStackedWidget->setCurrentWidget( mPageDatabase );
66 case QgsCrsSelectionWidget::CrsType::Custom:
67 mStackedWidget->setCurrentWidget( mPageCustom );
94 mDeferredInvalidCrsSet =
false;
101 if ( !mBlockSignals )
109 mSplitter->restoreState( settings.value( u
"Windows/ProjectionSelectorDialog/splitterState"_s ).toByteArray() );
115 settings.
setValue( u
"Windows/ProjectionSelectorDialog/splitterState"_s, mSplitter->saveState() );
126 if ( mShowNoCrsOption == show )
130 mShowNoCrsOption = show;
131 if ( mShowNoCrsOption )
133 mComboCrsType->insertItem( 0, mNotSetText );
137 mComboCrsType->removeItem( 0 );
140 if ( show && mDeferredInvalidCrsSet )
142 mComboCrsType->setCurrentIndex( 0 );
147 if ( mDeferredInvalidCrsSet )
150 mDeferredInvalidCrsSet =
false;
157 return mShowNoCrsOption;
164 if ( mShowNoCrsOption )
166 mComboCrsType->setItemText( 0, mNotSetText );
169 mLabelNoCrs->setText( description.isEmpty() ? text : description );
174 if ( !mComboCrsType->currentData().isValid() )
176 else if ( mDeferredInvalidCrsSet )
180 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
182 case QgsCrsSelectionWidget::CrsType::Predefined:
183 return projectionSelector->hasValidSelection();
184 case QgsCrsSelectionWidget::CrsType::Custom:
185 return mCrsDefinitionWidget->crs().isValid();
193 return projectionSelector->filters();
198 projectionSelector->setFilters(
filters );
203 if ( !mComboCrsType->currentData().isValid() )
207 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
209 case QgsCrsSelectionWidget::CrsType::Predefined:
210 return projectionSelector->crs();
211 case QgsCrsSelectionWidget::CrsType::Custom:
212 return mCrsDefinitionWidget->crs();
221 if ( !
crs.isValid() )
223 if ( mShowNoCrsOption )
224 mComboCrsType->setCurrentIndex( 0 );
226 mDeferredInvalidCrsSet =
true;
230 projectionSelector->setCrs(
crs );
231 mCrsDefinitionWidget->setCrs(
crs );
232 if (
crs.isValid() &&
crs.authid().isEmpty() )
234 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Custom ) ) );
235 mStackedWidget->setCurrentWidget( mPageCustom );
239 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Predefined ) ) );
240 mStackedWidget->setCurrentWidget( mPageDatabase );
251 projectionSelector->setOgcWmsCrsFilter( crsFilter );
260 : QDialog( parent, fl )
262 QVBoxLayout *vlayout =
new QVBoxLayout();
265 vlayout->addWidget( mCrsWidget, 1 );
267 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
268 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
269 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
270 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
272 vlayout->addWidget( mButtonBox );
274 setLayout( vlayout );
284 mCrsWidget->setMessage( message );
289 setMessage( tr(
"This layer appears to have no projection specification." ) +
' ' + tr(
"By default, this layer will now have its projection set to that of the project, "
290 "but you may override this by selecting a different projection below." ) );
295 mCrsWidget->setShowNoCrs( show );
300 return mCrsWidget->showNoCrs();
305 mCrsWidget->setNotSetText( text, description );
310 mRequireValidSelection =
true;
314 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
320 return mCrsWidget->hasValidSelection();
325 return mCrsWidget->filters();
330 mCrsWidget->setFilters(
filters );
335 return mCrsWidget->crs();
340 mCrsWidget->setCrs(
crs );
342 if ( mRequireValidSelection )
348 mCrsWidget->setOgcWmsCrsFilter( crsFilter );
351void QgsProjectionSelectionDialog::showHelp()
353 QgsHelp::openHelp( u
"working_with_projections/working_with_projections.html"_s );
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
Represents a coordinate reference system (CRS).
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.
QgsCoordinateReferenceSystemProxyModel::Filters filters() const
Returns the filters set on the available CRS.
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, QgsCoordinateReferenceSystemProxyModel::Filters filters=QgsCoordinateReferenceSystemProxyModel::FilterHorizontal|QgsCoordinateReferenceSystemProxyModel::FilterCompound)
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
void setFilters(QgsCoordinateReferenceSystemProxyModel::Filters filters)
Sets filters for the available CRS.
Stores settings for use within QGIS.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define BUILTIN_UNREACHABLE