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 );
92 mDeferredInvalidCrsSet =
false;
107 mSplitter->restoreState( settings.value( u
"Windows/ProjectionSelectorDialog/splitterState"_s ).toByteArray() );
113 settings.
setValue( u
"Windows/ProjectionSelectorDialog/splitterState"_s, mSplitter->saveState() );
124 if ( mShowNoCrsOption == show )
128 mShowNoCrsOption = show;
129 if ( mShowNoCrsOption )
131 mComboCrsType->insertItem( 0, mNotSetText );
135 mComboCrsType->removeItem( 0 );
138 if ( show && mDeferredInvalidCrsSet )
140 mComboCrsType->setCurrentIndex( 0 );
145 if ( mDeferredInvalidCrsSet )
148 mDeferredInvalidCrsSet =
false;
155 return mShowNoCrsOption;
162 if ( mShowNoCrsOption )
164 mComboCrsType->setItemText( 0, mNotSetText );
167 mLabelNoCrs->setText( description.isEmpty() ? text : description );
172 if ( !mComboCrsType->currentData().isValid() )
174 else if ( mDeferredInvalidCrsSet )
178 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
180 case QgsCrsSelectionWidget::CrsType::Predefined:
181 return projectionSelector->hasValidSelection();
182 case QgsCrsSelectionWidget::CrsType::Custom:
183 return mCrsDefinitionWidget->crs().isValid();
191 return projectionSelector->filters();
196 projectionSelector->setFilters(
filters );
201 if ( !mComboCrsType->currentData().isValid() )
205 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
207 case QgsCrsSelectionWidget::CrsType::Predefined:
208 return projectionSelector->crs();
209 case QgsCrsSelectionWidget::CrsType::Custom:
210 return mCrsDefinitionWidget->crs();
219 if ( !
crs.isValid() )
221 if ( mShowNoCrsOption )
222 mComboCrsType->setCurrentIndex( 0 );
224 mDeferredInvalidCrsSet =
true;
228 projectionSelector->setCrs(
crs );
229 mCrsDefinitionWidget->setCrs(
crs );
230 if (
crs.isValid() &&
crs.authid().isEmpty() )
232 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Custom ) ) );
233 mStackedWidget->setCurrentWidget( mPageCustom );
237 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Predefined ) ) );
238 mStackedWidget->setCurrentWidget( mPageDatabase );
249 projectionSelector->setOgcWmsCrsFilter( crsFilter );
258 : QDialog( parent, fl )
260 QVBoxLayout *vlayout =
new QVBoxLayout();
263 vlayout->addWidget( mCrsWidget, 1 );
265 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
266 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
267 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
268 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
270 vlayout->addWidget( mButtonBox );
272 setLayout( vlayout );
282 mCrsWidget->setMessage( message );
288 tr(
"This layer appears to have no projection specification." )
291 "By default, this layer will now have its projection set to that of the project, "
292 "but you may override this by selecting a different projection below."
299 mCrsWidget->setShowNoCrs( show );
304 return mCrsWidget->showNoCrs();
309 mCrsWidget->setNotSetText( text, description );
314 mRequireValidSelection =
true;
322 return mCrsWidget->hasValidSelection();
327 return mCrsWidget->filters();
332 mCrsWidget->setFilters(
filters );
337 return mCrsWidget->crs();
342 mCrsWidget->setCrs(
crs );
344 if ( mRequireValidSelection )
350 mCrsWidget->setOgcWmsCrsFilter( crsFilter );
353void QgsProjectionSelectionDialog::showHelp()
355 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