Add filter options for all crs selection widgets

This is a partial implementation -- we also should be filtering
the lists of recent crs to matching ones
This commit is contained in:
Nyall Dawson 2024-01-15 13:39:37 +10:00
parent cbc17eacb3
commit ddcc42ca85
8 changed files with 262 additions and 19 deletions

View File

@ -23,9 +23,14 @@ A generic widget allowing users to pick a Coordinate Reference System (or define
%End
public:
QgsCrsSelectionWidget( QWidget *parent /TransferThis/ = 0 );
QgsCrsSelectionWidget( QWidget *parent /TransferThis/ = 0,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
%Docstring
Constructor for QgsCrsSelectionWidget, with the specified ``parent`` widget.
Since QGIS 3.36, the optional ``filter`` argument can be used to specify filters on the systems
shown in the widget. The default is to show all horizontal and compound CRS in order to match
the behavior of older QGIS releases. The ``filter`` can be altered to also include vertical CRS if desired.
%End
~QgsCrsSelectionWidget();
@ -70,6 +75,24 @@ is shown when the option is selected.
bool hasValidSelection() const;
%Docstring
Returns ``True`` if the widget has a valid CRS defined.
%End
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
%Docstring
Returns the filters set on the available CRS.
.. seealso:: :py:func:`setFilters`
.. versionadded:: 3.36
%End
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
%Docstring
Sets ``filters`` for the available CRS.
.. seealso:: :py:func:`filters`
.. versionadded:: 3.36
%End
public slots:
@ -147,9 +170,14 @@ the you probably want to look at :py:class:`QgsProjectionSelectionWidget` instea
public:
QgsProjectionSelectionDialog( QWidget *parent /TransferThis/ = 0,
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
%Docstring
Constructor for QgsProjectionSelectionDialog.
Since QGIS 3.36, the optional ``filter`` argument can be used to specify filters on the systems
shown in the dialog. The default is to show all horizontal and compound CRS in order to match
the behavior of older QGIS releases. The ``filter`` can be altered to also include vertical CRS if desired.
%End
QgsCoordinateReferenceSystem crs() const;
@ -221,6 +249,24 @@ dialog if no selection is present.
Returns ``True`` if the dialog has a valid CRS defined.
.. versionadded:: 3.24
%End
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
%Docstring
Returns the filters set on the available CRS.
.. seealso:: :py:func:`setFilters`
.. versionadded:: 3.36
%End
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
%Docstring
Sets ``filters`` for the available CRS.
.. seealso:: :py:func:`filters`
.. versionadded:: 3.36
%End
public slots:

View File

@ -34,9 +34,14 @@ A widget for selecting a projection.
CrsNotSet,
};
explicit QgsProjectionSelectionWidget( QWidget *parent /TransferThis/ = 0 );
explicit QgsProjectionSelectionWidget( QWidget *parent /TransferThis/ = 0,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
%Docstring
Constructor for QgsProjectionSelectionWidget
Constructor for QgsProjectionSelectionWidget, with the specified ``parent`` widget.
Since QGIS 3.36, the optional ``filter`` argument can be used to specify filters on the systems
shown in the widget. The default is to show all horizontal and compound CRS in order to match
the behavior of older QGIS releases. The ``filter`` can be altered to also include vertical CRS if desired.
%End
QgsCoordinateReferenceSystem crs() const;
@ -150,6 +155,24 @@ Returns the title for the CRS selector dialog window.
Sets a filtered list of CRSes to show in the widget.
.. versionadded:: 3.28
%End
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
%Docstring
Returns the filters set on the available CRS.
.. seealso:: :py:func:`setFilters`
.. versionadded:: 3.36
%End
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
%Docstring
Sets ``filters`` for the available CRS.
.. seealso:: :py:func:`filters`
.. versionadded:: 3.36
%End
signals:

View File

@ -23,9 +23,14 @@ A generic widget allowing users to pick a Coordinate Reference System (or define
%End
public:
QgsCrsSelectionWidget( QWidget *parent /TransferThis/ = 0 );
QgsCrsSelectionWidget( QWidget *parent /TransferThis/ = 0,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
%Docstring
Constructor for QgsCrsSelectionWidget, with the specified ``parent`` widget.
Since QGIS 3.36, the optional ``filter`` argument can be used to specify filters on the systems
shown in the widget. The default is to show all horizontal and compound CRS in order to match
the behavior of older QGIS releases. The ``filter`` can be altered to also include vertical CRS if desired.
%End
~QgsCrsSelectionWidget();
@ -70,6 +75,24 @@ is shown when the option is selected.
bool hasValidSelection() const;
%Docstring
Returns ``True`` if the widget has a valid CRS defined.
%End
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
%Docstring
Returns the filters set on the available CRS.
.. seealso:: :py:func:`setFilters`
.. versionadded:: 3.36
%End
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
%Docstring
Sets ``filters`` for the available CRS.
.. seealso:: :py:func:`filters`
.. versionadded:: 3.36
%End
public slots:
@ -147,9 +170,14 @@ the you probably want to look at :py:class:`QgsProjectionSelectionWidget` instea
public:
QgsProjectionSelectionDialog( QWidget *parent /TransferThis/ = 0,
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
%Docstring
Constructor for QgsProjectionSelectionDialog.
Since QGIS 3.36, the optional ``filter`` argument can be used to specify filters on the systems
shown in the dialog. The default is to show all horizontal and compound CRS in order to match
the behavior of older QGIS releases. The ``filter`` can be altered to also include vertical CRS if desired.
%End
QgsCoordinateReferenceSystem crs() const;
@ -221,6 +249,24 @@ dialog if no selection is present.
Returns ``True`` if the dialog has a valid CRS defined.
.. versionadded:: 3.24
%End
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
%Docstring
Returns the filters set on the available CRS.
.. seealso:: :py:func:`setFilters`
.. versionadded:: 3.36
%End
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
%Docstring
Sets ``filters`` for the available CRS.
.. seealso:: :py:func:`filters`
.. versionadded:: 3.36
%End
public slots:

View File

@ -34,9 +34,14 @@ A widget for selecting a projection.
CrsNotSet,
};
explicit QgsProjectionSelectionWidget( QWidget *parent /TransferThis/ = 0 );
explicit QgsProjectionSelectionWidget( QWidget *parent /TransferThis/ = 0,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
%Docstring
Constructor for QgsProjectionSelectionWidget
Constructor for QgsProjectionSelectionWidget, with the specified ``parent`` widget.
Since QGIS 3.36, the optional ``filter`` argument can be used to specify filters on the systems
shown in the widget. The default is to show all horizontal and compound CRS in order to match
the behavior of older QGIS releases. The ``filter`` can be altered to also include vertical CRS if desired.
%End
QgsCoordinateReferenceSystem crs() const;
@ -150,6 +155,24 @@ Returns the title for the CRS selector dialog window.
Sets a filtered list of CRSes to show in the widget.
.. versionadded:: 3.28
%End
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
%Docstring
Returns the filters set on the available CRS.
.. seealso:: :py:func:`setFilters`
.. versionadded:: 3.36
%End
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
%Docstring
Sets ``filters`` for the available CRS.
.. seealso:: :py:func:`filters`
.. versionadded:: 3.36
%End
signals:

View File

@ -29,11 +29,14 @@
//
// QgsCrsSelectionWidget
//
QgsCrsSelectionWidget::QgsCrsSelectionWidget( QWidget *parent )
QgsCrsSelectionWidget::QgsCrsSelectionWidget( QWidget *parent,
QgsCoordinateReferenceSystemProxyModel::Filters filters )
: QgsPanelWidget( parent )
{
setupUi( this );
projectionSelector->setFilters( filters );
//we will show this only when a message is set
textEdit->hide();
@ -187,6 +190,16 @@ bool QgsCrsSelectionWidget::hasValidSelection() const
}
}
QgsCoordinateReferenceSystemProxyModel::Filters QgsCrsSelectionWidget::filters() const
{
return projectionSelector->filters();
}
void QgsCrsSelectionWidget::setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters )
{
projectionSelector->setFilters( filters );
}
QgsCoordinateReferenceSystem QgsCrsSelectionWidget::crs() const
{
if ( !mComboCrsType->currentData().isValid() )
@ -247,12 +260,12 @@ void QgsCrsSelectionWidget::setOgcWmsCrsFilter( const QSet<QString> &crsFilter )
//
QgsProjectionSelectionDialog::QgsProjectionSelectionDialog( QWidget *parent,
Qt::WindowFlags fl )
Qt::WindowFlags fl, QgsCoordinateReferenceSystemProxyModel::Filters filters )
: QDialog( parent, fl )
{
QVBoxLayout *vlayout = new QVBoxLayout();
mCrsWidget = new QgsCrsSelectionWidget();
mCrsWidget = new QgsCrsSelectionWidget( nullptr, filters );
vlayout->addWidget( mCrsWidget, 1 );
mButtonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
@ -314,6 +327,16 @@ bool QgsProjectionSelectionDialog::hasValidSelection() const
return mCrsWidget->hasValidSelection();
}
QgsCoordinateReferenceSystemProxyModel::Filters QgsProjectionSelectionDialog::filters() const
{
return mCrsWidget->filters();
}
void QgsProjectionSelectionDialog::setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters )
{
mCrsWidget->setFilters( filters );
}
QgsCoordinateReferenceSystem QgsProjectionSelectionDialog::crs() const
{
return mCrsWidget->crs();

View File

@ -43,8 +43,13 @@ class GUI_EXPORT QgsCrsSelectionWidget : public QgsPanelWidget, private Ui::QgsG
/**
* Constructor for QgsCrsSelectionWidget, with the specified \a parent widget.
*
* Since QGIS 3.36, the optional \a filter argument can be used to specify filters on the systems
* shown in the widget. The default is to show all horizontal and compound CRS in order to match
* the behavior of older QGIS releases. The \a filter can be altered to also include vertical CRS if desired.
*/
QgsCrsSelectionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
QgsCrsSelectionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
~QgsCrsSelectionWidget() override;
@ -87,6 +92,22 @@ class GUI_EXPORT QgsCrsSelectionWidget : public QgsPanelWidget, private Ui::QgsG
*/
bool hasValidSelection() const;
/**
* Returns the filters set on the available CRS.
*
* \see setFilters()
* \since QGIS 3.36
*/
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
/**
* Sets \a filters for the available CRS.
*
* \see filters()
* \since QGIS 3.36
*/
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
public slots:
/**
@ -174,9 +195,14 @@ class GUI_EXPORT QgsProjectionSelectionDialog : public QDialog
/**
* Constructor for QgsProjectionSelectionDialog.
*
* Since QGIS 3.36, the optional \a filter argument can be used to specify filters on the systems
* shown in the dialog. The default is to show all horizontal and compound CRS in order to match
* the behavior of older QGIS releases. The \a filter can be altered to also include vertical CRS if desired.
*/
QgsProjectionSelectionDialog( QWidget *parent SIP_TRANSFERTHIS = nullptr,
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags );
Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
/**
* Returns the CRS currently selected in the widget.
@ -242,6 +268,22 @@ class GUI_EXPORT QgsProjectionSelectionDialog : public QDialog
*/
bool hasValidSelection() const;
/**
* Returns the filters set on the available CRS.
*
* \see setFilters()
* \since QGIS 3.36
*/
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
/**
* Sets \a filters for the available CRS.
*
* \see filters()
* \since QGIS 3.36
*/
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
public slots:
/**

View File

@ -24,11 +24,12 @@
#include "qgscoordinatereferencesystemregistry.h"
#include "qgsdatums.h"
QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent )
QgsProjectionSelectionWidget::QgsProjectionSelectionWidget( QWidget *parent,
QgsCoordinateReferenceSystemProxyModel::Filters filters )
: QWidget( parent )
, mDialogTitle( tr( "Coordinate Reference System Selector" ) )
, mFilters( filters )
{
mCrsComboBox = new QgsHighlightableComboBox( this );
mCrsComboBox->addItem( tr( "invalid projection" ), QgsProjectionSelectionWidget::CurrentCrs );
mCrsComboBox->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );
@ -215,7 +216,7 @@ void QgsProjectionSelectionWidget::selectCrs()
if ( panel && panel->dockMode() )
{
mActivePanel = new QgsCrsSelectionWidget( this );
mActivePanel = new QgsCrsSelectionWidget( this, mFilters );
if ( !ogcFilter.isEmpty() )
mActivePanel->setOgcWmsCrsFilter( ogcFilter );
if ( !mMessage.isEmpty() )
@ -255,7 +256,7 @@ void QgsProjectionSelectionWidget::selectCrs()
}
else
{
QgsProjectionSelectionDialog dlg( this );
QgsProjectionSelectionDialog dlg( this, QgsGuiUtils::ModalDialogFlags, mFilters );
if ( !mMessage.isEmpty() )
dlg.setMessage( mMessage );
if ( !ogcFilter.isEmpty() )
@ -377,6 +378,19 @@ void QgsProjectionSelectionWidget::setFilter( const QList<QgsCoordinateReference
}
}
QgsCoordinateReferenceSystemProxyModel::Filters QgsProjectionSelectionWidget::filters() const
{
return mFilters;
}
void QgsProjectionSelectionWidget::setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters )
{
mFilters = filters;
if ( mActivePanel )
mActivePanel->setFilters( filters );
}
void QgsProjectionSelectionWidget::setSourceEnsemble( const QString &ensemble )
{
if ( mSourceEnsemble == ensemble )

View File

@ -25,6 +25,7 @@
#include <QPointer>
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatereferencesystemmodel.h"
#include "qgis_gui.h"
class QgsMapLayer;
@ -57,8 +58,15 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
CrsNotSet, //!< Not set (hidden by default)
};
//! Constructor for QgsProjectionSelectionWidget
explicit QgsProjectionSelectionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
/**
* Constructor for QgsProjectionSelectionWidget, with the specified \a parent widget.
*
* Since QGIS 3.36, the optional \a filter argument can be used to specify filters on the systems
* shown in the widget. The default is to show all horizontal and compound CRS in order to match
* the behavior of older QGIS releases. The \a filter can be altered to also include vertical CRS if desired.
*/
explicit QgsProjectionSelectionWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
/**
* Returns the currently selected CRS for the widget
@ -165,6 +173,22 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
*/
void setFilter( const QList< QgsCoordinateReferenceSystem > &crses );
/**
* Returns the filters set on the available CRS.
*
* \see setFilters()
* \since QGIS 3.36
*/
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
/**
* Sets \a filters for the available CRS.
*
* \see filters()
* \since QGIS 3.36
*/
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
signals:
/**
@ -228,6 +252,8 @@ class GUI_EXPORT QgsProjectionSelectionWidget : public QWidget
QList<QgsCoordinateReferenceSystem> mFilter;
QgsCoordinateReferenceSystemProxyModel::Filters mFilters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound;
void addNotSetOption();
void addProjectCrsOption();
void addDefaultCrsOption();