Skip to content
Permalink
Browse files

Add CompatibleGeometryTypesRole to style model

  • Loading branch information
nyalldawson committed Jul 29, 2020
1 parent 6245b55 commit d65b52db7752e44a16366fd337d97c3b78999ca7
@@ -43,6 +43,7 @@ instead.
SymbolTypeRole,
IsFavoriteRole,
LayerTypeRole,
CompatibleGeometryTypesRole,
};

explicit QgsStyleModel( QgsStyle *style, QObject *parent /TransferThis/ = 0 );
@@ -364,10 +364,49 @@ QVariant QgsStyleModel::data( const QModelIndex &index, int role ) const

case LayerTypeRole:
{
if ( entityType != QgsStyle::LabelSettingsEntity )
return QVariant();
switch ( entityType )
{
case QgsStyle::LabelSettingsEntity:
return mStyle->labelSettingsLayerType( name );

case QgsStyle::Symbol3DEntity:
case QgsStyle::SymbolEntity:
case QgsStyle::LegendPatchShapeEntity:
case QgsStyle::TagEntity:
case QgsStyle::ColorrampEntity:
case QgsStyle::SmartgroupEntity:
case QgsStyle::TextFormatEntity:
return QVariant();
}
return QVariant();
}

case CompatibleGeometryTypesRole:
{
switch ( entityType )
{
case QgsStyle::Symbol3DEntity:
{
QVariantList res;
const QList< QgsWkbTypes::GeometryType > types = mStyle->symbol3DCompatibleGeometryTypes( name );
res.reserve( types.size() );
for ( QgsWkbTypes::GeometryType type : types )
{
res << static_cast< int >( type );
}
return res;
}

return mStyle->labelSettingsLayerType( name );
case QgsStyle::LabelSettingsEntity:
case QgsStyle::SymbolEntity:
case QgsStyle::LegendPatchShapeEntity:
case QgsStyle::TagEntity:
case QgsStyle::ColorrampEntity:
case QgsStyle::SmartgroupEntity:
case QgsStyle::TextFormatEntity:
return QVariant();
}
return QVariant();
}

default:
@@ -63,6 +63,7 @@ class CORE_EXPORT QgsStyleModel: public QAbstractItemModel
SymbolTypeRole, //!< Symbol type (for symbol or legend patch shape entities)
IsFavoriteRole, //!< Whether entity is flagged as a favorite
LayerTypeRole, //!< Layer type (for label settings entities)
CompatibleGeometryTypesRole, //!< Compatible layer geometry types (for 3D symbols)
};

/**
@@ -54,6 +54,9 @@ def readXml(self, elem, context):
def writeXml(self, elem, context):
pass

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


def createMarkerSymbol():
symbol = QgsMarkerSymbol.createSimple({
@@ -496,6 +499,13 @@ def test_style_with_3d_symbols(self):
self.assertEqual(model.data(model.index(3, 0), QgsStyleModel.IsFavoriteRole), False)
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.IsFavoriteRole), False)

self.assertEqual(model.data(model.index(0, 0), QgsStyleModel.CompatibleGeometryTypesRole), [0, 1])
self.assertEqual(model.data(model.index(1, 0), QgsStyleModel.CompatibleGeometryTypesRole), [0, 1])
self.assertEqual(model.data(model.index(2, 0), QgsStyleModel.CompatibleGeometryTypesRole), [0, 1])
self.assertEqual(model.data(model.index(3, 0), QgsStyleModel.CompatibleGeometryTypesRole), [0, 1])
self.assertEqual(model.data(model.index(4, 0), QgsStyleModel.CompatibleGeometryTypesRole), [0, 1])
self.assertEqual(model.data(model.index(5, 0), QgsStyleModel.CompatibleGeometryTypesRole), None)

def test_mixed_style(self):
"""
Test style with both symbols and ramps

0 comments on commit d65b52d

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