Skip to content

Commit

Permalink
Add subsetStringChanged signal
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 29, 2018
1 parent f5c0a2c commit 5ab3fe4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -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
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -897,7 +899,7 @@ bool QgsVectorLayer::setSubsetString( const QString &subset )

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

Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -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 )
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions tests/src/python/test_qgsvectorlayer.py
Expand Up @@ -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()
Expand Down
Binary file modified tests/testdata/polys_overlapping_with_id.dbf
Binary file not shown.

2 comments on commit 5ab3fe4

@nirvn
Copy link
Contributor Author

@nirvn nirvn commented on 5ab3fe4 May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@wonder-sk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a good idea!

Please sign in to comment.