Skip to content
Permalink
Browse files

Improve misleading/confusing API, and fix "layer has no CRS" message

incorrectly show at the top of many projection selection dialog boxes
  • Loading branch information
nyalldawson committed Sep 23, 2020
1 parent 05c2519 commit c68d05cc40f8f2c828e5204e6e4f5f11e68b4a7c
@@ -57,9 +57,18 @@ Returns the CRS currently selected in the widget.

void setMessage( const QString &message );
%Docstring
Sets 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'.
Sets a ``message`` to show in the dialog.

.. seealso:: :py:func:`showNoCrsForLayerMessage`
%End

void showNoCrsForLayerMessage();
%Docstring
When called, the dialog will show a default "layer has no CRS set" message above the projection selector.

.. seealso:: :py:func:`setMessage`

.. versionadded:: 3.16
%End

void setShowNoProjection( bool show );
@@ -786,7 +786,12 @@ void QgisApp::validateCrs( QgsCoordinateReferenceSystem &srs )
// it in the ctor of the layer projection selector

QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog();
mySelector->setMessage( srs.validationHint() ); //shows a generic message, if not specified
const QString validationHint = srs.validationHint();
if ( !validationHint.isEmpty() )
mySelector->setMessage( validationHint );
else
mySelector->showNoCrsForLayerMessage();

if ( sAuthId.isNull() )
sAuthId = QgsProject::instance()->crs().authid();

@@ -11753,7 +11758,10 @@ void QgisApp::setLayerCrs()

QgsProjectionSelectionDialog mySelector( this );
mySelector.setCrs( mLayerTreeView->currentLayer()->crs() );
mySelector.setMessage( QString() );

if ( !mLayerTreeView->currentLayer()->crs().isValid() )
mySelector.showNoCrsForLayerMessage();

if ( !mySelector.exec() )
{
QApplication::restoreOverrideCursor();
@@ -11932,7 +11940,6 @@ void QgisApp::legendGroupSetCrs()
return;

QgsProjectionSelectionDialog mySelector( this );
mySelector.setMessage( QString() );
if ( !mySelector.exec() )
{
QApplication::restoreOverrideCursor();
@@ -39,7 +39,7 @@ void QgsLayerTreeViewNoCrsIndicatorProvider::onIndicatorClicked( const QModelInd
return;

QgsProjectionSelectionDialog selector( QgisApp::instance() );
selector.setMessage( QString() );
selector.showNoCrsForLayerMessage();
if ( selector.exec() )
{
QgsCoordinateReferenceSystem crs = selector.crs();
@@ -223,7 +223,6 @@ void QgsNewSpatialiteLayerDialog::pbnFindSRID_clicked()
{
// prepare projection selector
QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
mySelector->setMessage( QString() );
mySelector->setOgcWmsCrsFilter( myCRSs );
mySelector->setCrs( QgsCoordinateReferenceSystem::fromOgcWmsCrs( mCrsId ) );

@@ -1776,7 +1776,6 @@ void QgsProjectProperties::pbnWMSExtCanvas_clicked()
void QgsProjectProperties::pbnWMSAddSRS_clicked()
{
QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
mySelector->setMessage( QString() );
if ( mWMSList->count() > 0 )
{
mySelector->setCrs( QgsCoordinateReferenceSystem::fromOgcWmsCrs( mWMSList->item( mWMSList->count() - 1 )->text() ) );
@@ -389,14 +389,17 @@ void QgsOWSSourceSelect::mChangeCRSButton_clicked()
}

QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
mySelector->setMessage( QString() );
mySelector->setOgcWmsCrsFilter( mSelectedLayersCRSs );

QgsCoordinateReferenceSystem defaultCRS = QgsProject::instance()->crs();
if ( defaultCRS.isValid() )
{
mySelector->setCrs( defaultCRS );
}
else
{
mySelector->showNoCrsForLayerMessage();
}

if ( !mySelector->exec() )
return;
@@ -49,24 +49,19 @@ QgsProjectionSelectionDialog::~QgsProjectionSelectionDialog()

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 ( m.isEmpty() )
{
// Set up text edit pane
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." );
m = QStringLiteral( "%1 %2" ).arg( sentence1, sentence2 );
}

QString myStyle = QgsApplication::reportStyleSheet();
m = "<head><style>" + myStyle + "</style></head><body>" + m + "</body>";
textEdit->setHtml( m );
textEdit->setHtml( QStringLiteral( "<head><style>%1</style></head><body>%2</body>" ).arg( QgsApplication::reportStyleSheet(),
message ) );
textEdit->show();
}

void QgsProjectionSelectionDialog::showNoCrsForLayerMessage()
{
setMessage( tr( "This layer appears to have no projection specification." )
+ ' '
+ 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." ) );
}

void QgsProjectionSelectionDialog::setShowNoProjection( bool show )
{
projectionSelector->setShowNoProjection( show );
@@ -69,12 +69,20 @@ class GUI_EXPORT QgsProjectionSelectionDialog : public QDialog, private Ui::QgsG
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'.
* Sets a \a message to show in the dialog.
*
* \see showNoCrsForLayerMessage()
*/
void setMessage( const QString &message );

/**
* When called, the dialog will show a default "layer has no CRS set" message above the projection selector.
*
* \see setMessage()
* \since QGIS 3.16
*/
void showNoCrsForLayerMessage();

/**
* Sets whether a "no/invalid" projection option should be shown. If this
* option is selected, calling crs() will return an invalid QgsCoordinateReferenceSystem.
@@ -159,7 +159,9 @@ void QgsVirtualLayerSourceSelect::browseCRS()
QgsCoordinateReferenceSystem crs( mSrid );
Q_NOWARN_DEPRECATED_POP
crsSelector.setCrs( crs );
crsSelector.setMessage( QString() );
if ( !crs.isValid() )
crsSelector.showNoCrsForLayerMessage();

if ( crsSelector.exec() )
{
mCRS->setText( crsSelector.crs().authid() );
@@ -647,14 +647,17 @@ void QgsWMSSourceSelect::btnChangeSpatialRefSys_clicked()
}

QgsProjectionSelectionDialog *mySelector = new QgsProjectionSelectionDialog( this );
mySelector->setMessage( QString() );
mySelector->setOgcWmsCrsFilter( mCRSs );

QgsCoordinateReferenceSystem defaultCRS = QgsProject::instance()->crs();
if ( defaultCRS.isValid() )
{
mySelector->setCrs( defaultCRS );
}
else
{
mySelector->showNoCrsForLayerMessage();
}

if ( !mySelector->exec() )
return;

0 comments on commit c68d05c

Please sign in to comment.
You can’t perform that action at this time.