Skip to content
Permalink
Browse files

Add support for filtering style model by 3d layer type

  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent d65b52d commit a0e915fc50591b24acdb7cc0db86f04a2b42126b
@@ -218,7 +218,7 @@ no effect on non-symbol entities (i.e. color ramps).
Returns the layer type filter, or QgsWkbTypes.UnknownGeometry if no
layer type filter is present.

This setting has no effect on non-label settings entities (i.e. color ramps).
This setting has an effect on label settings entities and 3d symbols only.

.. seealso:: :py:func:`setLayerType`
%End
@@ -58,7 +58,7 @@ Sets the ``type`` of symbols to show in the widget.
Sets the layer ``type`` to show in the widget. Set ``type`` to QgsWkbTypes.UnknownGeometry if no
layer type filter is desired.

This setting only applies to label settings style entities.
This setting only applies to label settings and 3d style entities.
%End

QString currentTagFilter() const;
@@ -738,9 +738,34 @@ bool QgsStyleProxyModel::filterAcceptsRow( int source_row, const QModelIndex &so
if ( mSymbolTypeFilterEnabled && symbolType != mSymbolType )
return false;

if ( styleEntityType == QgsStyle::LabelSettingsEntity && mLayerType != QgsWkbTypes::UnknownGeometry &&
mLayerType != static_cast< QgsWkbTypes::GeometryType >( sourceModel()->data( index, QgsStyleModel::LayerTypeRole ).toInt() ) )
return false;
if ( mLayerType != QgsWkbTypes::UnknownGeometry )
{
switch ( styleEntityType )
{
case QgsStyle::SymbolEntity:
case QgsStyle::TextFormatEntity:
case QgsStyle::TagEntity:
case QgsStyle::ColorrampEntity:
case QgsStyle::SmartgroupEntity:
case QgsStyle::LegendPatchShapeEntity:
break;

case QgsStyle::LabelSettingsEntity:
{
if ( mLayerType != static_cast< QgsWkbTypes::GeometryType >( sourceModel()->data( index, QgsStyleModel::LayerTypeRole ).toInt() ) )
return false;
break;
}

case QgsStyle::Symbol3DEntity:
{
const QVariantList types = sourceModel()->data( index, QgsStyleModel::CompatibleGeometryTypesRole ).toList();
if ( !types.empty() && !types.contains( mLayerType ) )
return false;
break;
}
}
}

if ( mTagId >= 0 && !mTaggedSymbolNames.contains( name ) )
return false;
@@ -252,7 +252,7 @@ class CORE_EXPORT QgsStyleProxyModel: public QSortFilterProxyModel
* Returns the layer type filter, or QgsWkbTypes::UnknownGeometry if no
* layer type filter is present.
*
* This setting has no effect on non-label settings entities (i.e. color ramps).
* This setting has an effect on label settings entities and 3d symbols only.
*
* \see setLayerType()
*/
@@ -37,6 +37,7 @@ class Dummy3dSymbol(QgsAbstract3DSymbol):

def __init__(self):
super().__init__()
self.layer_types = [int(QgsWkbTypes.PointGeometry), int(QgsWkbTypes.LineGeometry)]

@staticmethod
def create():
@@ -55,7 +56,7 @@ def writeXml(self, elem, context):
pass

def compatibleGeometryTypes(self):
return [int(QgsWkbTypes.PointGeometry), int(QgsWkbTypes.LineGeometry)]
return self.layer_types


def createMarkerSymbol():
@@ -2012,8 +2013,10 @@ def test_filter_proxy(self):
self.assertTrue(style.addSymbol3D('sym3d a', symbol3d_a, True))
style.tagSymbol(QgsStyle.Symbol3DEntity, 'sym3d a', ['tag 1', 'tag 2'])
symbol3d_B = Dummy3dSymbol()
symbol3d_B.layer_types = [2]
self.assertTrue(style.addSymbol3D('sym3d BB', symbol3d_B, True))
symbol3d_B = Dummy3dSymbol()
symbol3d_B.layer_types = [1]
self.assertTrue(style.addSymbol3D('sym3d c', symbol3d_B, True))

model = QgsStyleProxyModel(style)
@@ -2516,6 +2519,22 @@ def test_filter_proxy(self):
model.setLayerType(QgsWkbTypes.UnknownGeometry)
self.assertEqual(model.rowCount(), 3)

model.setEntityFilter(QgsStyle.Symbol3DEntity)
model.setEntityFilterEnabled(True)
self.assertEqual(model.rowCount(), 3)
model.setLayerType(QgsWkbTypes.PointGeometry)
self.assertEqual(model.rowCount(), 1)
self.assertEqual(model.data(model.index(0, 0)), 'sym3d a')
model.setLayerType(QgsWkbTypes.LineGeometry)
self.assertEqual(model.rowCount(), 2)
self.assertEqual(model.data(model.index(0, 0)), 'sym3d a')
self.assertEqual(model.data(model.index(1, 0)), 'x')
model.setLayerType(QgsWkbTypes.PolygonGeometry)
self.assertEqual(model.rowCount(), 1)
self.assertEqual(model.data(model.index(0, 0)), 'sym3d BB')
model.setLayerType(QgsWkbTypes.UnknownGeometry)
self.assertEqual(model.rowCount(), 3)

def testIconSize(self):
"""
Test that model has responsive icon sizes for decorations

0 comments on commit a0e915f

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