23 #include <QDialogButtonBox>
24 #include <QApplication>
26 #include <QPushButton>
40 mNotSetText = tr(
"No CRS (or unknown/non-Earth projection)" );
41 mLabelNoCrs->setText( tr(
"Use this option to treat all coordinates as Cartesian coordinates in an unknown reference system." ) );
43 mComboCrsType->addItem( tr(
"Predefined CRS" ),
static_cast< int >( CrsType::Predefined ) );
44 mComboCrsType->addItem( tr(
"Custom CRS" ),
static_cast< int >( CrsType::Custom ) );
46 mStackedWidget->setCurrentWidget( mPageDatabase );
47 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int >( CrsType::Predefined ) ) );
49 connect( mComboCrsType, qOverload< int >( &QComboBox::currentIndexChanged ),
this, [ = ](
int )
51 if ( !mComboCrsType->currentData().isValid() )
52 mStackedWidget->setCurrentWidget( mPageNoCrs );
55 switch ( static_cast< CrsType >( mComboCrsType->currentData().toInt() ) )
57 case QgsCrsSelectionWidget::CrsType::Predefined:
58 mStackedWidget->setCurrentWidget( mPageDatabase );
60 case QgsCrsSelectionWidget::CrsType::Custom:
61 mStackedWidget->setCurrentWidget( mPageCustom );
75 emit crsDoubleClicked( projectionSelector->crs() );
83 emit hasValidSelectionChanged( hasValidSelection() );
92 emit hasValidSelectionChanged( hasValidSelection() );
101 emit hasValidSelectionChanged( hasValidSelection() );
106 mSplitter->restoreState( settings.value( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ) ).toByteArray() );
112 settings.
setValue( QStringLiteral(
"Windows/ProjectionSelectorDialog/splitterState" ), 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 if ( !mComboCrsType->currentData().isValid() )
195 switch (
static_cast< CrsType
>( mComboCrsType->currentData().toInt() ) )
197 case QgsCrsSelectionWidget::CrsType::Predefined:
198 return projectionSelector->crs();
199 case QgsCrsSelectionWidget::CrsType::Custom:
200 return mCrsDefinitionWidget->crs();
211 if ( mShowNoCrsOption )
212 mComboCrsType->setCurrentIndex( 0 );
214 mDeferredInvalidCrsSet =
true;
218 projectionSelector->setCrs(
crs );
219 mCrsDefinitionWidget->setCrs(
crs );
222 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Custom ) ) );
223 mStackedWidget->setCurrentWidget( mPageCustom );
227 mComboCrsType->setCurrentIndex( mComboCrsType->findData(
static_cast< int>( CrsType::Predefined ) ) );
228 mStackedWidget->setCurrentWidget( mPageDatabase );
239 projectionSelector->setOgcWmsCrsFilter( crsFilter );
250 : QDialog( parent, fl )
252 QVBoxLayout *vlayout =
new QVBoxLayout();
255 vlayout->addWidget( mCrsWidget, 1 );
257 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
258 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QgsProjectionSelectionDialog::accept );
259 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProjectionSelectionDialog::reject );
260 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProjectionSelectionDialog::showHelp );
262 vlayout->addWidget( mButtonBox );
264 setLayout( vlayout );
279 setMessage( tr(
"This layer appears to have no projection specification." )
281 + tr(
"By default, this layer will now have its projection set to that of the project, "
282 "but you may override this by selecting a different projection below." ) );
302 mRequireValidSelection =
true;
307 mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
318 return mCrsWidget->
crs();
325 if ( mRequireValidSelection )
334 void QgsProjectionSelectionDialog::showHelp()
336 QgsHelp::openHelp( QStringLiteral(
"working_with_projections/working_with_projections.html" ) );