25#include <QApplication>
26#include <QDialogButtonBox>
29#include "moc_qgsprojectionselectiondialog.cpp"
39 projectionSelector->setFilters(
filters );
44 mNotSetText = tr(
"No CRS (or unknown/non-Earth projection)" );
45 mLabelNoCrs->setText( tr(
"Use this option to treat all coordinates as Cartesian coordinates in an unknown reference system." ) );
47 mComboCrsType->addItem( tr(
"Predefined CRS" ),
static_cast<int>( CrsType::Predefined ) );
48 mComboCrsType->addItem( tr(
"Custom CRS" ),
static_cast<int>( CrsType::Custom ) );
50 mStackedWidget->setCurrentWidget( mPageDatabase );
51 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Predefined ) ) );
53 connect( mComboCrsType, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
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 );
91 mDeferredInvalidCrsSet =
false;
106 mSplitter->restoreState( settings.value( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ) ).toByteArray() );
112 settings.
setValue( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ), mSplitter->saveState() );
123 if ( mShowNoCrsOption == show )
127 mShowNoCrsOption = show;
128 if ( mShowNoCrsOption )
130 mComboCrsType->insertItem( 0, mNotSetText );
134 mComboCrsType->removeItem( 0 );
137 if ( show && mDeferredInvalidCrsSet )
139 mComboCrsType->setCurrentIndex( 0 );
144 if ( mDeferredInvalidCrsSet )
147 mDeferredInvalidCrsSet =
false;
154 return mShowNoCrsOption;
161 if ( mShowNoCrsOption )
163 mComboCrsType->setItemText( 0, mNotSetText );
166 mLabelNoCrs->setText( description.isEmpty() ? text : description );
171 if ( !mComboCrsType->currentData().isValid() )
173 else if ( mDeferredInvalidCrsSet )
177 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
179 case QgsCrsSelectionWidget::CrsType::Predefined:
180 return projectionSelector->hasValidSelection();
181 case QgsCrsSelectionWidget::CrsType::Custom:
182 return mCrsDefinitionWidget->crs().isValid();
190 return projectionSelector->filters();
195 projectionSelector->setFilters(
filters );
200 if ( !mComboCrsType->currentData().isValid() )
204 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
206 case QgsCrsSelectionWidget::CrsType::Predefined:
207 return projectionSelector->crs();
208 case QgsCrsSelectionWidget::CrsType::Custom:
209 return mCrsDefinitionWidget->crs();
218 if ( !
crs.isValid() )
220 if ( mShowNoCrsOption )
221 mComboCrsType->setCurrentIndex( 0 );
223 mDeferredInvalidCrsSet =
true;
227 projectionSelector->setCrs(
crs );
228 mCrsDefinitionWidget->setCrs(
crs );
229 if (
crs.isValid() &&
crs.authid().isEmpty() )
231 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Custom ) ) );
232 mStackedWidget->setCurrentWidget( mPageCustom );
236 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Predefined ) ) );
237 mStackedWidget->setCurrentWidget( mPageDatabase );
248 projectionSelector->setOgcWmsCrsFilter( crsFilter );
257 : QDialog( parent, fl )
259 QVBoxLayout *vlayout =
new QVBoxLayout();
262 vlayout->addWidget( mCrsWidget, 1 );
264 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
265 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
266 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
267 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
269 vlayout->addWidget( mButtonBox );
271 setLayout( vlayout );
281 mCrsWidget->setMessage( message );
286 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, "
287 "but you may override this by selecting a different projection below." ) );
292 mCrsWidget->setShowNoCrs( show );
297 return mCrsWidget->showNoCrs();
302 mCrsWidget->setNotSetText( text, description );
307 mRequireValidSelection =
true;
311 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
317 return mCrsWidget->hasValidSelection();
322 return mCrsWidget->filters();
327 mCrsWidget->setFilters(
filters );
332 return mCrsWidget->crs();
337 mCrsWidget->setCrs(
crs );
339 if ( mRequireValidSelection )
345 mCrsWidget->setOgcWmsCrsFilter( crsFilter );
348void QgsProjectionSelectionDialog::showHelp()
350 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...
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