Skip to content
Permalink
Browse files

Test supportInPlace for all polygon algorithms

  • Loading branch information
elpaso authored and nyalldawson committed Sep 14, 2018
1 parent d4af8ad commit c05aa149b00804abc50fcd671b47faee5342cc55
@@ -419,6 +419,11 @@ Returns any filters that affect how toolbox content is filtered.
%End

void setInPlaceLayer( QgsVectorLayer *layer );
%Docstring
Sets geometry \type for the in-place algorithms

:param layer: the vector layer for in-place algorithm filter
%End

void setFilterString( const QString &filter );
%Docstring
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsalgorithmdrape.h"
#include "qgsvectorlayer.h"

///@cond PRIVATE

@@ -195,6 +196,13 @@ QgsDrapeToZAlgorithm *QgsDrapeToZAlgorithm::createInstance() const
return new QgsDrapeToZAlgorithm();
}

bool QgsDrapeToZAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
return false;
return QgsWkbTypes::hasZ( layer->wkbType() );
}

QgsWkbTypes::Type QgsDrapeToZAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
{
QgsWkbTypes::Type wkb = inputWkbType;
@@ -247,6 +255,13 @@ QgsDrapeToMAlgorithm *QgsDrapeToMAlgorithm::createInstance() const
return new QgsDrapeToMAlgorithm();
}

bool QgsDrapeToMAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
return false;
return QgsWkbTypes::hasM( layer->wkbType() );
}

QgsWkbTypes::Type QgsDrapeToMAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
{
QgsWkbTypes::Type wkb = inputWkbType;
@@ -73,6 +73,7 @@ class QgsDrapeToZAlgorithm : public QgsDrapeAlgorithmBase
QString shortHelpString() const override;
QString shortDescription() const override;
QgsDrapeToZAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:

@@ -82,6 +83,7 @@ class QgsDrapeToZAlgorithm : public QgsDrapeAlgorithmBase
void prepareGeometry( QgsGeometry &geometry, double defaultVal ) const override;
QgsPoint drapeVertex( const QgsPoint &vertex, double rasterVal ) const override;


};


@@ -95,6 +97,7 @@ class QgsDrapeToMAlgorithm : public QgsDrapeAlgorithmBase
QString shortHelpString() const override;
QString shortDescription() const override;
QgsDrapeToMAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:

@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsalgorithmfixgeometries.h"
#include "qgsvectorlayer.h"

///@cond PRIVATE

@@ -72,6 +73,14 @@ QgsFixGeometriesAlgorithm *QgsFixGeometriesAlgorithm::createInstance() const
return new QgsFixGeometriesAlgorithm();
}

bool QgsFixGeometriesAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// The algorithm would drop M, so disable it if the layer has M
return ! QgsWkbTypes::hasM( layer->wkbType() );
}

QgsFeatureList QgsFixGeometriesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback )
{
if ( !feature.hasGeometry() )
@@ -41,6 +41,7 @@ class QgsFixGeometriesAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString groupId() const override;
QString shortHelpString() const override;
QgsFixGeometriesAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:
QgsProcessingFeatureSource::Flag sourceFlags() const override;
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsalgorithmminimumenclosingcircle.h"
#include "qgsvectorlayer.h"

///@cond PRIVATE

@@ -51,7 +52,7 @@ QString QgsMinimumEnclosingCircleAlgorithm::outputName() const

QgsWkbTypes::Type QgsMinimumEnclosingCircleAlgorithm::outputWkbType( QgsWkbTypes::Type ) const
{
return QgsWkbTypes::Polygon;
return QgsWkbTypes::Type::Polygon;
}

void QgsMinimumEnclosingCircleAlgorithm::initParameters( const QVariantMap & )
@@ -72,6 +73,14 @@ QgsMinimumEnclosingCircleAlgorithm *QgsMinimumEnclosingCircleAlgorithm::createIn
return new QgsMinimumEnclosingCircleAlgorithm();
}

bool QgsMinimumEnclosingCircleAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// (no Z no M)
return !( QgsWkbTypes::hasM( layer->wkbType() ) || QgsWkbTypes::hasZ( layer->wkbType() ) );
}

QgsFields QgsMinimumEnclosingCircleAlgorithm::outputFields( const QgsFields &inputFields ) const
{
QgsFields fields = inputFields;
@@ -42,6 +42,7 @@ class QgsMinimumEnclosingCircleAlgorithm : public QgsProcessingFeatureBasedAlgor
QString groupId() const override;
QString shortHelpString() const override;
QgsMinimumEnclosingCircleAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:
QString outputName() const override;
@@ -53,6 +54,7 @@ class QgsMinimumEnclosingCircleAlgorithm : public QgsProcessingFeatureBasedAlgor
private:

int mSegments = 72;

};

///@endcond PRIVATE
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsalgorithmmultiparttosinglepart.h"
#include "qgsvectorlayer.h"

///@cond PRIVATE

@@ -66,6 +67,14 @@ QgsMultipartToSinglepartAlgorithm *QgsMultipartToSinglepartAlgorithm::createInst
return new QgsMultipartToSinglepartAlgorithm();
}

bool QgsMultipartToSinglepartAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// The layer is already single part!
return QgsWkbTypes::isMultiType( layer->wkbType() );
}

QgsProcessingFeatureSource::Flag QgsMultipartToSinglepartAlgorithm::sourceFlags() const
{
// skip geometry checks - this algorithm can be used to repair geometries
@@ -45,6 +45,7 @@ class QgsMultipartToSinglepartAlgorithm : public QgsProcessingFeatureBasedAlgori
QString groupId() const override;
QString shortHelpString() const override;
QgsMultipartToSinglepartAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:

@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsalgorithmmultiringconstantbuffer.h"
#include "qgsvectorlayer.h"

///@cond PRIVATE

@@ -77,6 +78,14 @@ void QgsMultiRingConstantBufferAlgorithm::initParameters( const QVariantMap & )
addParameter( distance.release() );
}

bool QgsMultiRingConstantBufferAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// Polygons only
return layer->wkbType() == QgsWkbTypes::Type::Polygon || layer->wkbType() == QgsWkbTypes::Type::MultiPolygon;
}

bool QgsMultiRingConstantBufferAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mRingsNumber = parameterAsInt( parameters, QStringLiteral( "RINGS" ), context );
@@ -42,6 +42,7 @@ class QgsMultiRingConstantBufferAlgorithm : public QgsProcessingFeatureBasedAlgo
QString shortHelpString() const override;
QgsMultiRingConstantBufferAlgorithm *createInstance() const override SIP_FACTORY;
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:

@@ -60,6 +61,7 @@ class QgsMultiRingConstantBufferAlgorithm : public QgsProcessingFeatureBasedAlgo
double mDistance = 0.0;
bool mDynamicDistance = false;
QgsProperty mDistanceProperty;

};

///@endcond PRIVATE
@@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsalgorithmorientedminimumboundingbox.h"
#include "qgsvectorlayer.h"

///@cond PRIVATE

@@ -66,6 +67,14 @@ QgsOrientedMinimumBoundingBoxAlgorithm *QgsOrientedMinimumBoundingBoxAlgorithm::
return new QgsOrientedMinimumBoundingBoxAlgorithm();
}

bool QgsOrientedMinimumBoundingBoxAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// Polygons only
return layer->wkbType() == QgsWkbTypes::Type::Polygon || layer->wkbType() == QgsWkbTypes::Type::MultiPolygon;
}

QgsFields QgsOrientedMinimumBoundingBoxAlgorithm::outputFields( const QgsFields &inputFields ) const
{
QgsFields fields = inputFields;
@@ -41,6 +41,7 @@ class QgsOrientedMinimumBoundingBoxAlgorithm : public QgsProcessingFeatureBasedA
QString groupId() const override;
QString shortHelpString() const override;
QgsOrientedMinimumBoundingBoxAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:
QString outputName() const override;
@@ -151,6 +151,7 @@ QgsFeatureList QgsCreateParallelLinesAlgorithm::processFeature( const QgsFeature
for ( int i = 0; i < count; ++i )
{
offset += offsetStep;
// FIXME: shouldn't we use QgsVectorLayerUtils::createFeature?
QgsFeature offsetFeature = feature;
const QgsGeometry offsetGeometry = geometry.offsetCurve( offset, mSegments, mJoinStyle, mMiterLimit );
offsetFeature.setGeometry( offsetGeometry );
@@ -68,8 +68,9 @@ QgsPromoteToMultipartAlgorithm *QgsPromoteToMultipartAlgorithm::createInstance()

bool QgsPromoteToMultipartAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
Q_UNUSED( layer );
return false;
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
return QgsWkbTypes::isMultiType( layer->wkbType() );
}

QgsWkbTypes::Type QgsPromoteToMultipartAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
@@ -78,6 +78,12 @@ void QgsSegmentizeByMaximumDistanceAlgorithm::initParameters( const QVariantMap
addParameter( tolerance.release() );
}

bool QgsSegmentizeByMaximumDistanceAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
Q_UNUSED( layer );
return false;
}

bool QgsSegmentizeByMaximumDistanceAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mTolerance = parameterAsDouble( parameters, QStringLiteral( "DISTANCE" ), context );
@@ -167,6 +173,12 @@ void QgsSegmentizeByMaximumAngleAlgorithm::initParameters( const QVariantMap & )
addParameter( tolerance.release() );
}

bool QgsSegmentizeByMaximumAngleAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
{
Q_UNUSED( layer );
return false;
}

bool QgsSegmentizeByMaximumAngleAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mTolerance = parameterAsDouble( parameters, QStringLiteral( "ANGLE" ), context );
@@ -44,6 +44,7 @@ class QgsSegmentizeByMaximumDistanceAlgorithm : public QgsProcessingFeatureBased
QgsSegmentizeByMaximumDistanceAlgorithm *createInstance() const override SIP_FACTORY;
QList<int> inputLayerTypes() const override;
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:
QString outputName() const override;
@@ -77,6 +78,7 @@ class QgsSegmentizeByMaximumAngleAlgorithm : public QgsProcessingFeatureBasedAlg
QgsSegmentizeByMaximumAngleAlgorithm *createInstance() const override SIP_FACTORY;
QList<int> inputLayerTypes() const override;
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;

protected:
QString outputName() const override;

0 comments on commit c05aa14

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