Skip to content
Permalink
Browse files

Add subsetStringChanged signal

  • Loading branch information
nirvn committed May 29, 2018
1 parent f5c0a2c commit 5ab3fe4ba054179407c04969fc50fb45052d6d30
@@ -2390,6 +2390,12 @@ Is emitted, whenever the fields available from this layer have been changed.
This can be due to manually adding attributes or due to a join.
%End

void subsetStringChanged();
%Docstring
Emitted when the layer's subset string has changed.

.. versionadded:: 3.2
%End

void attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value );
%Docstring
Binary file not shown.
@@ -164,6 +164,8 @@ QgsVectorLayer::QgsVectorLayer( const QString &vectorLayerPath,
connect( this, &QgsVectorLayer::selectionChanged, this, [ = ] { emit repaintRequested(); } );
connect( QgsProject::instance()->relationManager(), &QgsRelationManager::relationsLoaded, this, &QgsVectorLayer::onRelationsLoaded );

connect( this, &QgsVectorLayer::subsetStringChanged, this, &QgsMapLayer::configChanged );

// Default simplify drawing settings
QgsSettings settings;
mSimplifyMethod.setSimplifyHints( settings.flagValue( QStringLiteral( "qgis/simplifyDrawingHints" ), mSimplifyMethod.simplifyHints(), QgsSettings::NoSection ) );
@@ -897,7 +899,7 @@ bool QgsVectorLayer::setSubsetString( const QString &subset )

if ( res )
{
emit configChanged();
emit subsetStringChanged();
emit repaintRequested();
}

@@ -354,6 +354,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
{
Q_OBJECT

Q_PROPERTY( QString subsetString READ subsetString WRITE setSubsetString NOTIFY subsetStringChanged )
Q_PROPERTY( QString displayExpression READ displayExpression WRITE setDisplayExpression NOTIFY displayExpressionChanged )
Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
Q_PROPERTY( QgsEditFormConfig editFormConfig READ editFormConfig WRITE setEditFormConfig NOTIFY editFormConfigChanged )
@@ -2148,6 +2149,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
void updatedFields();

/**
* Emitted when the layer's subset string has changed.
* \since QGIS 3.2
*/
void subsetStringChanged();

/**
* Is emitted whenever an attribute value change is done in the edit buffer.
@@ -1619,6 +1619,20 @@ def testUniqueStringsMatching(self):
self.assertEqual(set(layer.uniqueStringsMatching(0, 'n')),
set(['orange', 'BanaNa', 'waterMelon', 'pineapple', 'coconut']))

def test_subsetString(self):
subset_string_changed = False

def onSubsetStringChanged():
nonlocal subset_string_changed
subset_string_changed = True

path = os.path.join(unitTestDataPath(), 'lines.shp')
layer = QgsVectorLayer(path, 'test', 'ogr')
layer.subsetStringChanged.connect(onSubsetStringChanged)
layer.setSubsetString("\"Name\" = 'Highway'")
self.assertTrue(subset_string_changed)
self.assertEqual(layer.featureCount(), 2)

def testMinValue(self):
""" test retrieving minimum values """
layer = createLayerWithFivePoints()
Binary file not shown.

2 comments on commit 5ab3fe4

@nirvn

This comment has been minimized.

Copy link
Contributor Author

@nirvn nirvn replied May 29, 2018

@wonder-sk , should we update the layer tree filter indicator to make use of this signal? Seems most appropriate.

@wonder-sk

This comment has been minimized.

Copy link
Member

@wonder-sk wonder-sk replied May 29, 2018

Sounds like a good idea!

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