23#include <QDialogButtonBox>
24#include <QApplication>
38 projectionSelector->setFilters(
filters );
43 mNotSetText = tr(
"No CRS (or unknown/non-Earth projection)" );
44 mLabelNoCrs->setText( tr(
"Use this option to treat all coordinates as Cartesian coordinates in an unknown reference system." ) );
46 mComboCrsType->addItem( tr(
"Predefined CRS" ),
static_cast< int >( CrsType::Predefined ) );
47 mComboCrsType->addItem( tr(
"Custom CRS" ),
static_cast< int >( CrsType::Custom ) );
49 mStackedWidget->setCurrentWidget( mPageDatabase );
50 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int >( CrsType::Predefined ) ) );
52 connect( mComboCrsType, qOverload< int >( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
54 if ( !mComboCrsType->currentData().isValid() )
55 mStackedWidget->setCurrentWidget( mPageNoCrs );
58 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
60 case QgsCrsSelectionWidget::CrsType::Predefined:
61 mStackedWidget->setCurrentWidget( mPageDatabase );
63 case QgsCrsSelectionWidget::CrsType::Custom:
64 mStackedWidget->setCurrentWidget( mPageCustom );
94 mDeferredInvalidCrsSet =
false;
102 if ( !mBlockSignals )
110 mSplitter->restoreState( settings.value( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ) ).toByteArray() );
116 settings.
setValue( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ), mSplitter->saveState() );
128 if ( mShowNoCrsOption == show )
132 mShowNoCrsOption = show;
133 if ( mShowNoCrsOption )
135 mComboCrsType->insertItem( 0, mNotSetText );
139 mComboCrsType->removeItem( 0 );
142 if ( show && mDeferredInvalidCrsSet )
144 mComboCrsType->setCurrentIndex( 0 );
149 if ( mDeferredInvalidCrsSet )
152 mDeferredInvalidCrsSet =
false;
159 return mShowNoCrsOption;
166 if ( mShowNoCrsOption )
168 mComboCrsType->setItemText( 0, mNotSetText );
171 mLabelNoCrs->setText( description.isEmpty() ? text : description );
176 if ( !mComboCrsType->currentData().isValid() )
178 else if ( mDeferredInvalidCrsSet )
182 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
184 case QgsCrsSelectionWidget::CrsType::Predefined:
185 return projectionSelector->hasValidSelection();
186 case QgsCrsSelectionWidget::CrsType::Custom:
187 return mCrsDefinitionWidget->crs().isValid();
195 return projectionSelector->filters();
200 projectionSelector->setFilters(
filters );
205 if ( !mComboCrsType->currentData().isValid() )
209 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
211 case QgsCrsSelectionWidget::CrsType::Predefined:
212 return projectionSelector->crs();
213 case QgsCrsSelectionWidget::CrsType::Custom:
214 return mCrsDefinitionWidget->crs();
225 if ( mShowNoCrsOption )
226 mComboCrsType->setCurrentIndex( 0 );
228 mDeferredInvalidCrsSet =
true;
232 projectionSelector->setCrs(
crs );
233 mCrsDefinitionWidget->setCrs(
crs );
236 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Custom ) ) );
237 mStackedWidget->setCurrentWidget( mPageCustom );
241 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Predefined ) ) );
242 mStackedWidget->setCurrentWidget( mPageDatabase );
253 projectionSelector->setOgcWmsCrsFilter( crsFilter );
264 : QDialog( parent, fl )
266 QVBoxLayout *vlayout =
new QVBoxLayout();
269 vlayout->addWidget( mCrsWidget, 1 );
271 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
272 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
273 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
274 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
276 vlayout->addWidget( mButtonBox );
278 setLayout( vlayout );
293 setMessage( tr(
"This layer appears to have no projection specification." )
295 + tr(
"By default, this layer will now have its projection set to that of the project, "
296 "but you may override this by selecting a different projection below." ) );
316 mRequireValidSelection =
true;
321 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
342 return mCrsWidget->
crs();
349 if ( mRequireValidSelection )
358void QgsProjectionSelectionDialog::showHelp()
360 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.
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.
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