29#include <QApplication>
30#include <QDialogButtonBox>
34#include "moc_qgsprojectionselectiondialog.cpp"
36using namespace Qt::StringLiterals;
46 projectionSelector->setFilters(
filters );
51 mNotSetText = tr(
"No CRS (or unknown)" );
52 mLabelNoCrs->setText( tr(
"Use this option to treat all coordinates as Cartesian coordinates in an unknown reference system." ) );
54 mComboCrsType->addItem( tr(
"Predefined CRS" ),
static_cast<int>( CrsType::Predefined ) );
55 mComboCrsType->addItem( tr(
"Custom CRS" ),
static_cast<int>( CrsType::Custom ) );
56 mComboCrsType->addItem( tr(
"Topocentric CRS" ),
static_cast<int>( CrsType::Topocentric ) );
59 mTopocentricBaseSelector->setAllowTopocentricCrs(
false );
61 mStackedWidget->setCurrentWidget( mPageDatabase );
62 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Predefined ) ) );
64 connect( mComboCrsType, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int ) {
65 if ( !mComboCrsType->currentData().isValid() )
66 mStackedWidget->setCurrentWidget( mPageNoCrs );
69 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
71 case QgsCrsSelectionWidget::CrsType::Predefined:
72 mStackedWidget->setCurrentWidget( mPageDatabase );
74 case QgsCrsSelectionWidget::CrsType::Custom:
75 mStackedWidget->setCurrentWidget( mPageCustom );
77 case QgsCrsSelectionWidget::CrsType::Topocentric:
78 mStackedWidget->setCurrentWidget( mPageTopocentric );
81 const QgsRectangle b = mTopocentricBaseSelector->crs().bounds();
86 mSpinBoxTopoLat->clear();
87 mSpinBoxTopoLon->clear();
104 if ( !mBlockSignals )
112 if ( !mBlockSignals )
114 mDeferredInvalidCrsSet =
false;
121 if ( !mBlockSignals )
135 if ( !mBlockSignals )
138 mSpinBoxTopoLat->clear();
139 mSpinBoxTopoLon->clear();
146 connect( mSpinBoxTopoLat, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, [
this](
double ) {
147 if ( !mBlockSignals )
151 connect( mSpinBoxTopoLon, qOverload<double>( &QDoubleSpinBox::valueChanged ),
this, [
this](
double ) {
152 if ( !mBlockSignals )
157 mSplitter->restoreState( settings.value( u
"Windows/ProjectionSelectorDialog/splitterState"_s ).toByteArray() );
163 settings.
setValue( u
"Windows/ProjectionSelectorDialog/splitterState"_s, mSplitter->saveState() );
174 if ( mShowNoCrsOption == show )
178 mShowNoCrsOption = show;
179 if ( mShowNoCrsOption )
181 mComboCrsType->insertItem( 0, mNotSetText );
185 mComboCrsType->removeItem( 0 );
188 if ( show && mDeferredInvalidCrsSet )
190 mComboCrsType->setCurrentIndex( 0 );
195 if ( mDeferredInvalidCrsSet )
198 mDeferredInvalidCrsSet =
false;
205 return mShowNoCrsOption;
212 if ( mShowNoCrsOption )
214 mComboCrsType->setItemText( 0, mNotSetText );
217 mLabelNoCrs->setText( description.isEmpty() ? text : description );
222 if ( !mComboCrsType->currentData().isValid() )
224 else if ( mDeferredInvalidCrsSet )
228 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
230 case QgsCrsSelectionWidget::CrsType::Predefined:
231 return projectionSelector->hasValidSelection();
232 case QgsCrsSelectionWidget::CrsType::Custom:
233 return mCrsDefinitionWidget->crs().isValid();
234 case QgsCrsSelectionWidget::CrsType::Topocentric:
246 return projectionSelector->filters();
251 projectionSelector->setFilters(
filters );
256 if ( allow == mAllowTopocentricCrs )
258 mAllowTopocentricCrs = allow;
260 const int idx = mComboCrsType->findData(
static_cast<int>( CrsType::Topocentric ) );
261 if ( !allow && idx >= 0 )
262 mComboCrsType->removeItem( idx );
263 else if ( allow && idx < 0 )
264 mComboCrsType->addItem( tr(
"Topocentric CRS" ),
static_cast<int>( CrsType::Topocentric ) );
269 if ( !mComboCrsType->currentData().isValid() )
273 switch (
static_cast<CrsType
>( mComboCrsType->currentData().toInt() ) )
275 case QgsCrsSelectionWidget::CrsType::Predefined:
276 return projectionSelector->crs();
277 case QgsCrsSelectionWidget::CrsType::Custom:
278 return mCrsDefinitionWidget->crs();
279 case QgsCrsSelectionWidget::CrsType::Topocentric:
282 return base.
toTopocentricCrs( mSpinBoxTopoLat->value(), mSpinBoxTopoLon->value() );
292 if ( !
crs.isValid() )
294 if ( mShowNoCrsOption )
295 mComboCrsType->setCurrentIndex( 0 );
297 mDeferredInvalidCrsSet =
true;
301 double topoLat = 0.0, topoLon = 0.0;
302 if (
crs.topocentricOrigin( topoLat, topoLon ) )
305 mTopocentricBaseSelector->setCrs( baseCrs );
313 mSpinBoxTopoLat->clear();
314 mSpinBoxTopoLon->clear();
315 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Topocentric ) ) );
316 mStackedWidget->setCurrentWidget( mPageTopocentric );
318 else if (
crs.authid().isEmpty() )
320 projectionSelector->setCrs(
crs );
321 mCrsDefinitionWidget->setCrs(
crs );
322 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Custom ) ) );
323 mStackedWidget->setCurrentWidget( mPageCustom );
327 projectionSelector->setCrs(
crs );
328 mCrsDefinitionWidget->setCrs(
crs );
329 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast<int>( CrsType::Predefined ) ) );
330 mStackedWidget->setCurrentWidget( mPageDatabase );
341 projectionSelector->setOgcWmsCrsFilter( crsFilter );
346 projectionSelector->setPreviewRect( rect );
355 : QDialog( parent, fl )
357 QVBoxLayout *vlayout =
new QVBoxLayout();
360 vlayout->addWidget( mCrsWidget, 1 );
362 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
363 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
364 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
365 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
367 vlayout->addWidget( mButtonBox );
369 setLayout( vlayout );
379 mCrsWidget->setMessage( message );
385 tr(
"This layer appears to have no projection specification." )
388 "By default, this layer will now have its projection set to that of the project, "
389 "but you may override this by selecting a different projection below."
396 mCrsWidget->setShowNoCrs( show );
401 return mCrsWidget->showNoCrs();
406 mCrsWidget->setNotSetText( text, description );
411 mRequireValidSelection =
true;
419 return mCrsWidget->hasValidSelection();
424 return mCrsWidget->filters();
429 mCrsWidget->setFilters(
filters );
434 mCrsWidget->setAllowTopocentricCrs( allow );
439 return mCrsWidget->crs();
444 mCrsWidget->setCrs(
crs );
446 if ( mRequireValidSelection )
452 mCrsWidget->setOgcWmsCrsFilter( crsFilter );
455void QgsProjectionSelectionDialog::showHelp()
457 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...
@ FilterTopocentricCompatible
Include all CRS types compatible with topocentric CRS (all except projected CRS).
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QgsRectangle bounds() const
Returns the approximate bounds for the region the CRS is usable within.
QgsCoordinateReferenceSystem toTopocentricCrs(double latitude, double longitude) const
Constructs a topocentric CRS derived from this CRS with origin at latitude, longitude in decimal degr...
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.
void setAllowTopocentricCrs(bool allow)
Sets whether the topocentric CRS type option is shown in the dialog.
A rectangle specified with double values.
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