Skip to content

Commit

Permalink
Fix paper-cut when selecting projection from widget where it looks
Browse files Browse the repository at this point in the history
like the user has made a selection, but they've only selected one
of the projection category headings and so when they click OK they
see no change.

Now instead we disable the OK button in this dialog whenever the
user has a non-crs list item selected.
  • Loading branch information
nyalldawson committed Jan 29, 2021
1 parent ea57cfe commit 7b28cc6
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/gui/auto_generated/qgsprojectionselectiondialog.sip.in
Expand Up @@ -97,6 +97,14 @@ Sets the text to show for the not set option. Note that this option is not shown
by default and must be set visible by calling :py:func:`~QgsProjectionSelectionDialog.setShowNoProjection`.

.. versionadded:: 3.16
%End

void setRequireValidSelection();
%Docstring
Sets the dialog to require a valid selection only, preventing users from accepting the
dialog if no selection is present.

.. versionadded:: 3.18
%End

public slots:
Expand Down
Expand Up @@ -171,6 +171,13 @@ Notifies others that the widget is now fully initialized, including deferred sel
Emitted when a projection is double clicked in the list.

.. versionadded:: 2.14
%End

void hasValidSelectionChanged( bool isValid );
%Docstring
Emitted when the selection in the tree is changed from a valid selection to an invalid selection, or vice-versa.

.. versionadded:: 3.18
%End

protected:
Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsprojectionselectiondialog.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgshelp.h"
#include <QApplication>
#include "qgsgui.h"
#include <QPushButton>

QgsProjectionSelectionDialog::QgsProjectionSelectionDialog( QWidget *parent,
Qt::WindowFlags fl )
Expand Down Expand Up @@ -77,6 +78,16 @@ void QgsProjectionSelectionDialog::setNotSetText( const QString &text )
projectionSelector->setNotSetText( text );
}

void QgsProjectionSelectionDialog::setRequireValidSelection()
{
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( projectionSelector->hasValidSelection() );

connect( projectionSelector, &QgsProjectionSelectionTreeWidget::hasValidSelectionChanged, this, [ = ]( bool isValid )
{
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( isValid );
} );
}

QgsCoordinateReferenceSystem QgsProjectionSelectionDialog::crs() const
{
return projectionSelector->crs();
Expand Down
8 changes: 8 additions & 0 deletions src/gui/qgsprojectionselectiondialog.h
Expand Up @@ -106,6 +106,14 @@ class GUI_EXPORT QgsProjectionSelectionDialog : public QDialog, private Ui::QgsG
*/
void setNotSetText( const QString &text );

/**
* Sets the dialog to require a valid selection only, preventing users from accepting the
* dialog if no selection is present.
*
* \since QGIS 3.18
*/
void setRequireValidSelection();

public slots:

/**
Expand Down
15 changes: 15 additions & 0 deletions src/gui/qgsprojectionselectiontreewidget.cpp
Expand Up @@ -79,7 +79,10 @@ QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *par
connect( mCheckBoxNoProjection, &QCheckBox::toggled, this, [ = ]
{
if ( !mBlockSignals )
{
emit crsSelected();
emit hasValidSelectionChanged( hasValidSelection() );
}
} );
connect( mCheckBoxNoProjection, &QCheckBox::toggled, this, [ = ]( bool checked )
{
Expand Down Expand Up @@ -297,6 +300,7 @@ void QgsProjectionSelectionTreeWidget::setCrs( const QgsCoordinateReferenceSyste
if ( changed )
{
emit crsSelected();
emit hasValidSelectionChanged( hasValidSelection() );
}
}
}
Expand Down Expand Up @@ -484,6 +488,7 @@ void QgsProjectionSelectionTreeWidget::loadUserCrsList( QSet<QString> *crsFilter
// User defined coordinate system node
// Make in an italic font to distinguish them from real projections
mUserProjList = new QTreeWidgetItem( lstCoordinateSystems, QStringList( tr( "User Defined Coordinate Systems" ) ) );
mUserProjList->setFlags( mUserProjList->flags() & ~Qt::ItemIsSelectable );

QFont fontTemp = mUserProjList->font( 0 );
fontTemp.setItalic( true );
Expand Down Expand Up @@ -519,6 +524,7 @@ void QgsProjectionSelectionTreeWidget::loadCrsList( QSet<QString> *crsFilter )
//
// Geographic coordinate system node
mGeoList = new QTreeWidgetItem( lstCoordinateSystems, QStringList( tr( "Geographic Coordinate Systems" ) ) );
mGeoList->setFlags( mGeoList->flags() & ~Qt::ItemIsSelectable );

QFont fontTemp = mGeoList->font( 0 );
fontTemp.setItalic( true );
Expand All @@ -528,6 +534,7 @@ void QgsProjectionSelectionTreeWidget::loadCrsList( QSet<QString> *crsFilter )

// Projected coordinate system node
mProjList = new QTreeWidgetItem( lstCoordinateSystems, QStringList( tr( "Projected Coordinate Systems" ) ) );
mProjList->setFlags( mProjList->flags() & ~Qt::ItemIsSelectable );

fontTemp = mProjList->font( 0 );
fontTemp.setItalic( true );
Expand Down Expand Up @@ -614,6 +621,8 @@ void QgsProjectionSelectionTreeWidget::loadCrsList( QSet<QString> *crsFilter )
// the node doesn't exist -- create it
// Make in an italic font to distinguish them from real projections
node = new QTreeWidgetItem( mProjList, QStringList( srsType ) );
node->setFlags( node->flags() & ~Qt::ItemIsSelectable );

QFont fontTemp = node->font( 0 );
fontTemp.setItalic( true );
node->setFont( 0, fontTemp );
Expand Down Expand Up @@ -656,6 +665,8 @@ void QgsProjectionSelectionTreeWidget::loadUnknownCrs( const QgsCoordinateRefere
if ( !mUnknownList )
{
mUnknownList = new QTreeWidgetItem( lstCoordinateSystems, QStringList( tr( "Custom Coordinate Systems" ) ) );
mUnknownList->setFlags( mUnknownList->flags() & ~Qt::ItemIsSelectable );

QFont fontTemp = mUnknownList->font( 0 );
fontTemp.setItalic( true );
fontTemp.setBold( true );
Expand Down Expand Up @@ -689,7 +700,10 @@ void QgsProjectionSelectionTreeWidget::lstCoordinateSystems_currentItemChanged(
{
// Found a real CRS
if ( !mBlockSignals )
{
emit crsSelected();
emit hasValidSelectionChanged( true );
}

updateBoundsPreview();

Expand Down Expand Up @@ -721,6 +735,7 @@ void QgsProjectionSelectionTreeWidget::lstCoordinateSystems_currentItemChanged(
current->setSelected( false );
teProjection->clear();
lstRecent->clearSelection();
emit hasValidSelectionChanged( false );
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsprojectionselectiontreewidget.h
Expand Up @@ -162,6 +162,13 @@ class GUI_EXPORT QgsProjectionSelectionTreeWidget : public QWidget, private Ui::
*/
void projectionDoubleClicked();

/**
* Emitted when the selection in the tree is changed from a valid selection to an invalid selection, or vice-versa.
*
* \since QGIS 3.18
*/
void hasValidSelectionChanged( bool isValid );

protected:
// Used to ensure the projection list view is actually populated
void showEvent( QShowEvent *event ) override;
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsprojectionselectionwidget.cpp
Expand Up @@ -190,6 +190,7 @@ void QgsProjectionSelectionWidget::selectCrs()
{
dlg.setShowNoProjection( true );
}
dlg.setRequireValidSelection();

if ( dlg.exec() )
{
Expand Down

0 comments on commit 7b28cc6

Please sign in to comment.