diff --git a/doc/api_break.dox b/doc/api_break.dox index 065fac90b50..96f3d251dc0 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -257,6 +257,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat - QgsFormAnnotationItem. Use QgsFormAnnotation instead. - QgsHtmlAnnotationItem. Use QgsHtmlAnnotation instead. - QgsHttpTransaction. This class was outdated and code should be ported to native Qt or Python implementations. +- QgsGenericProjectionSelector. Use QgsProjectionSelectionTreeWidget instead. - QgsLabel and QgsLabelAttributes. Replaced by labeling based on PAL library, see QgsLabelingEngine. - QgsLabelingEngineInterface. Replaced by QgsLabelingEngine. - QgsLegendInterface was removed. It was replaced by layer tree API (QgsLayerTreeNode class and others). @@ -276,6 +277,7 @@ should now call QgsCoordinateReferenceSystem::invalidateCache() and QgsCoordinat - QgsRendererV2DataDefinedMenus was removed. Use QgsPropertyOverrideButton instead. - QgsSizeScaleWidget. Use QgsPropertyAssistantWidget instead. - QgsLegacyHelpers. +- QgsProjectionSelector. Use QgsProjectionSelectionDialog instead. - QgsProviderCountCalcEvent and QgsProviderExtentCalcEvent. These classes were unused in QGIS core and unmaintained. - QgsWebviewWidgetWrapper was removed. Use QgsExternalResourceWidgetWrapper instead. - QgsEditorWidgetConfig was removed. Use QVariantMap instead. diff --git a/python/gui/gui.sip b/python/gui/gui.sip index 98cb3be40e3..53ecc85b3aa 100644 --- a/python/gui/gui.sip +++ b/python/gui/gui.sip @@ -81,7 +81,6 @@ %Include qgsfloatingwidget.sip %Include qgsfocuswatcher.sip %Include qgsformannotation.sip -%Include qgsgenericprojectionselector.sip %Include qgsgeometryrubberband.sip %Include qgsgradientcolorrampdialog.sip %Include qgsgradientstopeditor.sip @@ -138,8 +137,9 @@ %Include qgspluginmanagerinterface.sip %Include qgspresetcolorrampdialog.sip %Include qgsprevieweffect.sip +%Include qgsprojectionselectiondialog.sip +%Include qgsprojectionselectiontreewidget.sip %Include qgsprojectionselectionwidget.sip -%Include qgsprojectionselector.sip %Include qgspropertyassistantwidget.sip %Include qgspropertyoverridebutton.sip %Include qgsquerybuilder.sip diff --git a/python/gui/qgsgenericprojectionselector.sip b/python/gui/qgsgenericprojectionselector.sip deleted file mode 100644 index 953177ef3e9..00000000000 --- a/python/gui/qgsgenericprojectionselector.sip +++ /dev/null @@ -1,64 +0,0 @@ - -/** - * \ingroup gui - * A generic dialog to prompt the user for a Coordinate Reference System. - * - * Typically you will use this when you want to prompt the user for - * a coordinate system identifier e.g. from a plugin you might do this - * to get an epsg code: - * \code - * QgsGenericProjectionSelector mySelector( mQgisIface->mainWindow() ); - * mySelector.setSelectedEpsg( mEpsgId ); - * if ( mySelector.exec() ) - * { - * mEpsgId = mySelector.selectedEpsg(); - * } - * \endcode - * - * If you wish to embed the projection selector into an existing dialog - * the you probably want to look at QgsProjectionSelector rather. - */ -class QgsGenericProjectionSelector : QDialog //, private Ui::QgsGenericProjectionSelectorBase -{ -%TypeHeaderCode -#include -%End - - public: - /** - * Constructor - */ - QgsGenericProjectionSelector( QWidget *parent /TransferThis/ = 0, - const Qt::WindowFlags& fl = QgisGui::ModalDialogFlags ); - - //! Destructor - ~QgsGenericProjectionSelector(); - - public slots: - /** If no parameter is passed, the message will be a generic - * 'define the CRS for this layer'. - */ - void setMessage( QString message = "" ); - long selectedCrsId(); - QString selectedAuthId(); - - void setSelectedCrsName( const QString& name ); - void setSelectedCrsId( long theID ); - void setSelectedAuthId( const QString& authId ); - - void on_mButtonBox_helpRequested(); - - /** - * \brief filters this dialog by the given CRSs - * - * Sets this dialog to filter the available projections to those listed - * by the given Coordinate Reference Systems. - * - * \param crsFilter a list of OGC Coordinate Reference Systems to filter the - * list of projections by. This is useful in (e.g.) WMS situations - * where you just want to offer what the WMS server can support. - * - * \warning This function's behavior is undefined if it is called after the dialog is shown. - */ - void setOgcWmsCrsFilter( const QSet& crsFilter ); -}; diff --git a/python/gui/qgsprojectionselectiondialog.sip b/python/gui/qgsprojectionselectiondialog.sip new file mode 100644 index 00000000000..bcaaf78768a --- /dev/null +++ b/python/gui/qgsprojectionselectiondialog.sip @@ -0,0 +1,39 @@ +class QgsProjectionSelectionDialog : QDialog //, private Ui::QgsGenericProjectionSelectorBase +{ +%TypeHeaderCode +#include +%End + + public: + /** + * Constructor + */ + QgsProjectionSelectionDialog( QWidget *parent /TransferThis/ = 0, + const Qt::WindowFlags& fl = QgisGui::ModalDialogFlags ); + + //! Destructor + ~QgsProjectionSelectionDialog(); + + QgsCoordinateReferenceSystem crs() const; + + void setMessage( const QString& message ); + + public slots: + + + void setCrs( const QgsCoordinateReferenceSystem& crs ); + + /** + * \brief filters this dialog by the given CRSs + * + * Sets this dialog to filter the available projections to those listed + * by the given Coordinate Reference Systems. + * + * \param crsFilter a list of OGC Coordinate Reference Systems to filter the + * list of projections by. This is useful in (e.g.) WMS situations + * where you just want to offer what the WMS server can support. + * + * \warning This function's behavior is undefined if it is called after the dialog is shown. + */ + void setOgcWmsCrsFilter( const QSet& crsFilter ); +}; diff --git a/python/gui/qgsprojectionselectiontreewidget.sip b/python/gui/qgsprojectionselectiontreewidget.sip new file mode 100644 index 00000000000..e2a11bdf885 --- /dev/null +++ b/python/gui/qgsprojectionselectiontreewidget.sip @@ -0,0 +1,31 @@ +class QgsProjectionSelectionTreeWidget : QWidget +{ +%TypeHeaderCode +#include +%End + + public: + QgsProjectionSelectionTreeWidget( QWidget* parent /TransferThis/ ); + + ~QgsProjectionSelectionTreeWidget(); + + QgsCoordinateReferenceSystem crs() const; + + public slots: + + void setCrs( const QgsCoordinateReferenceSystem& crs ); + void setOgcWmsCrsFilter( const QSet& crsFilter ); + void pushProjectionToFront(); + + signals: + + void crsSelected(); + void initialized(); + void projectionDoubleClicked(); + + protected: + void showEvent( QShowEvent * event ); + + void resizeEvent( QResizeEvent * event ); +}; + diff --git a/python/gui/qgsprojectionselectionwidget.sip b/python/gui/qgsprojectionselectionwidget.sip index 8af369d526f..c556bcd1e7c 100644 --- a/python/gui/qgsprojectionselectionwidget.sip +++ b/python/gui/qgsprojectionselectionwidget.sip @@ -30,7 +30,7 @@ class QgsProjectionSelectionWidget : QWidget * Can be used to modify how the projection selector dialog behaves. * @returns projection selector dialog */ - QgsGenericProjectionSelector* dialog(); + QgsProjectionSelectionDialog* dialog(); /** Returns the currently selected CRS for the widget * @returns current CRS diff --git a/python/gui/qgsprojectionselector.sip b/python/gui/qgsprojectionselector.sip deleted file mode 100644 index 72adf4bceb2..00000000000 --- a/python/gui/qgsprojectionselector.sip +++ /dev/null @@ -1,111 +0,0 @@ - - - -/** - @author Tim Sutton - */ -class QgsProjectionSelector : QWidget -{ -%TypeHeaderCode -#include -%End - - public: - QgsProjectionSelector( QWidget* parent /TransferThis/, const char *name = "", const Qt::WindowFlags& fl = 0 ); - - ~QgsProjectionSelector(); - - /** - * \brief Populate the proj tree view with user defined projection names... - * - * \param crsFilter a list of OGC Coordinate Reference Systems to filter the - * list of projections by. This is useful in (e.g.) WMS situations - * where you just want to offer what the WMS server can support. - * - * \todo Should this be public? - */ - void loadUserCrsList( QSet *crsFilter = 0 ); - - /** - * \brief Populate the proj tree view with system projection names... - * - * \param crsFilter a list of OGC Coordinate Reference Systems to filter the - * list of projections by. This is useful in (e.g.) WMS situations - * where you just want to offer what the WMS server can support. - * - * \todo Should this be public? - */ - void loadCrsList( QSet *crsFilter = 0 ); - - /*! - * \brief Make the string safe for use in SQL statements. - * This involves escaping single quotes, double quotes, backslashes, - * and optionally, percentage symbols. Percentage symbols are used - * as wildcards sometimes and so when using the string as part of the - * LIKE phrase of a select statement, should be escaped. - * \arg const QString in The input string to make safe. - * \return The string made safe for SQL statements. - */ - const QString sqlSafeString( const QString& theSQL ); - - //! Gets the current authority-style projection identifier - QString selectedAuthId(); - - public slots: - void setSelectedCrsName( const QString& theCRSName ); - - QString selectedName(); - - void setSelectedCrsId( long theCRSID ); - - void setSelectedAuthId( const QString& authId ); - - QString selectedProj4String(); - - //! Gets the current PostGIS-style projection identifier - long selectedPostgresSrId(); - - //! Gets the current QGIS projection identfier - long selectedCrsId(); - - /** - * \brief filters this widget by the given CRSs - * - * Sets this widget to filter the available projections to those listed - * by the given Coordinate Reference Systems. - * - * \param crsFilter a list of OGC Coordinate Reference Systems to filter the - * list of projections by. This is useful in (e.g.) WMS situations - * where you just want to offer what the WMS server can support. - * - * \warning This function's behavior is undefined if it is called after the widget is shown. - */ - void setOgcWmsCrsFilter( const QSet& crsFilter ); - void on_lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev ); - void on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev ); - void on_cbxHideDeprecated_stateChanged(); - void on_leSearch_textChanged( const QString & ); - - //! mark selected projection for push to front - void pushProjectionToFront(); - - protected: - /** Used to ensure the projection list view is actually populated */ - void showEvent( QShowEvent * event ); - - /** Used to manage column sizes */ - void resizeEvent( QResizeEvent * event ); - - signals: - void sridSelected( const QString& theSRID ); - //! Refresh any listening canvases - void refresh(); - //! Let listeners know if find has focus so they can adjust the default button - void searchBoxHasFocus( bool ); - //! Notify others that the widget is now fully initialized, including deferred selection of projection - //! @note added in 2.4 - void initialized(); - //! Apply projection on double click - //! @note added in 2.14 - void projectionDoubleClicked(); -}; diff --git a/python/plugins/processing/gui/wrappers.py b/python/plugins/processing/gui/wrappers.py index 3a21caad0b6..773e236b34f 100644 --- a/python/plugins/processing/gui/wrappers.py +++ b/python/plugins/processing/gui/wrappers.py @@ -56,7 +56,7 @@ from qgis.gui import ( QgsFieldComboBox, QgsFieldExpressionWidget, QgsFieldProxyModel, - QgsGenericProjectionSelector, + QgsProjectionSelectionDialog, QgsMapLayerComboBox, QgsProjectionSelectionWidget, ) @@ -311,13 +311,13 @@ class CrsWidgetWrapper(WidgetWrapper): return widget def selectProjection(self): - dialog = QgsGenericProjectionSelector(self.widget) + dialog = QgsProjectionSelectionDialog(self.widget) current_crs = QgsCoordinateReferenceSystem(self.combo.currentText()) if current_crs.isValid(): - dialog.setSelectedCrsId(current_crs.srsid()) + dialog.setCrs(current_crs) if dialog.exec_(): - self.setValue(dialog.selectedAuthId()) + self.setValue(dialog.crs().authid()) def setValue(self, value): if self.dialogType == DIALOG_MODELER: diff --git a/src/app/composer/qgscomposermapgridwidget.cpp b/src/app/composer/qgscomposermapgridwidget.cpp index b7450e2af69..3292491e4f9 100644 --- a/src/app/composer/qgscomposermapgridwidget.cpp +++ b/src/app/composer/qgscomposermapgridwidget.cpp @@ -22,7 +22,7 @@ #include "qgsproject.h" #include "qgssymbollayerutils.h" #include "qgsstyle.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgscomposition.h" #include "qgsmapsettings.h" #include "qgsexpressionbuilderdialog.h" @@ -1033,18 +1033,16 @@ void QgsComposerMapGridWidget::on_mMapGridCRSButton_clicked() return; } - QgsGenericProjectionSelector crsDialog( this ); + QgsProjectionSelectionDialog crsDialog( this ); QgsCoordinateReferenceSystem crs = mComposerMapGrid->crs(); - QString currentAuthId = crs.isValid() ? crs.authid() : mComposerMap->crs().authid(); - crsDialog.setSelectedAuthId( currentAuthId ); + crsDialog.setCrs( crs.isValid() ? crs : mComposerMap->crs() ); if ( crsDialog.exec() == QDialog::Accepted ) { mComposerMap->beginCommand( tr( "Grid CRS changed" ) ); - QString selectedAuthId = crsDialog.selectedAuthId(); - mComposerMapGrid->setCrs( QgsCoordinateReferenceSystem( selectedAuthId ) ); + mComposerMapGrid->setCrs( crsDialog.crs() ); mComposerMap->updateBoundingRect(); - mMapGridCRSButton->setText( selectedAuthId ); + mMapGridCRSButton->setText( crsDialog.crs().authid() ); mComposerMap->endCommand(); } } diff --git a/src/app/dwg/qgsdwgimportdialog.cpp b/src/app/dwg/qgsdwgimportdialog.cpp index 08f7dd02e46..7906de70f80 100644 --- a/src/app/dwg/qgsdwgimportdialog.cpp +++ b/src/app/dwg/qgsdwgimportdialog.cpp @@ -38,7 +38,7 @@ #include "qgslinesymbollayer.h" #include "qgspallabeling.h" #include "qgsmapcanvas.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgsmessagelog.h" #include "qgslogger.h" #include "qgsproperty.h" diff --git a/src/app/ogr/qgsvectorlayersaveasdialog.cpp b/src/app/ogr/qgsvectorlayersaveasdialog.cpp index b3ea20a9905..23665f6bc58 100644 --- a/src/app/ogr/qgsvectorlayersaveasdialog.cpp +++ b/src/app/ogr/qgsvectorlayersaveasdialog.cpp @@ -17,7 +17,7 @@ ***************************************************************************/ #include "qgslogger.h" #include "qgsvectorlayersaveasdialog.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgsvectordataprovider.h" #include "qgscoordinatereferencesystem.h" #include "qgseditorwidgetfactory.h" diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 26d17e846e9..c24ad7ab274 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -167,7 +167,7 @@ #include "qgsfieldformatterregistry.h" #include "qgsformannotation.h" #include "qgshtmlannotation.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgsgpsinformationwidget.h" #include "qgsguivectorlayertools.h" #include "qgslabelingwidget.h" @@ -525,7 +525,7 @@ void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs ) // @note this class is not a descendent of QWidget so we can't pass // it in the ctor of the layer projection selector - QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector(); + QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog(); mySelector->setMessage( srs.validationHint() ); //shows a generic message, if not specified if ( sAuthId.isNull() ) sAuthId = QgisApp::instance()->mapCanvas()->mapSettings().destinationCrs().authid(); @@ -533,7 +533,7 @@ void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs ) QgsCoordinateReferenceSystem defaultCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( sAuthId ); if ( defaultCrs.isValid() ) { - mySelector->setSelectedCrsId( defaultCrs.srsid() ); + mySelector->setCrs( defaultCrs ); } bool waiting = QApplication::overrideCursor() && QApplication::overrideCursor()->shape() == Qt::WaitCursor; @@ -542,9 +542,9 @@ void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs ) if ( mySelector->exec() ) { - QgsDebugMsg( "Layer srs set from dialog: " + QString::number( mySelector->selectedCrsId() ) ); - sAuthId = mySelector->selectedAuthId(); - srs.createFromOgcWmsCrs( mySelector->selectedAuthId() ); + QgsDebugMsg( "Layer srs set from dialog: " + QString::number( mySelector->crs().srsid() ) ); + srs = mySelector->crs(); + sAuthId = srs.authid(); } if ( waiting ) @@ -8740,16 +8740,16 @@ void QgisApp::setLayerCrs() return; } - QgsGenericProjectionSelector mySelector( this ); - mySelector.setSelectedCrsId( mLayerTreeView->currentLayer()->crs().srsid() ); - mySelector.setMessage(); + QgsProjectionSelectionDialog mySelector( this ); + mySelector.setCrs( mLayerTreeView->currentLayer()->crs() ); + mySelector.setMessage( QString() ); if ( !mySelector.exec() ) { QApplication::restoreOverrideCursor(); return; } - QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromSrsId( mySelector.selectedCrsId() ); + QgsCoordinateReferenceSystem crs = mySelector.crs(); Q_FOREACH ( QgsLayerTreeNode* node, mLayerTreeView->selectedNodes() ) { @@ -8897,15 +8897,15 @@ void QgisApp::legendGroupSetCrs() if ( !currentGroup ) return; - QgsGenericProjectionSelector mySelector( this ); - mySelector.setMessage(); + QgsProjectionSelectionDialog mySelector( this ); + mySelector.setMessage( QString() ); if ( !mySelector.exec() ) { QApplication::restoreOverrideCursor(); return; } - QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromSrsId( mySelector.selectedCrsId() ); + QgsCoordinateReferenceSystem crs = mySelector.crs(); Q_FOREACH ( QgsLayerTreeLayer* nodeLayer, currentGroup->findLayers() ) { if ( nodeLayer->layer() ) diff --git a/src/app/qgscustomprojectiondialog.cpp b/src/app/qgscustomprojectiondialog.cpp index 6c2a046a702..81ed8d72b82 100644 --- a/src/app/qgscustomprojectiondialog.cpp +++ b/src/app/qgscustomprojectiondialog.cpp @@ -23,7 +23,7 @@ #include "qgisapp.h" //<--theme icons #include "qgsapplication.h" #include "qgslogger.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgscrscache.h" //qt includes @@ -369,12 +369,10 @@ void QgsCustomProjectionDialog::on_leNameList_currentItemChanged( QTreeWidgetIte void QgsCustomProjectionDialog::on_pbnCopyCRS_clicked() { - QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this ); + QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this ); if ( mySelector->exec() ) { - QgsCoordinateReferenceSystem srs; - QString id = mySelector->selectedAuthId(); - srs.createFromOgcWmsCrs( id ); + QgsCoordinateReferenceSystem srs = mySelector->crs(); if ( leNameList->topLevelItemCount() == 0 ) { on_pbnAdd_clicked(); diff --git a/src/app/qgsdxfexportdialog.cpp b/src/app/qgsdxfexportdialog.cpp index 66e0fe0eb3c..7de0b77eaa5 100644 --- a/src/app/qgsdxfexportdialog.cpp +++ b/src/app/qgsdxfexportdialog.cpp @@ -28,7 +28,7 @@ #include "qgslayertreemapcanvasbridge.h" #include "qgsmapthemecollection.h" #include "qgsmapcanvas.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgscrscache.h" #include diff --git a/src/app/qgsnewspatialitelayerdialog.cpp b/src/app/qgsnewspatialitelayerdialog.cpp index 3935c336775..0563f2419da 100644 --- a/src/app/qgsnewspatialitelayerdialog.cpp +++ b/src/app/qgsnewspatialitelayerdialog.cpp @@ -27,7 +27,7 @@ #include "qgsvectorlayer.h" #include "qgsproject.h" #include "qgscoordinatereferencesystem.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgsslconnect.h" #include "qgslogger.h" @@ -236,14 +236,14 @@ void QgsNewSpatialiteLayerDialog::on_pbnFindSRID_clicked() } // prepare projection selector - QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this ); - mySelector->setMessage(); + QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this ); + mySelector->setMessage( QString() ); mySelector->setOgcWmsCrsFilter( myCRSs ); - mySelector->setSelectedAuthId( mCrsId ); + mySelector->setCrs( QgsCoordinateReferenceSystem::fromOgcWmsCrs( mCrsId ) ); if ( mySelector->exec() ) { - QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mySelector->selectedAuthId() ); + QgsCoordinateReferenceSystem srs = mySelector->crs(); QString crsId = srs.authid(); if ( crsId != mCrsId ) { diff --git a/src/app/qgsoptions.cpp b/src/app/qgsoptions.cpp index 0cb96986d90..db8043723d9 100644 --- a/src/app/qgsoptions.cpp +++ b/src/app/qgsoptions.cpp @@ -23,7 +23,7 @@ #include "qgisappstylesheet.h" #include "qgshighlight.h" #include "qgsmapcanvas.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgscoordinatereferencesystem.h" #include "qgstolerance.h" #include "qgsscaleutils.h" diff --git a/src/app/qgsprojectproperties.cpp b/src/app/qgsprojectproperties.cpp index 9f5c294129e..3099c49625b 100644 --- a/src/app/qgsprojectproperties.cpp +++ b/src/app/qgsprojectproperties.cpp @@ -34,7 +34,7 @@ #include "qgsvectorlayer.h" #include "qgsvectordataprovider.h" #include "qgsscaleutils.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgsstyle.h" #include "qgssymbol.h" #include "qgsstylemanagerdialog.h" @@ -106,8 +106,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa connect( buttonBox->button( QDialogButtonBox::Apply ), SIGNAL( clicked() ), this, SLOT( apply() ) ); connect( this, SIGNAL( accepted() ), this, SLOT( apply() ) ); - connect( projectionSelector, SIGNAL( sridSelected( QString ) ), this, SLOT( srIdUpdated() ) ); - connect( projectionSelector, SIGNAL( initialized() ), this, SLOT( projectionSelectorInitialized() ) ); + connect( projectionSelector, &QgsProjectionSelectionTreeWidget::crsSelected, this, &QgsProjectProperties::srIdUpdated ); + connect( projectionSelector, &QgsProjectionSelectionTreeWidget::initialized, this, &QgsProjectProperties::projectionSelectorInitialized ); connect( cmbEllipsoid, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updateEllipsoidUI( int ) ) ); @@ -130,7 +130,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa updateGuiForMapUnits( srs.mapUnits() ); QgsDebugMsg( "Read project CRSID: " + QString::number( mProjectSrsId ) ); - projectionSelector->setSelectedCrsId( mProjectSrsId ); + projectionSelector->setCrs( srs ); mMapTileRenderingCheckBox->setChecked( mMapCanvas->mapSettings().testFlag( QgsMapSettings::RenderMapTile ) ); @@ -776,14 +776,14 @@ void QgsProjectProperties::apply() // selected that has an srid. This prevents error if the user // selects a top-level node rather than an actual coordinate // system - long myCRSID = projectionSelector->selectedCrsId(); + long myCRSID = projectionSelector->crs().srsid(); if ( myCRSID ) { QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( myCRSID ); mMapCanvas->setDestinationCrs( srs ); QgsDebugMsg( QString( "Selected CRS " ) + srs.description() ); // write the currently selected projections _proj string_ to project settings - QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->selectedProj4String() ) ); + QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->crs().toProj4() ) ); QgsProject::instance()->setCrs( srs ); // Set the map units to the projected coordinates if we are projecting @@ -1212,20 +1212,22 @@ void QgsProjectProperties::on_cbxProjectionEnabled_toggled( bool onFlyEnabled ) // reset projection to default const QMap &mapLayers = QgsProject::instance()->mapLayers(); + QgsCoordinateReferenceSystem crs; if ( mMapCanvas->currentLayer() ) { - mLayerSrsId = mMapCanvas->currentLayer()->crs().srsid(); + crs = mMapCanvas->currentLayer()->crs(); } else if ( !mapLayers.isEmpty() ) { - mLayerSrsId = mapLayers.begin().value()->crs().srsid(); + crs = mapLayers.begin().value()->crs(); } else { - mLayerSrsId = mProjectSrsId; + crs = QgsCoordinateReferenceSystem::fromSrsId( mProjectSrsId ); } + mLayerSrsId = crs.srsid(); mProjectSrsId = mLayerSrsId; - projectionSelector->setSelectedCrsId( mLayerSrsId ); + projectionSelector->setCrs( crs ); // unset ellipsoid mEllipsoidIndex = 0; @@ -1234,9 +1236,9 @@ void QgsProjectProperties::on_cbxProjectionEnabled_toggled( bool onFlyEnabled ) { if ( !mLayerSrsId ) { - mLayerSrsId = projectionSelector->selectedCrsId(); + mLayerSrsId = projectionSelector->crs().srsid(); } - projectionSelector->setSelectedCrsId( mProjectSrsId ); + projectionSelector->setCrs( QgsCoordinateReferenceSystem::fromSrsId( mProjectSrsId ) ); } srIdUpdated(); @@ -1303,11 +1305,10 @@ void QgsProjectProperties::updateGuiForMapUnits( QgsUnitTypes::DistanceUnit unit void QgsProjectProperties::srIdUpdated() { - long myCRSID = projectionSelector->selectedCrsId(); - if ( !isProjected() || !myCRSID ) + QgsCoordinateReferenceSystem srs = projectionSelector->crs(); + if ( !isProjected() || !srs.isValid() ) return; - QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( myCRSID ); //set radio button to crs map unit type QgsUnitTypes::DistanceUnit units = srs.mapUnits(); @@ -1354,15 +1355,15 @@ void QgsProjectProperties::on_pbnWMSExtCanvas_clicked() void QgsProjectProperties::on_pbnWMSAddSRS_clicked() { - QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector( this ); - mySelector->setMessage(); + QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this ); + mySelector->setMessage( QString() ); if ( mWMSList->count() > 0 ) { - mySelector->setSelectedAuthId( mWMSList->item( mWMSList->count() - 1 )->text() ); + mySelector->setCrs( QgsCoordinateReferenceSystem::fromOgcWmsCrs( mWMSList->item( mWMSList->count() - 1 )->text() ) ); } - if ( mySelector->exec() && mySelector->selectedCrsId() != 0 ) + if ( mySelector->exec() && mySelector->crs().isValid() ) { - QString authid = mySelector->selectedAuthId(); + QString authid = mySelector->crs().authid(); QList items = mWMSList->findItems( authid.mid( 5 ), Qt::MatchFixedString ); if ( items.isEmpty() ) @@ -1400,7 +1401,7 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked() if ( cbxProjectionEnabled->isChecked() ) { - QgsCoordinateReferenceSystem srs = QgsCoordinateReferenceSystem::fromSrsId( projectionSelector->selectedCrsId() ); + QgsCoordinateReferenceSystem srs = projectionSelector->crs(); crsList << srs.authid(); } diff --git a/src/app/qgsrasterlayerproperties.cpp b/src/app/qgsrasterlayerproperties.cpp index 373c3210c3a..c2c73c9db5e 100644 --- a/src/app/qgsrasterlayerproperties.cpp +++ b/src/app/qgsrasterlayerproperties.cpp @@ -26,7 +26,7 @@ #include "qgscontrastenhancement.h" #include "qgscoordinatetransform.h" #include "qgscubicrasterresampler.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgslogger.h" #include "qgsmapcanvas.h" #include "qgsmaplayerstyleguiutils.h" diff --git a/src/app/qgsvectorlayerproperties.cpp b/src/app/qgsvectorlayerproperties.cpp index 2fcf5ad6e17..e7883b8b512 100644 --- a/src/app/qgsvectorlayerproperties.cpp +++ b/src/app/qgsvectorlayerproperties.cpp @@ -33,7 +33,7 @@ #include "qgsfieldcalculator.h" #include "qgsfieldsproperties.h" #include "qgslabelingwidget.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgslogger.h" #include "qgsmapcanvas.h" #include "qgsmaplayerconfigwidgetfactory.h" diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index b1c93d4529f..d6a4ab08877 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -223,7 +223,6 @@ SET(QGIS_GUI_SRCS qgsfloatingwidget.cpp qgsfocuswatcher.cpp qgsformannotation.cpp - qgsgenericprojectionselector.cpp qgsgeometryrubberband.cpp qgsgradientcolorrampdialog.cpp qgsgradientstopeditor.cpp @@ -281,8 +280,9 @@ SET(QGIS_GUI_SRCS qgspluginmanagerinterface.cpp qgspresetcolorrampdialog.cpp qgsprevieweffect.cpp + qgsprojectionselectiondialog.cpp qgsprojectionselectionwidget.cpp - qgsprojectionselector.cpp + qgsprojectionselectiontreewidget.cpp qgspropertyassistantwidget.cpp qgspropertyoverridebutton.cpp qgsquerybuilder.cpp @@ -375,7 +375,6 @@ SET(QGIS_GUI_MOC_HDRS qgsfloatingwidget.h qgsfocuswatcher.h qgsformannotation.h - qgsgenericprojectionselector.h qgsgradientcolorrampdialog.h qgsgradientstopeditor.h qgsgroupwmsdatadialog.h @@ -426,8 +425,9 @@ SET(QGIS_GUI_MOC_HDRS qgspluginmanagerinterface.h qgspresetcolorrampdialog.h qgsprevieweffect.h + qgsprojectionselectiondialog.h qgsprojectionselectionwidget.h - qgsprojectionselector.h + qgsprojectionselectiontreewidget.h qgspropertyassistantwidget.h qgspropertyoverridebutton.h qgsquerybuilder.h diff --git a/src/gui/qgsnewgeopackagelayerdialog.cpp b/src/gui/qgsnewgeopackagelayerdialog.cpp index 651f2f290b4..97980fa0931 100644 --- a/src/gui/qgsnewgeopackagelayerdialog.cpp +++ b/src/gui/qgsnewgeopackagelayerdialog.cpp @@ -25,7 +25,7 @@ #include "qgsvectorlayer.h" #include "qgsproject.h" #include "qgscoordinatereferencesystem.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgslogger.h" diff --git a/src/gui/qgsowssourceselect.cpp b/src/gui/qgsowssourceselect.cpp index a8d3f8e89ce..9efcd13efc1 100644 --- a/src/gui/qgsowssourceselect.cpp +++ b/src/gui/qgsowssourceselect.cpp @@ -24,7 +24,7 @@ #include "qgscontexthelp.h" #include "qgscoordinatereferencesystem.h" #include "qgsdatasourceuri.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgslogger.h" #include "qgsmanageconnectionsdialog.h" #include "qgsmessageviewer.h" @@ -376,20 +376,20 @@ void QgsOWSSourceSelect::on_mChangeCRSButton_clicked() layers << layer; } - QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this ); - mySelector->setMessage(); + QgsProjectionSelectionDialog * mySelector = new QgsProjectionSelectionDialog( this ); + mySelector->setMessage( QString() ); mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs ); QgsCoordinateReferenceSystem defaultCRS = QgsProject::instance()->crs(); if ( defaultCRS.isValid() ) { - mySelector->setSelectedCrsId( defaultCRS.srsid() ); + mySelector->setCrs( defaultCRS ); } if ( !mySelector->exec() ) return; - mSelectedCRS = mySelector->selectedAuthId(); + mSelectedCRS = mySelector->crs().authid(); delete mySelector; mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) ); diff --git a/src/gui/qgsgenericprojectionselector.cpp b/src/gui/qgsprojectionselectiondialog.cpp similarity index 63% rename from src/gui/qgsgenericprojectionselector.cpp rename to src/gui/qgsprojectionselectiondialog.cpp index 14e89892a9b..f5c75cfa849 100644 --- a/src/gui/qgsgenericprojectionselector.cpp +++ b/src/gui/qgsprojectionselectiondialog.cpp @@ -17,15 +17,11 @@ ***************************************************************************/ #include "qgsapplication.h" -#include +#include "qgsprojectionselectiondialog.h" #include #include -/** - * \class QgsGenericProjectionSelector - * \brief A generic dialog to prompt the user for a Coordinate Reference System - */ -QgsGenericProjectionSelector::QgsGenericProjectionSelector( QWidget *parent, +QgsProjectionSelectionDialog::QgsProjectionSelectionDialog( QWidget *parent, Qt::WindowFlags fl ) : QDialog( parent, fl ) { @@ -38,14 +34,15 @@ QgsGenericProjectionSelector::QgsGenericProjectionSelector( QWidget *parent, textEdit->hide(); //apply selected projection upon double click on item - connect( projectionSelector, SIGNAL( projectionDoubleClicked() ), this, SLOT( accept() ) ); + connect( projectionSelector, &QgsProjectionSelectionTreeWidget::projectionDoubleClicked, this, &QgsProjectionSelectionDialog::accept ); } -void QgsGenericProjectionSelector::setMessage( QString message ) +void QgsProjectionSelectionDialog::setMessage( const QString& message ) { + QString m = message; //short term kludge to make the layer selector default to showing //a layer projection selection message. If you want the selector - if ( message.isEmpty() ) + if ( m.isEmpty() ) { // Set up text edit pane QString format( QStringLiteral( "

%1

%2 %3" ) ); @@ -53,48 +50,32 @@ void QgsGenericProjectionSelector::setMessage( QString message ) QString sentence1 = tr( "This layer appears to have no projection specification." ); QString sentence2 = tr( "By default, this layer will now have its projection set to that of the project, " "but you may override this by selecting a different projection below." ); - message = format.arg( header, sentence1, sentence2 ); + m = format.arg( header, sentence1, sentence2 ); } QString myStyle = QgsApplication::reportStyleSheet(); - message = "" + message + ""; - textEdit->setHtml( message ); + m = "" + m + ""; + textEdit->setHtml( m ); textEdit->show(); } -QgsGenericProjectionSelector::~QgsGenericProjectionSelector() +QgsProjectionSelectionDialog::~QgsProjectionSelectionDialog() { QSettings settings; settings.setValue( QStringLiteral( "/Windows/ProjectionSelector/geometry" ), saveGeometry() ); } -void QgsGenericProjectionSelector::setSelectedCrsName( const QString& name ) +QgsCoordinateReferenceSystem QgsProjectionSelectionDialog::crs() const { - projectionSelector->setSelectedCrsName( name ); + return projectionSelector->crs(); } -void QgsGenericProjectionSelector::setSelectedCrsId( long theID ) +void QgsProjectionSelectionDialog::setCrs( const QgsCoordinateReferenceSystem& crs ) { - projectionSelector->setSelectedCrsId( theID ); + projectionSelector->setCrs( crs ); } -void QgsGenericProjectionSelector::setSelectedAuthId( const QString& theID ) -{ - projectionSelector->setSelectedAuthId( theID ); -} - -long QgsGenericProjectionSelector::selectedCrsId() -{ - //@note don't use getSelectedWkt as that just returns the name part! - return projectionSelector->selectedCrsId(); -} - -QString QgsGenericProjectionSelector::selectedAuthId() -{ - return projectionSelector->selectedAuthId(); -} - -void QgsGenericProjectionSelector::setOgcWmsCrsFilter( const QSet& crsFilter ) +void QgsProjectionSelectionDialog::setOgcWmsCrsFilter( const QSet& crsFilter ) { projectionSelector->setOgcWmsCrsFilter( crsFilter ); } diff --git a/src/gui/qgsgenericprojectionselector.h b/src/gui/qgsprojectionselectiondialog.h similarity index 72% rename from src/gui/qgsgenericprojectionselector.h rename to src/gui/qgsprojectionselectiondialog.h index 3e523f21313..2ca841ee321 100644 --- a/src/gui/qgsgenericprojectionselector.h +++ b/src/gui/qgsprojectionselectiondialog.h @@ -24,8 +24,10 @@ #include "qgscontexthelp.h" #include "qgis_gui.h" +#include "qgscoordinatereferencesystem.h" /** + * \class QgsProjectionSelectionDialog * \ingroup gui * A generic dialog to prompt the user for a Coordinate Reference System. * @@ -33,46 +35,55 @@ * a coordinate system identifier e.g. from a plugin you might do this * to get an epsg code: * \code - * QgsGenericProjectionSelector mySelector( mQGisIface->mainWindow() ); - * mySelector.setSelectedEpsg( mEpsgId ); + * QgsProjectionSelectionDialog mySelector( mQGisIface->mainWindow() ); + * mySelector.setCrs( crs ); * if ( mySelector.exec() ) * { - * mEpsgId = mySelector.selectedEpsg(); + * mCrs = mySelector.crs(); * } * \endcode * * If you wish to embed the projection selector into an existing dialog - * the you probably want to look at QgsProjectionSelector rather. + * the you probably want to look at QgsProjectionSelectionWidget instead. + * @note added in QGIS 3.0 */ -class GUI_EXPORT QgsGenericProjectionSelector : public QDialog, private Ui::QgsGenericProjectionSelectorBase +class GUI_EXPORT QgsProjectionSelectionDialog : public QDialog, private Ui::QgsGenericProjectionSelectorBase { Q_OBJECT public: /** - * Constructor + * Constructor for QgsProjectionSelectionDialog. */ - QgsGenericProjectionSelector( QWidget *parent = nullptr, + QgsProjectionSelectionDialog( QWidget *parent = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags ); - ~QgsGenericProjectionSelector(); + ~QgsProjectionSelectionDialog(); + + /** + * Returns the CRS currently selected in the widget. + * @note added in QGIS 3.0 + * @see setCrs() + */ + QgsCoordinateReferenceSystem crs() const; + + /** + * Sets a \a message to show in the dialog. If an empty string is + * passed, the message will be a generic + * 'define the CRS for this layer'. + */ + void setMessage( const QString& message ); public slots: - /** If no parameter is passed, the message will be a generic - * 'define the CRS for this layer'. + /** + * Sets the initial \a crs to show within the dialog. + * @note added in QGIS 3.0 + * @see crs() */ - void setMessage( QString message = QStringLiteral( "" ) ); - long selectedCrsId(); - QString selectedAuthId(); - - void setSelectedCrsName( const QString& name ); - void setSelectedCrsId( long theID ); - void setSelectedAuthId( const QString& authId ); - - void on_mButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } + void setCrs( const QgsCoordinateReferenceSystem& crs ); /** * \brief filters this dialog by the given CRSs @@ -87,6 +98,10 @@ class GUI_EXPORT QgsGenericProjectionSelector : public QDialog, private Ui::QgsG * \warning This function's behavior is undefined if it is called after the dialog is shown. */ void setOgcWmsCrsFilter( const QSet& crsFilter ); + + private slots: + + void on_mButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } }; #endif // #ifndef QGSLAYERCRSSELECTOR_H diff --git a/src/gui/qgsprojectionselector.cpp b/src/gui/qgsprojectionselectiontreewidget.cpp similarity index 90% rename from src/gui/qgsprojectionselector.cpp rename to src/gui/qgsprojectionselectiontreewidget.cpp index 8154860d728..a7fc76afa9f 100644 --- a/src/gui/qgsprojectionselector.cpp +++ b/src/gui/qgsprojectionselectiontreewidget.cpp @@ -8,7 +8,7 @@ * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ -#include +#include "qgsprojectionselectiontreewidget.h" //standard includes #include @@ -27,24 +27,23 @@ #include #include -QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name, Qt::WindowFlags fl ) - : QWidget( parent, fl ) +QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget* parent ) + : QWidget( parent ) , mUserProjList( nullptr ) , mGeoList( nullptr ) , mProjList( nullptr ) , mProjListDone( false ) , mUserProjListDone( false ) , mRecentProjListDone( false ) - , mSearchColumn( QgsProjectionSelector::None ) + , mSearchColumn( QgsProjectionSelectionTreeWidget::None ) , mPushProjectionToFront( false ) { - Q_UNUSED( name ); setupUi( this ); - if ( qobject_cast( parent ) ) + if ( QDialog* dlg = qobject_cast( parent ) ) { // mark selected projection for push to front if parent dialog is accepted - connect( parent, SIGNAL( accepted() ), this, SLOT( pushProjectionToFront() ) ); + connect( dlg, &QDialog::accepted, this, &QgsProjectionSelectionTreeWidget::pushProjectionToFront ); } // Get the full path name to the sqlite3 spatial reference database. @@ -67,7 +66,7 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name, mRecentProjections = QgsCoordinateReferenceSystem::recentProjections(); } -QgsProjectionSelector::~QgsProjectionSelector() +QgsProjectionSelectionTreeWidget::~QgsProjectionSelectionTreeWidget() { if ( !mPushProjectionToFront ) { @@ -112,7 +111,7 @@ QgsProjectionSelector::~QgsProjectionSelector() settings.setValue( QStringLiteral( "/UI/recentProjectionsAuthId" ), projectionsAuthId ); } -void QgsProjectionSelector::resizeEvent( QResizeEvent * event ) +void QgsProjectionSelectionTreeWidget::resizeEvent( QResizeEvent * event ) { lstCoordinateSystems->header()->resizeSection( NameColumn, event->size().width() - 240 ); lstCoordinateSystems->header()->resizeSection( AuthidColumn, 240 ); @@ -123,7 +122,7 @@ void QgsProjectionSelector::resizeEvent( QResizeEvent * event ) lstRecent->header()->resizeSection( QgisCrsIdColumn, 0 ); } -void QgsProjectionSelector::showEvent( QShowEvent * event ) +void QgsProjectionSelectionTreeWidget::showEvent( QShowEvent * event ) { // ensure the projection list view is actually populated // before we show this widget @@ -146,7 +145,7 @@ void QgsProjectionSelector::showEvent( QShowEvent * event ) QWidget::showEvent( event ); } -QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet * crsFilter ) +QString QgsProjectionSelectionTreeWidget::ogcWmsCrsFilterAsSqlExpression( QSet * crsFilter ) { QString sqlExpression = QStringLiteral( "1" ); // it's "SQL" for "true" QMap authParts; @@ -204,22 +203,7 @@ QString QgsProjectionSelector::ogcWmsCrsFilterAsSqlExpression( QSet * c return sqlExpression; } -void QgsProjectionSelector::setSelectedCrsName( const QString& theCRSName ) -{ - applySelection( NameColumn, theCRSName ); -} - -void QgsProjectionSelector::setSelectedCrsId( long theCRSID ) -{ - applySelection( QgisCrsIdColumn, QString::number( theCRSID ) ); -} - -void QgsProjectionSelector::setSelectedAuthId( const QString& id ) -{ - applySelection( AuthidColumn, id ); -} - -void QgsProjectionSelector::applySelection( int column, QString value ) +void QgsProjectionSelectionTreeWidget::applySelection( int column, QString value ) { if ( !mProjListDone || !mUserProjListDone ) { @@ -229,17 +213,17 @@ void QgsProjectionSelector::applySelection( int column, QString value ) return; } - if ( column == QgsProjectionSelector::None ) + if ( column == QgsProjectionSelectionTreeWidget::None ) { // invoked deferred selection column = mSearchColumn; value = mSearchValue; - mSearchColumn = QgsProjectionSelector::None; + mSearchColumn = QgsProjectionSelectionTreeWidget::None; mSearchValue.clear(); } - if ( column == QgsProjectionSelector::None ) + if ( column == QgsProjectionSelectionTreeWidget::None ) return; QList nodes = lstCoordinateSystems->findItems( value, Qt::MatchExactly | Qt::MatchRecursive, column ); @@ -259,7 +243,7 @@ void QgsProjectionSelector::applySelection( int column, QString value ) } } -void QgsProjectionSelector::insertRecent( long crsId ) +void QgsProjectionSelectionTreeWidget::insertRecent( long crsId ) { if ( !mProjListDone || !mUserProjListDone ) return; @@ -275,15 +259,20 @@ void QgsProjectionSelector::insertRecent( long crsId ) } //note this line just returns the projection name! -QString QgsProjectionSelector::selectedName() +QString QgsProjectionSelectionTreeWidget::selectedName() { // return the selected wkt name from the list view QTreeWidgetItem *lvi = lstCoordinateSystems->currentItem(); return lvi ? lvi->text( NameColumn ) : QString::null; } +void QgsProjectionSelectionTreeWidget::setCrs( const QgsCoordinateReferenceSystem& crs ) +{ + applySelection( AuthidColumn, crs.authid() ); +} + // Returns the whole proj4 string for the selected projection node -QString QgsProjectionSelector::selectedProj4String() +QString QgsProjectionSelectionTreeWidget::selectedProj4String() { // Only return the projection if there is a node in the tree // selected that has an srid. This prevents error if the user @@ -351,7 +340,7 @@ QString QgsProjectionSelector::selectedProj4String() return projString; } -QString QgsProjectionSelector::getSelectedExpression( const QString& expression ) +QString QgsProjectionSelectionTreeWidget::getSelectedExpression( const QString& expression ) const { // Only return the attribute if there is a node in the tree // selected that has an srs_id. This prevents error if the user @@ -391,7 +380,9 @@ QString QgsProjectionSelector::getSelectedExpression( const QString& expression int rc = sqlite3_open_v2( databaseFileName.toUtf8().data(), &database, SQLITE_OPEN_READONLY, nullptr ); if ( rc ) { - showDBMissingWarning( databaseFileName ); + QgsMessageLog::logMessage( tr( "Resource Location Error" ), tr( "Error reading database file from: \n %1\n" + "Because of this the projection selector will not work..." ).arg( databaseFileName ), + QgsMessageLog::CRITICAL ); return QString(); } @@ -421,23 +412,16 @@ QString QgsProjectionSelector::getSelectedExpression( const QString& expression return attributeValue; } - -long QgsProjectionSelector::selectedPostgresSrId() -{ - return getSelectedExpression( QStringLiteral( "srid" ) ).toLong(); -} - - -QString QgsProjectionSelector::selectedAuthId() +QgsCoordinateReferenceSystem QgsProjectionSelectionTreeWidget::crs() const { int srid = getSelectedExpression( QStringLiteral( "srs_id" ) ).toLong(); if ( srid >= USER_CRS_START_ID ) - return QStringLiteral( "USER:%1" ).arg( srid ); + return QgsCoordinateReferenceSystem::fromOgcWmsCrs( QString( "USER:%1" ).arg( srid ) ); else - return getSelectedExpression( QStringLiteral( "upper(auth_name||':'||auth_id)" ) ); + return QgsCoordinateReferenceSystem::fromOgcWmsCrs( getSelectedExpression( QStringLiteral( "upper(auth_name||':'||auth_id)" ) ) ); } -long QgsProjectionSelector::selectedCrsId() +long QgsProjectionSelectionTreeWidget::selectedCrsId() { QTreeWidgetItem* item = lstCoordinateSystems->currentItem(); @@ -448,7 +432,7 @@ long QgsProjectionSelector::selectedCrsId() } -void QgsProjectionSelector::setOgcWmsCrsFilter( const QSet& crsFilter ) +void QgsProjectionSelectionTreeWidget::setOgcWmsCrsFilter( const QSet& crsFilter ) { mCrsFilter = crsFilter; mProjListDone = false; @@ -456,7 +440,7 @@ void QgsProjectionSelector::setOgcWmsCrsFilter( const QSet& crsFilter ) lstCoordinateSystems->clear(); } -void QgsProjectionSelector::loadUserCrsList( QSet *crsFilter ) +void QgsProjectionSelectionTreeWidget::loadUserCrsList( QSet *crsFilter ) { if ( mUserProjListDone ) return; @@ -532,7 +516,7 @@ void QgsProjectionSelector::loadUserCrsList( QSet *crsFilter ) mUserProjListDone = true; } -void QgsProjectionSelector::loadCrsList( QSet *crsFilter ) +void QgsProjectionSelectionTreeWidget::loadCrsList( QSet *crsFilter ) { if ( mProjListDone ) return; @@ -674,7 +658,7 @@ void QgsProjectionSelector::loadCrsList( QSet *crsFilter ) } // New coordinate system selected from the list -void QgsProjectionSelector::on_lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * ) +void QgsProjectionSelectionTreeWidget::on_lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * ) { QgsDebugMsg( "Entered." ); @@ -691,7 +675,7 @@ void QgsProjectionSelector::on_lstCoordinateSystems_currentItemChanged( QTreeWid if ( current->childCount() == 0 ) { // Found a real CRS - emit sridSelected( QString::number( selectedCrsId() ) ); + emit crsSelected(); teProjection->setText( selectedProj4String() ); teSelected->setText( selectedName() ); @@ -719,7 +703,7 @@ void QgsProjectionSelector::on_lstCoordinateSystems_currentItemChanged( QTreeWid } } -void QgsProjectionSelector::on_lstCoordinateSystems_itemDoubleClicked( QTreeWidgetItem *current, int column ) +void QgsProjectionSelectionTreeWidget::on_lstCoordinateSystems_itemDoubleClicked( QTreeWidgetItem *current, int column ) { Q_UNUSED( column ); @@ -737,7 +721,7 @@ void QgsProjectionSelector::on_lstCoordinateSystems_itemDoubleClicked( QTreeWidg emit projectionDoubleClicked(); } -void QgsProjectionSelector::on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * ) +void QgsProjectionSelectionTreeWidget::on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem * ) { QgsDebugMsg( "Entered." ); @@ -754,7 +738,7 @@ void QgsProjectionSelector::on_lstRecent_currentItemChanged( QTreeWidgetItem *cu lstCoordinateSystems->setCurrentItem( nodes.first() ); } -void QgsProjectionSelector::on_lstRecent_itemDoubleClicked( QTreeWidgetItem *current, int column ) +void QgsProjectionSelectionTreeWidget::on_lstRecent_itemDoubleClicked( QTreeWidgetItem *current, int column ) { Q_UNUSED( column ); @@ -771,7 +755,7 @@ void QgsProjectionSelector::on_lstRecent_itemDoubleClicked( QTreeWidgetItem *cur emit projectionDoubleClicked(); } -void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item ) +void QgsProjectionSelectionTreeWidget::hideDeprecated( QTreeWidgetItem *item ) { if ( item->data( 0, Qt::UserRole ).toBool() ) { @@ -788,13 +772,13 @@ void QgsProjectionSelector::hideDeprecated( QTreeWidgetItem *item ) hideDeprecated( item->child( i ) ); } -void QgsProjectionSelector::on_cbxHideDeprecated_stateChanged() +void QgsProjectionSelectionTreeWidget::on_cbxHideDeprecated_stateChanged() { for ( int i = 0; i < lstCoordinateSystems->topLevelItemCount(); i++ ) hideDeprecated( lstCoordinateSystems->topLevelItem( i ) ); } -void QgsProjectionSelector::on_leSearch_textChanged( const QString & filterTxt ) +void QgsProjectionSelectionTreeWidget::on_leSearch_textChanged( const QString & filterTxt ) { QString filterTxtCopy = filterTxt; filterTxtCopy.replace( QRegExp( "\\s+" ), QStringLiteral( ".*" ) ); @@ -864,14 +848,14 @@ void QgsProjectionSelector::on_leSearch_textChanged( const QString & filterTxt ) } -void QgsProjectionSelector::pushProjectionToFront() +void QgsProjectionSelectionTreeWidget::pushProjectionToFront() { // set flag to push selected projection to front in destructor mPushProjectionToFront = true; } -long QgsProjectionSelector::getLargestCrsIdMatch( const QString& sql ) +long QgsProjectionSelectionTreeWidget::getLargestCrsIdMatch( const QString& sql ) { long srsId = 0; @@ -940,7 +924,7 @@ long QgsProjectionSelector::getLargestCrsIdMatch( const QString& sql ) return srsId; } -QStringList QgsProjectionSelector::authorities() +QStringList QgsProjectionSelectionTreeWidget::authorities() { sqlite3 *database = nullptr; const char *tail = nullptr; @@ -983,7 +967,7 @@ QStringList QgsProjectionSelector::authorities() * \arg const QString in The input string to make safe. * \return The string made safe for SQL statements. */ -const QString QgsProjectionSelector::sqlSafeString( const QString& theSQL ) +const QString QgsProjectionSelectionTreeWidget::sqlSafeString( const QString& theSQL ) { QString retval = theSQL; retval.replace( '\\', QLatin1String( "\\\\" ) ); @@ -993,7 +977,7 @@ const QString QgsProjectionSelector::sqlSafeString( const QString& theSQL ) return retval; } -void QgsProjectionSelector::showDBMissingWarning( const QString& fileName ) +void QgsProjectionSelectionTreeWidget::showDBMissingWarning( const QString& fileName ) { QMessageBox::critical( this, tr( "Resource Location Error" ), diff --git a/src/gui/qgsprojectionselector.h b/src/gui/qgsprojectionselectiontreewidget.h similarity index 79% rename from src/gui/qgsprojectionselector.h rename to src/gui/qgsprojectionselectiontreewidget.h index 932563311bd..f7b7ac3d532 100644 --- a/src/gui/qgsprojectionselector.h +++ b/src/gui/qgsprojectionselectiontreewidget.h @@ -18,74 +18,52 @@ #include "qgis.h" #include "qgis_gui.h" +#include "qgscoordinatereferencesystem.h" class QResizeEvent; -/** \ingroup gui - * A widget for selecting a Coordinate reference system from a tree. - * @see QgsGenericProjectionSelector. - @author Tim Sutton - */ -class GUI_EXPORT QgsProjectionSelector : public QWidget, private Ui::QgsProjectionSelectorBase +/** + * \class QgsProjectionSelectionTreeWidget + * \ingroup gui + * A widget for selecting a coordinate reference system from a tree. + * + * This widget implements a tree view of projections, as seen in the + * QgsProjectionSelectionDialog dialog. In most cases it is more + * suitable to use the compact QgsProjectionSelectionWidget widget. + * + * \see QgsProjectionSelectionDialog. + * \see QgsProjectionSelectionWidget + * \note added in QGIS 3.0 + */ + +class GUI_EXPORT QgsProjectionSelectionTreeWidget : public QWidget, private Ui::QgsProjectionSelectorBase { Q_OBJECT + public: - QgsProjectionSelector( QWidget* parent, const char *name = "", Qt::WindowFlags fl = 0 ); - - ~QgsProjectionSelector(); /** - * \brief Populate the proj tree view with user defined projection names... - * - * \param crsFilter a list of OGC Coordinate Reference Systems to filter the - * list of projections by. This is useful in (e.g.) WMS situations - * where you just want to offer what the WMS server can support. - * - * \todo Should this be public? + * Constructor for QgsProjectionSelectionTreeWidget. */ - void loadUserCrsList( QSet *crsFilter = nullptr ); + QgsProjectionSelectionTreeWidget( QWidget* parent = nullptr ); + + ~QgsProjectionSelectionTreeWidget(); /** - * \brief Populate the proj tree view with system projection names... - * - * \param crsFilter a list of OGC Coordinate Reference Systems to filter the - * list of projections by. This is useful in (e.g.) WMS situations - * where you just want to offer what the WMS server can support. - * - * \todo Should this be public? + * Returns the CRS currently selected in the widget. + * @note added in QGIS 3.0 + * @see setCrs() */ - void loadCrsList( QSet *crsFilter = nullptr ); - - /*! - * \brief Make the string safe for use in SQL statements. - * This involves escaping single quotes, double quotes, backslashes, - * and optionally, percentage symbols. Percentage symbols are used - * as wildcards sometimes and so when using the string as part of the - * LIKE phrase of a select statement, should be escaped. - * \arg const QString in The input string to make safe. - * \return The string made safe for SQL statements. - */ - const QString sqlSafeString( const QString& theSQL ); - - //! Gets the current authority-style projection identifier - QString selectedAuthId(); + QgsCoordinateReferenceSystem crs() const; public slots: - void setSelectedCrsName( const QString& theCRSName ); - QString selectedName(); - - void setSelectedCrsId( long theCRSID ); - - void setSelectedAuthId( const QString& authId ); - - QString selectedProj4String(); - - //! Gets the current PostGIS-style projection identifier - long selectedPostgresSrId(); - - //! Gets the current QGIS projection identfier - long selectedCrsId(); + /** + * Sets the initial \a crs to show within the dialog. + * @note added in QGIS 3.0 + * @see crs() + */ + void setCrs( const QgsCoordinateReferenceSystem& crs ); /** * \brief filters this widget by the given CRSs @@ -100,14 +78,31 @@ class GUI_EXPORT QgsProjectionSelector : public QWidget, private Ui::QgsProjecti * \warning This function's behavior is undefined if it is called after the widget is shown. */ void setOgcWmsCrsFilter( const QSet& crsFilter ); - void on_lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev ); - void on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev ); - void on_cbxHideDeprecated_stateChanged(); - void on_leSearch_textChanged( const QString & ); - //! mark selected projection for push to front + /** + * Marks the current selected projection for push to front of recent projections list. + */ void pushProjectionToFront(); + signals: + + /** + * Emitted when a projection is selected in the widget. + */ + void crsSelected(); + + /** + * Notifies others that the widget is now fully initialized, including deferred selection of projection. + * @note added in 2.4 + */ + void initialized(); + + /** + * Emitted when a projection is double clicked in the list. + * @note added in 2.14 + */ + void projectionDoubleClicked(); + protected: // Used to ensure the projection list view is actually populated void showEvent( QShowEvent * event ) override; @@ -117,6 +112,35 @@ class GUI_EXPORT QgsProjectionSelector : public QWidget, private Ui::QgsProjecti private: + /** + * \brief Populate the proj tree view with user defined projection names... + * + * \param crsFilter a list of OGC Coordinate Reference Systems to filter the + * list of projections by. This is useful in (e.g.) WMS situations + * where you just want to offer what the WMS server can support. + */ + void loadUserCrsList( QSet *crsFilter = nullptr ); + + /** + * \brief Populate the proj tree view with system projection names... + * + * \param crsFilter a list of OGC Coordinate Reference Systems to filter the + * list of projections by. This is useful in (e.g.) WMS situations + * where you just want to offer what the WMS server can support. + */ + void loadCrsList( QSet *crsFilter = nullptr ); + + /*! + * \brief Make the string safe for use in SQL statements. + * This involves escaping single quotes, double quotes, backslashes, + * and optionally, percentage symbols. Percentage symbols are used + * as wildcards sometimes and so when using the string as part of the + * LIKE phrase of a select statement, should be escaped. + * \arg const QString in The input string to make safe. + * \return The string made safe for SQL statements. + */ + const QString sqlSafeString( const QString& theSQL ); + /** * \brief converts the CRS group to a SQL expression fragment * @@ -140,14 +164,21 @@ class GUI_EXPORT QgsProjectionSelector : public QWidget, private Ui::QgsProjecti * does not scroll the list to the selection if the widget is not visible. * Therefore you will typically want to use this in a showEvent(). */ - void applySelection( int column = QgsProjectionSelector::None, QString value = QString::null ); + void applySelection( int column = QgsProjectionSelectionTreeWidget::None, QString value = QString::null ); /** * \brief gets an arbitrary sqlite3 expression from the selection * * \param e The sqlite3 expression (typically "srid" or "sridid") */ - QString getSelectedExpression( const QString& e ); + QString getSelectedExpression( const QString& e ) const; + + QString selectedName(); + + QString selectedProj4String(); + + //! Gets the current QGIS projection identfier + long selectedCrsId(); //! Show the user a warning if the srs database could not be found void showDBMissingWarning( const QString& fileName ); @@ -204,19 +235,10 @@ class GUI_EXPORT QgsProjectionSelector : public QWidget, private Ui::QgsProjecti //! Apply projection on double click void on_lstCoordinateSystems_itemDoubleClicked( QTreeWidgetItem *current, int column ); void on_lstRecent_itemDoubleClicked( QTreeWidgetItem *current, int column ); - - signals: - void sridSelected( const QString& theSRID ); - //! Refresh any listening canvases - void refresh(); - //! Let listeners know if find has focus so they can adjust the default button - void searchBoxHasFocus( bool ); - //! Notify others that the widget is now fully initialized, including deferred selection of projection - //! @note added in 2.4 - void initialized(); - //! Apply projection on double click - //! @note added in 2.14 - void projectionDoubleClicked(); + void on_lstCoordinateSystems_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev ); + void on_lstRecent_currentItemChanged( QTreeWidgetItem *current, QTreeWidgetItem *prev ); + void on_cbxHideDeprecated_stateChanged(); + void on_leSearch_textChanged( const QString & ); }; #endif diff --git a/src/gui/qgsprojectionselectionwidget.cpp b/src/gui/qgsprojectionselectionwidget.cpp index 09781b4d85a..f66e04a4865 100644 --- a/src/gui/qgsprojectionselectionwidget.cpp +++ b/src/gui/qgsprojectionselectionwidget.cpp @@ -18,14 +18,14 @@ #include "qgsprojectionselectionwidget.h" #include "qgsapplication.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgsproject.h" #include QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) : QWidget( parent ) { - mDialog = new QgsGenericProjectionSelector( this ); + mDialog = new QgsProjectionSelectionDialog( this ); QHBoxLayout* layout = new QHBoxLayout(); layout->setContentsMargins( 0, 0, 0, 0 ); @@ -66,7 +66,7 @@ QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent ) setFocusPolicy( Qt::StrongFocus ); setFocusProxy( mButton ); - connect( mButton, SIGNAL( clicked() ), this, SLOT( selectCrs() ) ); + connect( mButton, &QToolButton::clicked, this, &QgsProjectionSelectionWidget::selectCrs ); connect( mCrsComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( comboIndexChanged( int ) ) ); } @@ -173,7 +173,7 @@ void QgsProjectionSelectionWidget::selectCrs() //find out crs id of current proj4 string if ( mCrs.isValid() ) { - mDialog->setSelectedCrsId( mCrs.srsid() ); + mDialog->setCrs( mCrs ); } if ( mDialog->exec() ) @@ -181,7 +181,7 @@ void QgsProjectionSelectionWidget::selectCrs() mCrsComboBox->blockSignals( true ); mCrsComboBox->setCurrentIndex( mCrsComboBox->findData( QgsProjectionSelectionWidget::CurrentCrs ) ); mCrsComboBox->blockSignals( false ); - QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( mDialog->selectedAuthId() ); + QgsCoordinateReferenceSystem crs = mDialog->crs(); setCrs( crs ); emit crsChanged( crs ); } diff --git a/src/gui/qgsprojectionselectionwidget.h b/src/gui/qgsprojectionselectionwidget.h index 4611230fdad..f26c985e1b9 100644 --- a/src/gui/qgsprojectionselectionwidget.h +++ b/src/gui/qgsprojectionselectionwidget.h @@ -25,7 +25,7 @@ #include "qgscoordinatereferencesystem.h" #include "qgis_gui.h" -class QgsGenericProjectionSelector; +class QgsProjectionSelectionDialog; /** * \class QgsProjectionSelectionWidget @@ -56,7 +56,7 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget * Can be used to modify how the projection selector dialog behaves. * @returns projection selector dialog */ - QgsGenericProjectionSelector* dialog() { return mDialog; } + QgsProjectionSelectionDialog* dialog() { return mDialog; } /** Returns the currently selected CRS for the widget * @returns current CRS @@ -121,7 +121,7 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget QgsCoordinateReferenceSystem mDefaultCrs; QComboBox* mCrsComboBox = nullptr; QToolButton* mButton = nullptr; - QgsGenericProjectionSelector* mDialog = nullptr; + QgsProjectionSelectionDialog* mDialog = nullptr; QString mNotSetText; void addNotSetOption(); diff --git a/src/gui/qgsrasterlayersaveasdialog.cpp b/src/gui/qgsrasterlayersaveasdialog.cpp index 1163cd7d6ab..dc7871b173f 100644 --- a/src/gui/qgsrasterlayersaveasdialog.cpp +++ b/src/gui/qgsrasterlayersaveasdialog.cpp @@ -21,7 +21,7 @@ #include "qgsrasterformatsaveoptionswidget.h" #include "qgsrasterrenderer.h" #include "qgsrastertransparency.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "gdal.h" diff --git a/src/gui/qgssourceselectdialog.cpp b/src/gui/qgssourceselectdialog.cpp index c3ff4bc96c0..c5547b08dc7 100644 --- a/src/gui/qgssourceselectdialog.cpp +++ b/src/gui/qgssourceselectdialog.cpp @@ -18,7 +18,7 @@ #include "qgssourceselectdialog.h" #include "qgsowsconnection.h" #include "qgsnewhttpconnection.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgsexpressionbuilderdialog.h" #include "qgscontexthelp.h" #include "qgsproject.h" @@ -74,8 +74,8 @@ QgsSourceSelectDialog::QgsSourceSelectDialog( const QString& serviceName, Servic connect( btnChangeSpatialRefSys, SIGNAL( clicked() ), this, SLOT( changeCrs() ) ); connect( lineFilter, SIGNAL( textChanged( QString ) ), this, SLOT( filterChanged( QString ) ) ); populateConnectionList(); - mProjectionSelector = new QgsGenericProjectionSelector( this ); - mProjectionSelector->setMessage(); + mProjectionSelector = new QgsProjectionSelectionDialog( this ); + mProjectionSelector->setMessage( QString() ); treeView->setItemDelegate( new QgsSourceSelectItemDelegate( treeView ) ); @@ -367,7 +367,7 @@ void QgsSourceSelectDialog::changeCrs() { if ( mProjectionSelector->exec() ) { - QString crsString = mProjectionSelector->selectedAuthId(); + QString crsString = mProjectionSelector->crs().authid(); labelCoordRefSys->setText( crsString ); } } @@ -397,7 +397,7 @@ void QgsSourceSelectDialog::changeCrsFilter() if ( !preferredCRS.isEmpty() ) { QgsCoordinateReferenceSystem refSys = QgsCoordinateReferenceSystem::fromOgcWmsCrs( preferredCRS ); - mProjectionSelector->setSelectedCrsId( refSys.srsid() ); + mProjectionSelector->setCrs( refSys ); labelCoordRefSys->setText( preferredCRS ); } diff --git a/src/gui/qgssourceselectdialog.h b/src/gui/qgssourceselectdialog.h index 8d77a2456e1..3df023efbdf 100644 --- a/src/gui/qgssourceselectdialog.h +++ b/src/gui/qgssourceselectdialog.h @@ -23,7 +23,7 @@ class QStandardItemModel; class QSortFilterProxyModel; -class QgsGenericProjectionSelector; +class QgsProjectionSelectionDialog; class QgsOwsConnection; /** \ingroup gui @@ -53,7 +53,7 @@ class GUI_EXPORT QgsSourceSelectDialog : public QDialog, protected Ui::QgsSource protected: QString mServiceName; ServiceType mServiceType; - QgsGenericProjectionSelector* mProjectionSelector = nullptr; + QgsProjectionSelectionDialog* mProjectionSelector = nullptr; // Available CRS for a server connection, key=typename, value=list("EPSG:XXXX") QMap mAvailableCRS; QStandardItemModel* mModel = nullptr; diff --git a/src/plugins/coordinate_capture/coordinatecapture.cpp b/src/plugins/coordinate_capture/coordinatecapture.cpp index 5597d7d5f9d..4a9459b6e43 100644 --- a/src/plugins/coordinate_capture/coordinatecapture.cpp +++ b/src/plugins/coordinate_capture/coordinatecapture.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include "qgsdockwidget.h" #include "coordinatecapture.h" @@ -184,11 +184,11 @@ void CoordinateCapture::help() void CoordinateCapture::setCRS() { - QgsGenericProjectionSelector mySelector( mQGisIface->mainWindow() ); - mySelector.setSelectedCrsId( mCrs.srsid() ); + QgsProjectionSelectionDialog mySelector( mQGisIface->mainWindow() ); + mySelector.setCrs( mCrs ); if ( mySelector.exec() ) { - mCrs.createFromSrsId( mySelector.selectedCrsId() ); + mCrs = mySelector.crs(); mTransform.setDestinationCrs( mCrs ); mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QgsUnitTypes::DistanceDegrees ) ? 5 : 3; //precision depends on CRS units } diff --git a/src/plugins/georeferencer/qgstransformsettingsdialog.cpp b/src/plugins/georeferencer/qgstransformsettingsdialog.cpp index df3e52ce8fd..f3c7fd6bab2 100644 --- a/src/plugins/georeferencer/qgstransformsettingsdialog.cpp +++ b/src/plugins/georeferencer/qgstransformsettingsdialog.cpp @@ -18,7 +18,7 @@ #include #include -#include "qgsprojectionselector.h" +#include "qgsprojectionselectiontreewidget.h" #include "qgsapplication.h" #include "qgsrasterlayer.h" diff --git a/src/plugins/grass/qgsgrassnewmapset.cpp b/src/plugins/grass/qgsgrassnewmapset.cpp index 78f68b87c3f..112d0554f8b 100644 --- a/src/plugins/grass/qgsgrassnewmapset.cpp +++ b/src/plugins/grass/qgsgrassnewmapset.cpp @@ -25,7 +25,7 @@ #include "qgslogger.h" #include "qgsmapcanvas.h" #include "qgsproject.h" -#include "qgsprojectionselector.h" +#include "qgsprojectionselectiontreewidget.h" #include "qgslocalec.h" #include "qgscsexception.h" @@ -354,9 +354,8 @@ void QgsGrassNewMapset::setProjectionPage() setGrassProjection(); } -void QgsGrassNewMapset::sridSelected( QString theSRID ) +void QgsGrassNewMapset::sridSelected() { - Q_UNUSED( theSRID ); projectionSelected(); } @@ -383,7 +382,7 @@ void QgsGrassNewMapset::setGrassProjection() { setError( mProjErrorLabel ); - QString proj4 = mProjectionSelector->selectedProj4String(); + QString proj4 = mProjectionSelector->crs().toProj4(); // Not defined if ( mNoProjRadioButton->isChecked() ) @@ -481,11 +480,11 @@ void QgsGrassNewMapset::setRegionPage() QgsCoordinateReferenceSystem newCrs; if ( mProjRadioButton->isChecked() ) { - QgsDebugMsg( QString( "selectedCrsId() = %1" ).arg( mProjectionSelector->selectedCrsId() ) ); + QgsDebugMsg( QString( "selectedCrsId() = %1" ).arg( mProjectionSelector->crs().srsid() ) ); - if ( mProjectionSelector->selectedCrsId() > 0 ) + if ( mProjectionSelector->crs().srsid() > 0 ) { - newCrs.createFromSrsId( mProjectionSelector->selectedCrsId() ); + newCrs = mProjectionSelector->crs(); if ( ! newCrs.isValid() ) { QgsGrass::warning( tr( "Cannot create projection." ) ); @@ -592,7 +591,7 @@ void QgsGrassNewMapset::setGrassRegionDefaults() if ( extSet && ( mNoProjRadioButton->isChecked() || ( mProjRadioButton->isChecked() - && srs.srsid() == mProjectionSelector->selectedCrsId() ) + && srs.srsid() == mProjectionSelector->crs().srsid() ) ) ) { @@ -814,7 +813,7 @@ void QgsGrassNewMapset::setSelectedRegion() // Warning: seems that crashes if source == dest - if ( mProjectionSelector->selectedCrsId() != GEOCRS_ID ) + if ( mProjectionSelector->crs().srsid() != GEOCRS_ID ) { // Warning: QgsCoordinateReferenceSystem::EpsgCrsId is broken (using epsg_id) //QgsCoordinateReferenceSystem source ( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); @@ -826,7 +825,7 @@ void QgsGrassNewMapset::setSelectedRegion() return; } - QgsCoordinateReferenceSystem dest = QgsCoordinateReferenceSystem::fromSrsId( mProjectionSelector->selectedCrsId() ); + QgsCoordinateReferenceSystem dest = mProjectionSelector->crs(); if ( !dest.isValid() ) { @@ -1024,9 +1023,9 @@ void QgsGrassNewMapset::drawRegion() points << points[0]; // close polygon // Warning: seems that crashes if source == dest - if ( mProjectionSelector->selectedCrsId() != GEOCRS_ID ) + if ( mProjectionSelector->crs().srsid() != GEOCRS_ID ) { - QgsCoordinateReferenceSystem source = QgsCoordinateReferenceSystem::fromSrsId( mProjectionSelector->selectedCrsId() ); + QgsCoordinateReferenceSystem source = mProjectionSelector->crs(); if ( !source.isValid() ) { @@ -1358,21 +1357,21 @@ void QgsGrassNewMapset::pageSelected( int index ) { QGridLayout *projectionLayout = new QGridLayout( mProjectionFrame ); - mProjectionSelector = new QgsProjectionSelector( mProjectionFrame, "Projection", 0 ); + mProjectionSelector = new QgsProjectionSelectionTreeWidget( mProjectionFrame ); mProjectionSelector->setEnabled( false ); projectionLayout->addWidget( mProjectionSelector, 0, 0 ); mProjectionSelector->show(); - connect( mProjectionSelector, SIGNAL( sridSelected( QString ) ), - this, SLOT( sridSelected( QString ) ) ); + connect( mProjectionSelector, &QgsProjectionSelectionTreeWidget::crsSelected, + this, &QgsGrassNewMapset::sridSelected ); QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs(); QgsDebugMsg( "srs = " + srs.toWkt() ); if ( srs.isValid() ) { - mProjectionSelector->setSelectedCrsId( srs.srsid() ); + mProjectionSelector->setCrs( srs ); mProjRadioButton->setChecked( true ); projRadioSwitched(); } diff --git a/src/plugins/grass/qgsgrassnewmapset.h b/src/plugins/grass/qgsgrassnewmapset.h index f91c2d45103..488968a7bd3 100644 --- a/src/plugins/grass/qgsgrassnewmapset.h +++ b/src/plugins/grass/qgsgrassnewmapset.h @@ -22,7 +22,7 @@ class QgsGrassPlugin; class QgisInterface; class QgsPoint; -class QgsProjectionSelector; +class QgsProjectionSelectionTreeWidget; extern "C" { @@ -109,7 +109,7 @@ class QgsGrassNewMapset : public QWizard, private Ui::QgsGrassNewMapsetBase void setProjectionPage(); //! Projection selected - void sridSelected( QString ); + void sridSelected(); void projectionSelected(); //! Location radio switched @@ -200,7 +200,7 @@ class QgsGrassNewMapset : public QWizard, private Ui::QgsGrassNewMapsetBase static bool sRunning; //! Projection selector - QgsProjectionSelector *mProjectionSelector = nullptr; + QgsProjectionSelectionTreeWidget *mProjectionSelector = nullptr; //! GRASS projection struct Cell_head mCellHead; diff --git a/src/providers/virtual/qgsvirtuallayersourceselect.cpp b/src/providers/virtual/qgsvirtuallayersourceselect.cpp index 89a679ec10c..c4c3ced34be 100644 --- a/src/providers/virtual/qgsvirtuallayersourceselect.cpp +++ b/src/providers/virtual/qgsvirtuallayersourceselect.cpp @@ -22,7 +22,7 @@ email : hugo dot mercier at oslandia dot com #include #include #include -#include +#include #include #include #include @@ -176,14 +176,14 @@ void QgsVirtualLayerSourceSelect::onLayerComboChanged( int idx ) void QgsVirtualLayerSourceSelect::onBrowseCRS() { - QgsGenericProjectionSelector crsSelector( this ); + QgsProjectionSelectionDialog crsSelector( this ); QgsCoordinateReferenceSystem crs( mSrid ); - crsSelector.setSelectedCrsId( crs.srsid() ); // convert postgis srid to internal id - crsSelector.setMessage(); + crsSelector.setCrs( crs ); + crsSelector.setMessage( QString() ); if ( crsSelector.exec() ) { - mCRS->setText( crsSelector.selectedAuthId() ); - QgsCoordinateReferenceSystem newCrs = QgsCoordinateReferenceSystem::fromSrsId( crsSelector.selectedCrsId() ); + mCRS->setText( crsSelector.crs().authid() ); + QgsCoordinateReferenceSystem newCrs = crsSelector.crs(); mSrid = newCrs.postgisSrid(); } } diff --git a/src/providers/wfs/qgswfssourceselect.cpp b/src/providers/wfs/qgswfssourceselect.cpp index 353d4577d1c..c58596fc713 100644 --- a/src/providers/wfs/qgswfssourceselect.cpp +++ b/src/providers/wfs/qgswfssourceselect.cpp @@ -23,7 +23,7 @@ #include "qgswfsdatasourceuri.h" #include "qgswfsutils.h" #include "qgsnewhttpconnection.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgscontexthelp.h" #include "qgsproject.h" #include "qgscoordinatereferencesystem.h" @@ -82,8 +82,8 @@ QgsWFSSourceSelect::QgsWFSSourceSelect( QWidget* parent, Qt::WindowFlags fl, boo connect( btnChangeSpatialRefSys, SIGNAL( clicked() ), this, SLOT( changeCRS() ) ); connect( lineFilter, SIGNAL( textChanged( QString ) ), this, SLOT( filterChanged( QString ) ) ); populateConnectionList(); - mProjectionSelector = new QgsGenericProjectionSelector( this ); - mProjectionSelector->setMessage(); + mProjectionSelector = new QgsProjectionSelectionDialog( this ); + mProjectionSelector->setMessage( QString() ); mItemDelegate = new QgsWFSItemDelegate( treeView ); treeView->setItemDelegate( mItemDelegate ); @@ -677,7 +677,7 @@ void QgsWFSSourceSelect::changeCRS() { if ( mProjectionSelector->exec() ) { - QString crsString = mProjectionSelector->selectedAuthId(); + QString crsString = mProjectionSelector->crs().authid(); labelCoordRefSys->setText( crsString ); } } @@ -704,7 +704,7 @@ void QgsWFSSourceSelect::changeCRSFilter() if ( !preferredCRS.isEmpty() ) { QgsCoordinateReferenceSystem refSys = QgsCoordinateReferenceSystem::fromOgcWmsCrs( preferredCRS ); - mProjectionSelector->setSelectedCrsId( refSys.srsid() ); + mProjectionSelector->setCrs( refSys ); labelCoordRefSys->setText( preferredCRS ); } diff --git a/src/providers/wfs/qgswfssourceselect.h b/src/providers/wfs/qgswfssourceselect.h index de456eff6b3..0f729f7c7ab 100644 --- a/src/providers/wfs/qgswfssourceselect.h +++ b/src/providers/wfs/qgswfssourceselect.h @@ -26,7 +26,7 @@ #include #include -class QgsGenericProjectionSelector; +class QgsProjectionSelectionDialog; class QgsWfsCapabilities; class QgsSQLComposerDialog; @@ -56,7 +56,7 @@ class QgsWFSSourceSelect: public QDialog, private Ui::QgsWFSSourceSelectBase private: QgsWFSSourceSelect(); //default constructor is forbidden - QgsGenericProjectionSelector* mProjectionSelector = nullptr; + QgsProjectionSelectionDialog* mProjectionSelector = nullptr; /** Stores the available CRS for a server connections. The first string is the typename, the corresponding list diff --git a/src/providers/wms/qgswmssourceselect.cpp b/src/providers/wms/qgswmssourceselect.cpp index dd389669111..6938b460c45 100644 --- a/src/providers/wms/qgswmssourceselect.cpp +++ b/src/providers/wms/qgswmssourceselect.cpp @@ -23,7 +23,7 @@ #include "qgscontexthelp.h" #include "qgscoordinatereferencesystem.h" #include "qgsdatasourceuri.h" -#include "qgsgenericprojectionselector.h" +#include "qgsprojectionselectiondialog.h" #include "qgslogger.h" #include "qgsmanageconnectionsdialog.h" #include "qgsmessageviewer.h" @@ -617,20 +617,20 @@ void QgsWMSSourceSelect::on_btnChangeSpatialRefSys_clicked() layers << layer; } - QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this ); - mySelector->setMessage(); + QgsProjectionSelectionDialog * mySelector = new QgsProjectionSelectionDialog( this ); + mySelector->setMessage( QString() ); mySelector->setOgcWmsCrsFilter( mCRSs ); QgsCoordinateReferenceSystem defaultCRS = QgsProject::instance()->crs(); if ( defaultCRS.isValid() ) { - mySelector->setSelectedCrsId( defaultCRS.srsid() ); + mySelector->setCrs( defaultCRS ); } if ( !mySelector->exec() ) return; - mCRS = mySelector->selectedAuthId(); + mCRS = mySelector->crs().authid(); delete mySelector; labelCoordRefSys->setText( descriptionForAuthId( mCRS ) ); diff --git a/src/ui/qgsgenericprojectionselectorbase.ui b/src/ui/qgsgenericprojectionselectorbase.ui index 7c7c417ae68..e24ffb07f84 100644 --- a/src/ui/qgsgenericprojectionselectorbase.ui +++ b/src/ui/qgsgenericprojectionselectorbase.ui @@ -54,7 +54,7 @@ - + @@ -71,9 +71,9 @@ - QgsProjectionSelector + QgsProjectionSelectionTreeWidget QWidget -
qgsprojectionselector.h
+
qgsprojectionselectiontreewidget.h
1
diff --git a/src/ui/qgsprojectpropertiesbase.ui b/src/ui/qgsprojectpropertiesbase.ui index 20cf02e3b01..334c78287e2 100644 --- a/src/ui/qgsprojectpropertiesbase.ui +++ b/src/ui/qgsprojectpropertiesbase.ui @@ -770,7 +770,7 @@ - +
@@ -2604,9 +2604,9 @@ 1 - QgsProjectionSelector + QgsProjectionSelectionTreeWidget QWidget -
qgsprojectionselector.h
+
qgsprojectionselectiontreewidget.h
1