22#include "moc_qgsprojectionselectiondialog.cpp"
24#include <QDialogButtonBox>
25#include <QApplication>
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, [ = ](
int )
55 if ( !mComboCrsType->currentData().isValid() )
56 mStackedWidget->setCurrentWidget( mPageNoCrs );
59 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
61 case QgsCrsSelectionWidget::CrsType::Predefined:
62 mStackedWidget->setCurrentWidget( mPageDatabase );
64 case QgsCrsSelectionWidget::CrsType::Custom:
65 mStackedWidget->setCurrentWidget( mPageCustom );
95 mDeferredInvalidCrsSet =
false;
103 if ( !mBlockSignals )
111 mSplitter->restoreState( settings.value( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ) ).toByteArray() );
117 settings.
setValue( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ), mSplitter->saveState() );
129 if ( mShowNoCrsOption == show )
133 mShowNoCrsOption = show;
134 if ( mShowNoCrsOption )
136 mComboCrsType->insertItem( 0, mNotSetText );
140 mComboCrsType->removeItem( 0 );
143 if ( show && mDeferredInvalidCrsSet )
145 mComboCrsType->setCurrentIndex( 0 );
150 if ( mDeferredInvalidCrsSet )
153 mDeferredInvalidCrsSet =
false;
160 return mShowNoCrsOption;
167 if ( mShowNoCrsOption )
169 mComboCrsType->setItemText( 0, mNotSetText );
172 mLabelNoCrs->setText( description.isEmpty() ? text : description );
177 if ( !mComboCrsType->currentData().isValid() )
179 else if ( mDeferredInvalidCrsSet )
183 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
185 case QgsCrsSelectionWidget::CrsType::Predefined:
186 return projectionSelector->hasValidSelection();
187 case QgsCrsSelectionWidget::CrsType::Custom:
188 return mCrsDefinitionWidget->crs().isValid();
196 return projectionSelector->filters();
201 projectionSelector->setFilters(
filters );
206 if ( !mComboCrsType->currentData().isValid() )
210 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
212 case QgsCrsSelectionWidget::CrsType::Predefined:
213 return projectionSelector->crs();
214 case QgsCrsSelectionWidget::CrsType::Custom:
215 return mCrsDefinitionWidget->crs();
226 if ( mShowNoCrsOption )
227 mComboCrsType->setCurrentIndex( 0 );
229 mDeferredInvalidCrsSet =
true;
233 projectionSelector->setCrs(
crs );
234 mCrsDefinitionWidget->setCrs(
crs );
237 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Custom ) ) );
238 mStackedWidget->setCurrentWidget( mPageCustom );
242 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Predefined ) ) );
243 mStackedWidget->setCurrentWidget( mPageDatabase );
254 projectionSelector->setOgcWmsCrsFilter( crsFilter );
265 : QDialog( parent, fl )
267 QVBoxLayout *vlayout =
new QVBoxLayout();
270 vlayout->addWidget( mCrsWidget, 1 );
272 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
273 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
274 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
275 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
277 vlayout->addWidget( mButtonBox );
279 setLayout( vlayout );
294 setMessage( tr(
"This layer appears to have no projection specification." )
296 + tr(
"By default, this layer will now have its projection set to that of the project, "
297 "but you may override this by selecting a different projection below." ) );
317 mRequireValidSelection =
true;
322 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
343 return mCrsWidget->
crs();
350 if ( mRequireValidSelection )
359void QgsProjectionSelectionDialog::showHelp()
361 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