Skip to content

Commit

Permalink
move enum QgsMapLayerProxyModel::Filter to Qgis (#54891)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored Oct 11, 2023
1 parent 6467a47 commit c76b86e
Show file tree
Hide file tree
Showing 44 changed files with 317 additions and 211 deletions.
2 changes: 1 addition & 1 deletion python/core/additions/qgssettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _qgssettings_flag_value(self, key, flagDefaultValue, section=QgsSettings.NoS
"""

# There is an issue in SIP, flags.__class__ does not return the proper class
# (e.g. Filters instead of QgsMapLayerProxyModel.Filters)
# (e.g. Filters instead of Qgis.LayerFilters)
# dirty hack to get the parent class
__import__(flagDefaultValue.__module__)
baseClass = None
Expand Down
54 changes: 54 additions & 0 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,60 @@
Qgis.LayerType.__doc__ = "Types of layers that can be added to a map\n\n.. versionadded:: 3.30.\n\n" + '* ``VectorLayer``: ' + Qgis.LayerType.Vector.__doc__ + '\n' + '* ``RasterLayer``: ' + Qgis.LayerType.Raster.__doc__ + '\n' + '* ``PluginLayer``: ' + Qgis.LayerType.Plugin.__doc__ + '\n' + '* ``MeshLayer``: ' + Qgis.LayerType.Mesh.__doc__ + '\n' + '* ``VectorTileLayer``: ' + Qgis.LayerType.VectorTile.__doc__ + '\n' + '* ``AnnotationLayer``: ' + Qgis.LayerType.Annotation.__doc__ + '\n' + '* ``PointCloudLayer``: ' + Qgis.LayerType.PointCloud.__doc__ + '\n' + '* ``GroupLayer``: ' + Qgis.LayerType.Group.__doc__ + '\n' + '* ``TiledScene``: ' + Qgis.LayerType.TiledScene.__doc__
# --
Qgis.LayerType.baseClass = Qgis
QgsMapLayerProxyModel.Filter = Qgis.LayerFilter
# monkey patching scoped based enum
QgsMapLayerProxyModel.RasterLayer = Qgis.LayerFilter.RasterLayer
QgsMapLayerProxyModel.RasterLayer.is_monkey_patched = True
QgsMapLayerProxyModel.RasterLayer.__doc__ = ""
QgsMapLayerProxyModel.NoGeometry = Qgis.LayerFilter.NoGeometry
QgsMapLayerProxyModel.NoGeometry.is_monkey_patched = True
QgsMapLayerProxyModel.NoGeometry.__doc__ = ""
QgsMapLayerProxyModel.PointLayer = Qgis.LayerFilter.PointLayer
QgsMapLayerProxyModel.PointLayer.is_monkey_patched = True
QgsMapLayerProxyModel.PointLayer.__doc__ = ""
QgsMapLayerProxyModel.LineLayer = Qgis.LayerFilter.LineLayer
QgsMapLayerProxyModel.LineLayer.is_monkey_patched = True
QgsMapLayerProxyModel.LineLayer.__doc__ = ""
QgsMapLayerProxyModel.PolygonLayer = Qgis.LayerFilter.PolygonLayer
QgsMapLayerProxyModel.PolygonLayer.is_monkey_patched = True
QgsMapLayerProxyModel.PolygonLayer.__doc__ = ""
QgsMapLayerProxyModel.HasGeometry = Qgis.LayerFilter.HasGeometry
QgsMapLayerProxyModel.HasGeometry.is_monkey_patched = True
QgsMapLayerProxyModel.HasGeometry.__doc__ = ""
QgsMapLayerProxyModel.VectorLayer = Qgis.LayerFilter.VectorLayer
QgsMapLayerProxyModel.VectorLayer.is_monkey_patched = True
QgsMapLayerProxyModel.VectorLayer.__doc__ = ""
QgsMapLayerProxyModel.PluginLayer = Qgis.LayerFilter.PluginLayer
QgsMapLayerProxyModel.PluginLayer.is_monkey_patched = True
QgsMapLayerProxyModel.PluginLayer.__doc__ = ""
QgsMapLayerProxyModel.WritableLayer = Qgis.LayerFilter.WritableLayer
QgsMapLayerProxyModel.WritableLayer.is_monkey_patched = True
QgsMapLayerProxyModel.WritableLayer.__doc__ = ""
QgsMapLayerProxyModel.MeshLayer = Qgis.LayerFilter.MeshLayer
QgsMapLayerProxyModel.MeshLayer.is_monkey_patched = True
QgsMapLayerProxyModel.MeshLayer.__doc__ = "QgsMeshLayer \since QGIS 3.6"
QgsMapLayerProxyModel.VectorTileLayer = Qgis.LayerFilter.VectorTileLayer
QgsMapLayerProxyModel.VectorTileLayer.is_monkey_patched = True
QgsMapLayerProxyModel.VectorTileLayer.__doc__ = "QgsVectorTileLayer \since QGIS 3.14"
QgsMapLayerProxyModel.PointCloudLayer = Qgis.LayerFilter.PointCloudLayer
QgsMapLayerProxyModel.PointCloudLayer.is_monkey_patched = True
QgsMapLayerProxyModel.PointCloudLayer.__doc__ = "QgsPointCloudLayer \since QGIS 3.18"
QgsMapLayerProxyModel.AnnotationLayer = Qgis.LayerFilter.AnnotationLayer
QgsMapLayerProxyModel.AnnotationLayer.is_monkey_patched = True
QgsMapLayerProxyModel.AnnotationLayer.__doc__ = "QgsAnnotationLayer \since QGIS 3.22"
QgsMapLayerProxyModel.TiledSceneLayer = Qgis.LayerFilter.TiledSceneLayer
QgsMapLayerProxyModel.TiledSceneLayer.is_monkey_patched = True
QgsMapLayerProxyModel.TiledSceneLayer.__doc__ = "QgsTiledSceneLayer \since QGIS 3.34"
QgsMapLayerProxyModel.All = Qgis.LayerFilter.All
QgsMapLayerProxyModel.All.is_monkey_patched = True
QgsMapLayerProxyModel.All.__doc__ = ""
QgsMapLayerProxyModel.SpatialLayer = Qgis.LayerFilter.SpatialLayer
QgsMapLayerProxyModel.SpatialLayer.is_monkey_patched = True
QgsMapLayerProxyModel.SpatialLayer.__doc__ = "\since QGIS 3.24"
Qgis.LayerFilter.__doc__ = "Filter for layers\n\n.. versionadded:: 3.34.\n\n" + '* ``RasterLayer``: ' + Qgis.LayerFilter.RasterLayer.__doc__ + '\n' + '* ``NoGeometry``: ' + Qgis.LayerFilter.NoGeometry.__doc__ + '\n' + '* ``PointLayer``: ' + Qgis.LayerFilter.PointLayer.__doc__ + '\n' + '* ``LineLayer``: ' + Qgis.LayerFilter.LineLayer.__doc__ + '\n' + '* ``PolygonLayer``: ' + Qgis.LayerFilter.PolygonLayer.__doc__ + '\n' + '* ``HasGeometry``: ' + Qgis.LayerFilter.HasGeometry.__doc__ + '\n' + '* ``VectorLayer``: ' + Qgis.LayerFilter.VectorLayer.__doc__ + '\n' + '* ``PluginLayer``: ' + Qgis.LayerFilter.PluginLayer.__doc__ + '\n' + '* ``WritableLayer``: ' + Qgis.LayerFilter.WritableLayer.__doc__ + '\n' + '* ``MeshLayer``: ' + Qgis.LayerFilter.MeshLayer.__doc__ + '\n' + '* ``VectorTileLayer``: ' + Qgis.LayerFilter.VectorTileLayer.__doc__ + '\n' + '* ``PointCloudLayer``: ' + Qgis.LayerFilter.PointCloudLayer.__doc__ + '\n' + '* ``AnnotationLayer``: ' + Qgis.LayerFilter.AnnotationLayer.__doc__ + '\n' + '* ``TiledSceneLayer``: ' + Qgis.LayerFilter.TiledSceneLayer.__doc__ + '\n' + '* ``All``: ' + Qgis.LayerFilter.All.__doc__ + '\n' + '* ``SpatialLayer``: ' + Qgis.LayerFilter.SpatialLayer.__doc__
# --
Qgis.LayerFilters.baseClass = Qgis
LayerFilters = Qgis # dirty hack since SIP seems to introduce the flags in module
QgsWkbTypes.Type = Qgis.WkbType
# monkey patching scoped based enum
QgsWkbTypes.Unknown = Qgis.WkbType.Unknown
Expand Down
3 changes: 0 additions & 3 deletions python/core/auto_additions/qgsmaplayerproxymodel.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Rerturns the layer tree model
Sets the layer tree model
%End

void setFilters( const QgsMapLayerProxyModel::Filters &filters );
void setFilters( Qgis::LayerFilters filters );
%Docstring
Defines the type layers (vector, raster, etc) shown in the tree
If the list is empty, all types are shown.
Expand Down
24 changes: 24 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ The development version
TiledScene,
};

enum class LayerFilter
{
RasterLayer,
NoGeometry,
PointLayer,
LineLayer,
PolygonLayer,
HasGeometry,
VectorLayer,
PluginLayer,
WritableLayer,
MeshLayer,
VectorTileLayer,
PointCloudLayer,
AnnotationLayer,
TiledSceneLayer,
All,
SpatialLayer
};
typedef QFlags<Qgis::LayerFilter> LayerFilters;


enum class WkbType
{
Unknown,
Expand Down Expand Up @@ -2441,6 +2463,8 @@ QFlags<Qgis::TiledSceneRendererFlag> operator|(Qgis::TiledSceneRendererFlag f1,

QFlags<Qgis::FieldConfigurationFlag> operator|(Qgis::FieldConfigurationFlag f1, QFlags<Qgis::FieldConfigurationFlag> f2);

QFlags<Qgis::LayerFilter> operator|(Qgis::LayerFilter f1, QFlags<Qgis::LayerFilter> f2);




Expand Down
44 changes: 17 additions & 27 deletions python/core/auto_generated/qgsmaplayerproxymodel.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,6 @@ The :py:class:`QgsMapLayerProxyModel` class provides an easy to use model to dis
#include "qgsmaplayerproxymodel.h"
%End
public:
enum Filter
{
RasterLayer,
NoGeometry,
PointLayer,
LineLayer,
PolygonLayer,
HasGeometry,
VectorLayer,
PluginLayer,
WritableLayer,
MeshLayer,
VectorTileLayer,
PointCloudLayer,
AnnotationLayer,
TiledSceneLayer,
All,
SpatialLayer
};
typedef QFlags<QgsMapLayerProxyModel::Filter> Filters;


explicit QgsMapLayerProxyModel( QObject *parent /TransferThis/ = 0 );
%Docstring
Expand All @@ -55,7 +34,7 @@ It can be used to filter the layers list in a widget.
layerModel returns the :py:class:`QgsMapLayerModel` used in this QSortFilterProxyModel
%End

QgsMapLayerProxyModel *setFilters( QgsMapLayerProxyModel::Filters filters );
QgsMapLayerProxyModel *setFilters( Qgis::LayerFilters filters );
%Docstring
Sets ``filter`` flags which affect how layers are filtered within the model.

Expand All @@ -64,7 +43,21 @@ Sets ``filter`` flags which affect how layers are filtered within the model.
.. versionadded:: 2.3
%End

const Filters &filters() const;
void setFilters( int filters ) /Deprecated/;
%Docstring
Filters according to layer type and/or geometry type.

.. note::

for API compatibility

.. versionadded:: 3.34

.. deprecated:: QGIS 3.34
use the flag signature instead
%End

const Qgis::LayerFilters &filters() const;
%Docstring
Returns the filter flags which affect how layers are filtered within the model.

Expand All @@ -82,7 +75,7 @@ If ``project`` is ``None`` then :py:func:`QgsProject.instance()` will be used.
.. versionadded:: 3.24
%End

static bool layerMatchesFilters( const QgsMapLayer *layer, const Filters &filters );
static bool layerMatchesFilters( const QgsMapLayer *layer, const Qgis::LayerFilters &filters );
%Docstring
Returns if the ``layer`` matches the given ``filters``

Expand Down Expand Up @@ -238,9 +231,6 @@ specified string will be shown.

};

QFlags<QgsMapLayerProxyModel::Filter> operator|(QgsMapLayerProxyModel::Filter f1, QFlags<QgsMapLayerProxyModel::Filter> f2);


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
20 changes: 17 additions & 3 deletions python/gui/auto_generated/qgsmaplayercombobox.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,26 @@ QgsMapLayerComboBox creates a combo box to display the list of layers (currently
The layers can be filtered and/or ordered.
%End

void setFilters( QgsMapLayerProxyModel::Filters filters );
void setFilters( Qgis::LayerFilters filters );
%Docstring
setFilters allows filtering according to layer type and/or geometry type.
Filters according to layer type and/or geometry type.
%End

QgsMapLayerProxyModel::Filters filters() const;
void setFilters( int filters ) /Deprecated/;
%Docstring
Filters according to layer type and/or geometry type.

.. note::

for API compatibility

.. versionadded:: 3.34

.. deprecated:: QGIS 3.34
use the flag signature instead
%End

Qgis::LayerFilters filters() const;
%Docstring
currently used filter on list layers
%End
Expand Down
25 changes: 14 additions & 11 deletions python/plugins/processing/algs/qgis/ui/InterpolationWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@
from qgis.PyQt.QtCore import pyqtSignal
from qgis.PyQt.QtWidgets import (QTreeWidgetItem,
QComboBox)
from qgis.core import (QgsApplication,
QgsMapLayerProxyModel,
QgsWkbTypes,
QgsRectangle,
QgsReferencedRectangle,
QgsCoordinateReferenceSystem,
QgsProcessingUtils,
QgsProcessingParameterNumber,
QgsProcessingParameterDefinition,
QgsFieldProxyModel)
from qgis.core import (
Qgis,
QgsApplication,
QgsMapLayerProxyModel,
QgsWkbTypes,
QgsRectangle,
QgsReferencedRectangle,
QgsCoordinateReferenceSystem,
QgsProcessingUtils,
QgsProcessingParameterNumber,
QgsProcessingParameterDefinition,
QgsFieldProxyModel
)
from qgis.gui import QgsDoubleSpinBox
from qgis.analysis import QgsInterpolator

Expand Down Expand Up @@ -99,7 +102,7 @@ def __init__(self):
self.btnRemove.clicked.connect(self.removeLayer)

self.cmbLayers.layerChanged.connect(self.layerChanged)
self.cmbLayers.setFilters(QgsMapLayerProxyModel.VectorLayer)
self.cmbLayers.setFilters(Qgis.LayerFilter.VectorLayer)
self.cmbFields.setFilters(QgsFieldProxyModel.Numeric)
self.cmbFields.setLayer(self.cmbLayers.currentLayer())

Expand Down
5 changes: 3 additions & 2 deletions python/plugins/processing/gui/ExtentSelectionPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

from qgis.gui import QgsMapLayerComboBox
from qgis.utils import iface
from qgis.core import (QgsProcessingParameterDefinition,
from qgis.core import (Qgis,
QgsProcessingParameterDefinition,
QgsProcessingParameters,
QgsProject,
QgsReferencedRectangle,
Expand All @@ -63,7 +64,7 @@ def __init__(self, parent=None):
vl.addWidget(QLabel(self.tr('Use extent from')))
self.combo = QgsMapLayerComboBox()
self.combo.setFilters(
QgsMapLayerProxyModel.HasGeometry | QgsMapLayerProxyModel.RasterLayer | QgsMapLayerProxyModel.MeshLayer)
Qgis.LayerFilter.HasGeometry | Qgis.LayerFilter.RasterLayer | Qgis.LayerFilter.MeshLayer)
self.combo.setShowCrs(ProcessingConfig.getSetting(ProcessingConfig.SHOW_CRS_DEF))
vl.addWidget(self.combo)

Expand Down
10 changes: 5 additions & 5 deletions src/app/3d/qgs3dmapconfigwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
mDebugDepthMapSizeSpinBox->setClearValue( 0.1 );

cboTerrainLayer->setAllowEmptyLayer( true );
cboTerrainLayer->setFilters( QgsMapLayerProxyModel::RasterLayer );
cboTerrainLayer->setFilters( Qgis::LayerFilter::RasterLayer );

cboTerrainType->addItem( tr( "Flat Terrain" ), QgsTerrainGenerator::Flat );
cboTerrainType->addItem( tr( "DEM (Raster Layer)" ), QgsTerrainGenerator::Dem );
Expand All @@ -109,7 +109,7 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
spinTerrainResolution->setValue( demTerrainGen->resolution() );
spinTerrainSkirtHeight->setValue( demTerrainGen->skirtHeight() );
cboTerrainLayer->setLayer( demTerrainGen->layer() );
cboTerrainLayer->setFilters( QgsMapLayerProxyModel::RasterLayer );
cboTerrainLayer->setFilters( Qgis::LayerFilter::RasterLayer );
}
else if ( terrainGen && terrainGen->type() == QgsTerrainGenerator::Online )
{
Expand All @@ -122,7 +122,7 @@ Qgs3DMapConfigWidget::Qgs3DMapConfigWidget( Qgs3DMapSettings *map, QgsMapCanvas
{
cboTerrainType->setCurrentIndex( cboTerrainType->findData( QgsTerrainGenerator::Mesh ) );
QgsMeshTerrainGenerator *meshTerrain = static_cast<QgsMeshTerrainGenerator *>( terrainGen );
cboTerrainLayer->setFilters( QgsMapLayerProxyModel::MeshLayer );
cboTerrainLayer->setFilters( Qgis::LayerFilter::MeshLayer );
cboTerrainLayer->setLayer( meshTerrain->meshLayer() );
mMeshSymbolWidget->setLayer( meshTerrain->meshLayer(), false );
mMeshSymbolWidget->setSymbol( meshTerrain->symbol() );
Expand Down Expand Up @@ -408,11 +408,11 @@ void Qgs3DMapConfigWidget::onTerrainTypeChanged()
QgsMapLayer *oldTerrainLayer = cboTerrainLayer->currentLayer();
if ( cboTerrainType->currentData() == QgsTerrainGenerator::Dem )
{
cboTerrainLayer->setFilters( QgsMapLayerProxyModel::RasterLayer );
cboTerrainLayer->setFilters( Qgis::LayerFilter::RasterLayer );
}
else if ( cboTerrainType->currentData() == QgsTerrainGenerator::Mesh )
{
cboTerrainLayer->setFilters( QgsMapLayerProxyModel::MeshLayer );
cboTerrainLayer->setFilters( Qgis::LayerFilter::MeshLayer );
}

if ( cboTerrainLayer->currentLayer() != oldTerrainLayer )
Expand Down
2 changes: 1 addition & 1 deletion src/app/gps/qgsgpstoolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ QgsGpsToolBar::QgsGpsToolBar( QgsAppGpsConnection *connection, QgsMapCanvas *can

mDestinationLayerModel = new QgsMapLayerProxyModel( this );
mDestinationLayerModel->setProject( QgsProject::instance() );
mDestinationLayerModel->setFilters( QgsMapLayerProxyModel::Filter::HasGeometry | QgsMapLayerProxyModel::Filter::WritableLayer );
mDestinationLayerModel->setFilters( Qgis::LayerFilter::HasGeometry | Qgis::LayerFilter::WritableLayer );

mDestinationLayerMenu = new QMenu( this );
connect( mDestinationLayerMenu, &QMenu::aboutToShow, this, &QgsGpsToolBar::destinationMenuAboutToShow );
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/qgsreportfieldgroupsectionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ QgsReportSectionFieldGroupWidget::QgsReportSectionFieldGroupWidget( QgsReportOrg
{
setupUi( this );

mLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
mLayerComboBox->setFilters( Qgis::LayerFilter::VectorLayer );
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, mFieldComboBox, &QgsFieldComboBox::setLayer );
connect( mButtonEditBody, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editBody );
connect( mButtonEditHeader, &QPushButton::clicked, this, &QgsReportSectionFieldGroupWidget::editHeader );
Expand Down
2 changes: 1 addition & 1 deletion src/app/mesh/qgsmeshcalculatordialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QgsMeshCalculatorDialog::QgsMeshCalculatorDialog( QgsMeshLayer *meshLayer, QWidg
setupUi( this );
QgsGui::enableAutoGeometryRestore( this );

cboLayerMask->setFilters( QgsMapLayerProxyModel::PolygonLayer );
cboLayerMask->setFilters( Qgis::LayerFilter::PolygonLayer );
QgsMeshDatasetGroupListModel *model = new QgsMeshDatasetGroupListModel( this );
model->syncToLayer( meshLayer );
model->setDisplayProviderName( true );
Expand Down
2 changes: 1 addition & 1 deletion src/app/mesh/qgsnewmeshlayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ QgsNewMeshLayerDialog::QgsNewMeshLayerDialog( QWidget *parent, Qt::WindowFlags f
mFormatComboBox->setCurrentIndex( -1 );
mFileWidget->setStorageMode( QgsFileWidget::SaveFile );
mFileWidget->setFilter( filters.join( QLatin1String( ";;" ) ) );
mMeshProjectComboBox->setFilters( QgsMapLayerProxyModel::MeshLayer );
mMeshProjectComboBox->setFilters( Qgis::LayerFilter::MeshLayer );

connect( mFormatComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ),
this, &QgsNewMeshLayerDialog::onFormatChanged );
Expand Down
4 changes: 2 additions & 2 deletions src/app/project/qgsprojectelevationsettingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ QgsProjectElevationSettingsWidget::QgsProjectElevationSettingsWidget( QWidget *p

mDemOffsetSpinBox->setClearValue( 0.0 );
mDemScaleSpinBox->setClearValue( 1.0 );
mComboDemLayer->setFilters( QgsMapLayerProxyModel::RasterLayer );
mComboDemLayer->setFilters( Qgis::LayerFilter::RasterLayer );

mMeshOffsetSpinBox->setClearValue( 0.0 );
mMeshScaleSpinBox->setClearValue( 1.0 );
mComboMeshLayer->setFilters( QgsMapLayerProxyModel::MeshLayer );
mComboMeshLayer->setFilters( Qgis::LayerFilter::MeshLayer );

mComboTerrainType->addItem( tr( "Flat Terrain" ), QStringLiteral( "flat" ) );
mComboTerrainType->addItem( tr( "DEM (Raster Layer)" ), QStringLiteral( "raster" ) );
Expand Down
Loading

0 comments on commit c76b86e

Please sign in to comment.