Skip to content
Permalink
Browse files

Use an enum for join methods for readability

  • Loading branch information
nyalldawson committed Jan 2, 2020
1 parent 919b40e commit cfa5c317ebdb2fe01148afaeea4abf6b4987dd85
@@ -59,7 +59,7 @@ void QgsJoinByLocationAlgorithm::initAlgorithm( const QVariantMap & )
<< QObject::tr( "Take attributes of the first matching feature only (one-to-one)" );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "METHOD" ),
QObject::tr( "Join type" ),
joinMethods, false, 0 ) );
joinMethods, false, static_cast< int >( OneToMany ) ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DISCARD_NONMATCHING" ),
QObject::tr( "Discard records which could not be joined" ),
false ) );
@@ -128,7 +128,7 @@ QVariantMap QgsJoinByLocationAlgorithm::processAlgorithm( const QVariantMap &par
if ( !joinSource )
throw QgsProcessingException( invalidSourceError( parameters, QStringLiteral( "JOIN" ) ) );

mJoinMethod = parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context );
mJoinMethod = static_cast< JoinMethod >( parameterAsEnum( parameters, QStringLiteral( "METHOD" ), context ) );

const QStringList joinedFieldNames = parameterAsFields( parameters, QStringLiteral( "JOIN_FIELDS" ), context );

@@ -321,7 +321,8 @@ bool QgsJoinByLocationAlgorithm::processFeatures( QgsFeature &joinFeature, QgsPr
{
if ( feedback->isCanceled() )
break;
if ( mJoinMethod == 1 && !mUnjoinedIds.contains( baseFeature.id() ) )

if ( mJoinMethod == OneToOne && !mUnjoinedIds.contains( baseFeature.id() ) )
continue;

if ( !engine )
@@ -54,12 +54,17 @@ class QgsJoinByLocationAlgorithm : public QgsProcessingAlgorithm
bool featureFilter( const QgsFeature &feature, QgsGeometryEngine *engine ) const;

private:
enum JoinMethod
{
OneToMany = 0,
OneToOne = 1,
};
std::unique_ptr< QgsProcessingFeatureSource > mBaseSource;
QgsAttributeList mFields2Indices;
bool mDiscardNonMatching = false;
std::unique_ptr< QgsFeatureSink > mJoinedFeatures;
std::unique_ptr< QgsFeatureSink > mUnjoinedFeatures;
int mJoinMethod = 0;
JoinMethod mJoinMethod = OneToMany;
QList<int> mPredicates;
QgsFeatureIds mUnjoinedIds;

0 comments on commit cfa5c31

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