By default, QgsProjectionSelectionTreeWidget should only

show horizontal (and compound) CRS in order to match behavior
of older releases

But allow opt in filters for display of vertical crs
This commit is contained in:
Nyall Dawson 2023-07-12 09:17:47 +10:00
parent ef6057aadd
commit 8c91e8fa97
5 changed files with 67 additions and 6 deletions

View File

@ -172,6 +172,9 @@ Returns whether deprecated CRS will be filtered from the results.
};
QFlags<QgsCoordinateReferenceSystemProxyModel::Filter> operator|(QgsCoordinateReferenceSystemProxyModel::Filter f1, QFlags<QgsCoordinateReferenceSystemProxyModel::Filter> f2);
/************************************************************************
* This file has been generated automatically from *

View File

@ -32,9 +32,14 @@ suitable to use the compact :py:class:`QgsProjectionSelectionWidget` widget.
%End
public:
QgsProjectionSelectionTreeWidget( QWidget *parent /TransferThis/ = 0 );
QgsProjectionSelectionTreeWidget( QWidget *parent /TransferThis/ = 0,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
%Docstring
Constructor for QgsProjectionSelectionTreeWidget.
Constructor for QgsProjectionSelectionTreeWidget, with the specified ``parent`` widget.
Since QGIS 3.34, 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
~QgsProjectionSelectionTreeWidget();
@ -109,6 +114,24 @@ The initial "preview" rectangle for the bounds overview map.
.. seealso:: :py:func:`previewRect`
.. versionadded:: 3.0
%End
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
%Docstring
Returns the filters set on the available CRS.
.. seealso:: :py:func:`setFilters`
.. versionadded:: 3.34
%End
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
%Docstring
Sets ``filters`` for the available CRS.
.. seealso:: :py:func:`filters`
.. versionadded:: 3.34
%End
public slots:

View File

@ -397,5 +397,7 @@ class GUI_EXPORT QgsCoordinateReferenceSystemProxyModel: public QSortFilterProxy
Filters mFilters = Filters();
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsCoordinateReferenceSystemProxyModel::Filters )
#endif // QGSCOORDINATEREFERENCESYSTEMMODEL_H

View File

@ -36,12 +36,14 @@
#include <QMessageBox>
#include <QRegularExpression>
QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *parent )
QgsProjectionSelectionTreeWidget::QgsProjectionSelectionTreeWidget( QWidget *parent, QgsCoordinateReferenceSystemProxyModel::Filters filters )
: QWidget( parent )
{
setupUi( this );
mCrsModel = new QgsCoordinateReferenceSystemProxyModel( this );
mCrsModel->setFilters( filters );
lstCoordinateSystems->setModel( mCrsModel );
lstCoordinateSystems->setSelectionBehavior( QAbstractItemView::SelectRows );
@ -253,6 +255,16 @@ QgsRectangle QgsProjectionSelectionTreeWidget::previewRect() const
return mAreaCanvas->canvasRect();
}
QgsCoordinateReferenceSystemProxyModel::Filters QgsProjectionSelectionTreeWidget::filters() const
{
return mCrsModel->filters();
}
void QgsProjectionSelectionTreeWidget::setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters )
{
mCrsModel->setFilters( filters );
}
QgsCoordinateReferenceSystem QgsProjectionSelectionTreeWidget::crs() const
{
if ( mCheckBoxNoProjection->isEnabled() && mCheckBoxNoProjection->isChecked() )

View File

@ -19,9 +19,9 @@
#include "qgis_sip.h"
#include "qgis_gui.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatereferencesystemmodel.h"
class QResizeEvent;
class QgsCoordinateReferenceSystemProxyModel;
/**
* \class QgsProjectionSelectionTreeWidget
@ -44,9 +44,14 @@ class GUI_EXPORT QgsProjectionSelectionTreeWidget : public QWidget, private Ui::
public:
/**
* Constructor for QgsProjectionSelectionTreeWidget.
* Constructor for QgsProjectionSelectionTreeWidget, with the specified \a parent widget.
*
* Since QGIS 3.34, 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.
*/
QgsProjectionSelectionTreeWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
QgsProjectionSelectionTreeWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr,
QgsCoordinateReferenceSystemProxyModel::Filters filters = QgsCoordinateReferenceSystemProxyModel::FilterHorizontal | QgsCoordinateReferenceSystemProxyModel::FilterCompound );
~QgsProjectionSelectionTreeWidget() override;
@ -109,6 +114,22 @@ class GUI_EXPORT QgsProjectionSelectionTreeWidget : public QWidget, private Ui::
*/
QgsRectangle previewRect() const;
/**
* Returns the filters set on the available CRS.
*
* \see setFilters()
* \since QGIS 3.34
*/
QgsCoordinateReferenceSystemProxyModel::Filters filters() const;
/**
* Sets \a filters for the available CRS.
*
* \see filters()
* \since QGIS 3.34
*/
void setFilters( QgsCoordinateReferenceSystemProxyModel::Filters filters );
public slots:
/**