Skip to content
Permalink
Browse files
Rename UseSelection -> UseSelectionIfPresent, clarify docs
  • Loading branch information
nyalldawson committed Apr 26, 2017
1 parent 1c6f165 commit b067bd786ac4fe2e84cfeb03037a80294016c516
@@ -28,7 +28,7 @@ class QgsProcessingContext

enum Flag
{
UseSelection,
UseSelectionIfPresent,
};
typedef QFlags<QgsProcessingContext::Flag> Flags;

@@ -86,7 +86,7 @@ def testValues(self):
self.assertEqual(res[2], [2, 1, 0, 2, 1, 0, 0, 0, 0])

# test with selected features
context.setFlags(QgsProcessingContext.UseSelection)
context.setFlags(QgsProcessingContext.UseSelectionIfPresent)
test_layer.selectByIds([2, 4, 6])
res = vector.values(test_layer, context, 1)
self.assertEqual(set(res[1]), set([5, 7, 3]))
@@ -111,7 +111,7 @@ def testUniqueValues(self):
self.assertEqual(set(v), set([2, 1, 0]))

# test with selected features
context.setFlags(QgsProcessingContext.UseSelection)
context.setFlags(QgsProcessingContext.UseSelectionIfPresent)
test_layer.selectByIds([2, 4, 6])
v = vector.uniqueValues(test_layer, context, 'id')
self.assertEqual(len(v), len(set(v)))
@@ -108,7 +108,7 @@ def createContext():

use_selection = ProcessingConfig.getSetting(ProcessingConfig.USE_SELECTED)
if use_selection:
context.setFlags(QgsProcessingContext.UseSelection)
context.setFlags(QgsProcessingContext.UseSelectionIfPresent)

invalid_features_method = ProcessingConfig.getSetting(ProcessingConfig.FILTER_INVALID_GEOMETRIES)
context.setInvalidGeometryCheck(invalid_features_method)
@@ -94,7 +94,7 @@ def uniqueValues(layer, context, attribute):
"""

fieldIndex = resolveFieldIndex(layer, attribute)
if context.flags() & QgsProcessingContext.UseSelection \
if context.flags() & QgsProcessingContext.UseSelectionIfPresent \
and layer.selectedFeatureCount() > 0:

# iterate through selected features
@@ -41,7 +41,7 @@ class CORE_EXPORT QgsProcessingContext
//! Flags that affect how processing algorithms are run
enum Flag
{
UseSelection = 1 << 0, //!< Filter to selected features when running algorithms
UseSelectionIfPresent = 1 << 0, //!< Filter to selected features when running algorithms (if a selection exists)
};
Q_DECLARE_FLAGS( Flags, Flag )

@@ -175,7 +175,7 @@ QString QgsProcessingUtils::normalizeLayerSource( const QString &source )

QgsFeatureIterator QgsProcessingUtils::getFeatures( QgsVectorLayer *layer, const QgsProcessingContext &context, const QgsFeatureRequest &request )
{
bool useSelection = context.flags() & QgsProcessingContext::UseSelection && layer->selectedFeatureCount() > 0;
bool useSelection = context.flags() & QgsProcessingContext::UseSelectionIfPresent && layer->selectedFeatureCount() > 0;

QgsFeatureRequest req( request );
req.setInvalidGeometryCheck( context.invalidGeometryCheck() );
@@ -192,7 +192,7 @@ QgsFeatureIterator QgsProcessingUtils::getFeatures( QgsVectorLayer *layer, const

long QgsProcessingUtils::featureCount( QgsVectorLayer *layer, const QgsProcessingContext &context )
{
bool useSelection = context.flags() & QgsProcessingContext::UseSelection && layer->selectedFeatureCount() > 0;
bool useSelection = context.flags() & QgsProcessingContext::UseSelectionIfPresent && layer->selectedFeatureCount() > 0;
if ( useSelection )
return layer->selectedFeatureCount();
else
@@ -465,7 +465,7 @@ void TestQgsProcessing::features()
QCOMPARE( QgsProcessingUtils::featureCount( layer, context ), 5L );

// test with selected features
context.setFlags( QgsProcessingContext::UseSelection );
context.setFlags( QgsProcessingContext::UseSelectionIfPresent );
layer->selectByIds( QgsFeatureIds() << 2 << 4 );
ids = getIds( QgsProcessingUtils::getFeatures( layer, context ) );
QCOMPARE( ids, QgsFeatureIds() << 2 << 4 );
@@ -479,7 +479,7 @@ void TestQgsProcessing::features()
QCOMPARE( QgsProcessingUtils::featureCount( layer, context ), 5L );

// using selected features, but no selection
context.setFlags( QgsProcessingContext::UseSelection );
context.setFlags( QgsProcessingContext::UseSelectionIfPresent );
layer->removeSelection();
ids = getIds( QgsProcessingUtils::getFeatures( layer, context ) );
QCOMPARE( ids, QgsFeatureIds() << 1 << 2 << 3 << 4 << 5 );
@@ -496,7 +496,7 @@ void TestQgsProcessing::features()


//test that feature request is honored when using selections
context.setFlags( QgsProcessingContext::UseSelection );
context.setFlags( QgsProcessingContext::UseSelectionIfPresent );
layer->selectByIds( QgsFeatureIds() << 2 << 4 );
ids = getIds( QgsProcessingUtils::getFeatures( layer, context, QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ) ) );
QCOMPARE( ids, QgsFeatureIds() << 2 << 4 );

0 comments on commit b067bd7

Please sign in to comment.