Change QgsProcessingAlgorithm::supportInPlaceEdit to use QgsMapLayer, not QgsVectorLayer

Because at some stage in the future we may allow in-place edits to raster layers,
and we don't want to have to break API for this.
This commit is contained in:
Nyall Dawson 2018-09-21 13:31:33 +10:00
parent e2068b8c1f
commit 4b24552097
29 changed files with 91 additions and 42 deletions

View File

@ -812,7 +812,7 @@ should correspond to the invalid source parameter name.
.. versionadded:: 3.2
%End
virtual bool supportInPlaceEdit( const QgsVectorLayer *layer ) const;
virtual bool supportInPlaceEdit( const QgsMapLayer *layer ) const;
%Docstring
Checks whether this algorithm supports in-place editing on the given ``layer``
Default implementation returns false.
@ -976,7 +976,8 @@ Returns the feature request used for fetching features to process from the
source layer. The default implementation requests all attributes and geometry.
%End
virtual bool supportInPlaceEdit( const QgsVectorLayer *layer ) const;
virtual bool supportInPlaceEdit( const QgsMapLayer *layer ) const;
%Docstring
Checks whether this algorithm supports in-place editing on the given ``layer``
Default implementation for feature based algorithms run some basic compatibility

View File

@ -162,7 +162,7 @@ QgsFeatureList QgsAddIncrementalFieldAlgorithm::processFeature( const QgsFeature
return QgsFeatureList() << f;
}
bool QgsAddIncrementalFieldAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsAddIncrementalFieldAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
{
Q_UNUSED( layer );
return false;

View File

@ -53,7 +53,7 @@ class QgsAddIncrementalFieldAlgorithm : public QgsProcessingFeatureBasedAlgorith
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
QgsFeatureRequest request() const override;
QgsFeatureList processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
private:

View File

@ -62,7 +62,7 @@ QgsAssignProjectionAlgorithm *QgsAssignProjectionAlgorithm::createInstance() con
return new QgsAssignProjectionAlgorithm();
}
bool QgsAssignProjectionAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsAssignProjectionAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
{
Q_UNUSED( layer );
return false;

View File

@ -41,7 +41,7 @@ class QgsAssignProjectionAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString groupId() const override;
QString shortHelpString() const override;
QgsAssignProjectionAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:

View File

@ -18,6 +18,7 @@
#include "qgsalgorithmclip.h"
#include "qgsgeometryengine.h"
#include "qgsoverlayutils.h"
#include "qgsvectorlayer.h"
///@cond PRIVATE
@ -76,10 +77,13 @@ QgsClipAlgorithm *QgsClipAlgorithm::createInstance() const
return new QgsClipAlgorithm();
}
bool QgsClipAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsClipAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
Q_UNUSED( layer );
return true;
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
return layer->isSpatial();
}
QVariantMap QgsClipAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )

View File

@ -44,7 +44,7 @@ class QgsClipAlgorithm : public QgsProcessingAlgorithm
QString groupId() const override;
QString shortHelpString() const override;
QgsClipAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
QgsProcessingAlgorithm::Flags flags() const override;
protected:

View File

@ -196,8 +196,12 @@ QgsDrapeToZAlgorithm *QgsDrapeToZAlgorithm::createInstance() const
return new QgsDrapeToZAlgorithm();
}
bool QgsDrapeToZAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsDrapeToZAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
return false;
return QgsWkbTypes::hasZ( layer->wkbType() );
@ -255,8 +259,12 @@ QgsDrapeToMAlgorithm *QgsDrapeToMAlgorithm::createInstance() const
return new QgsDrapeToMAlgorithm();
}
bool QgsDrapeToMAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsDrapeToMAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsDrapeAlgorithmBase::supportInPlaceEdit( layer ) )
return false;
return QgsWkbTypes::hasM( layer->wkbType() );

View File

@ -73,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
@ -97,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:

View File

@ -59,7 +59,7 @@ QgsDropMZValuesAlgorithm *QgsDropMZValuesAlgorithm::createInstance() const
return new QgsDropMZValuesAlgorithm();
}
bool QgsDropMZValuesAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsDropMZValuesAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
{
Q_UNUSED( layer );
return false;

View File

@ -41,7 +41,7 @@ class QgsDropMZValuesAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString groupId() const override;
QString shortHelpString() const override;
QgsDropMZValuesAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:

View File

@ -136,8 +136,12 @@ QgsFilterVerticesByM *QgsFilterVerticesByM::createInstance() const
return new QgsFilterVerticesByM();
}
bool QgsFilterVerticesByM::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsFilterVerticesByM::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsFilterVerticesAlgorithmBase::supportInPlaceEdit( layer ) )
return false;
return QgsWkbTypes::hasM( layer->wkbType() );
@ -182,10 +186,14 @@ QgsFilterVerticesByZ *QgsFilterVerticesByZ::createInstance() const
return new QgsFilterVerticesByZ();
}
bool QgsFilterVerticesByZ::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsFilterVerticesByZ::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsFilterVerticesAlgorithmBase::supportInPlaceEdit( layer ) )
return false;
return false;
return QgsWkbTypes::hasZ( layer->wkbType() );
}

View File

@ -72,7 +72,7 @@ class QgsFilterVerticesByM : public QgsFilterVerticesAlgorithmBase
QString displayName() const override;
QStringList tags() const override;
QgsFilterVerticesByM *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
private:
@ -95,7 +95,7 @@ class QgsFilterVerticesByZ : public QgsFilterVerticesAlgorithmBase
QString displayName() const override;
QStringList tags() const override;
QgsFilterVerticesByZ *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
private:

View File

@ -73,9 +73,13 @@ QgsFixGeometriesAlgorithm *QgsFixGeometriesAlgorithm::createInstance() const
return new QgsFixGeometriesAlgorithm();
}
bool QgsFixGeometriesAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsFixGeometriesAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( !layer->isSpatial() || ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// The algorithm would drop M, so disable it if the layer has M
return ! QgsWkbTypes::hasM( layer->wkbType() );

View File

@ -41,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
QgsProcessingFeatureSource::Flag sourceFlags() const override;

View File

@ -73,8 +73,12 @@ QgsMinimumEnclosingCircleAlgorithm *QgsMinimumEnclosingCircleAlgorithm::createIn
return new QgsMinimumEnclosingCircleAlgorithm();
}
bool QgsMinimumEnclosingCircleAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsMinimumEnclosingCircleAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// (no Z no M)

View File

@ -42,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
QString outputName() const override;

View File

@ -78,8 +78,12 @@ void QgsMultiRingConstantBufferAlgorithm::initParameters( const QVariantMap & )
addParameter( distance.release() );
}
bool QgsMultiRingConstantBufferAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsMultiRingConstantBufferAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// Polygons only

View File

@ -42,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:

View File

@ -67,8 +67,12 @@ QgsOrientedMinimumBoundingBoxAlgorithm *QgsOrientedMinimumBoundingBoxAlgorithm::
return new QgsOrientedMinimumBoundingBoxAlgorithm();
}
bool QgsOrientedMinimumBoundingBoxAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsOrientedMinimumBoundingBoxAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
// Polygons only

View File

@ -41,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
QString outputName() const override;

View File

@ -66,8 +66,12 @@ QgsPromoteToMultipartAlgorithm *QgsPromoteToMultipartAlgorithm::createInstance()
return new QgsPromoteToMultipartAlgorithm();
}
bool QgsPromoteToMultipartAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsPromoteToMultipartAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;
return QgsWkbTypes::isMultiType( layer->wkbType() );

View File

@ -44,7 +44,7 @@ class QgsPromoteToMultipartAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString groupId() const override;
QString shortHelpString() const override;
QgsPromoteToMultipartAlgorithm *createInstance() const override SIP_FACTORY;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
QString outputName() const override;

View File

@ -78,7 +78,7 @@ void QgsSegmentizeByMaximumDistanceAlgorithm::initParameters( const QVariantMap
addParameter( tolerance.release() );
}
bool QgsSegmentizeByMaximumDistanceAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsSegmentizeByMaximumDistanceAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
{
Q_UNUSED( layer );
return false;
@ -173,7 +173,7 @@ void QgsSegmentizeByMaximumAngleAlgorithm::initParameters( const QVariantMap & )
addParameter( tolerance.release() );
}
bool QgsSegmentizeByMaximumAngleAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsSegmentizeByMaximumAngleAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
{
Q_UNUSED( layer );
return false;

View File

@ -44,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
QString outputName() const override;
@ -78,7 +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;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
QString outputName() const override;

View File

@ -164,8 +164,12 @@ QgsWkbTypes::Type QgsTranslateAlgorithm::outputWkbType( QgsWkbTypes::Type inputW
}
bool QgsTranslateAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsTranslateAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
if ( ! QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( layer ) )
return false;

View File

@ -42,7 +42,7 @@ class QgsTranslateAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QString shortHelpString() const override;
QgsTranslateAlgorithm *createInstance() const override SIP_FACTORY;
void initParameters( const QVariantMap &configuration = QVariantMap() ) override;
bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
protected:
QString outputName() const override;

View File

@ -762,7 +762,7 @@ QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap &parameters,
}
}
bool QgsProcessingAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsProcessingAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
{
Q_UNUSED( layer );
return false;
@ -907,8 +907,12 @@ QgsFeatureRequest QgsProcessingFeatureBasedAlgorithm::request() const
return QgsFeatureRequest();
}
bool QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( const QgsVectorLayer *layer ) const
bool QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
{
const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
if ( !layer )
return false;
QgsWkbTypes::GeometryType inPlaceGeometryType = layer->geometryType();
if ( !inputLayerTypes().empty() &&
!inputLayerTypes().contains( QgsProcessing::TypeVector ) &&

View File

@ -812,7 +812,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
* \return true if the algorithm supports in-place editing
* \since QGIS 3.4
*/
virtual bool supportInPlaceEdit( const QgsVectorLayer *layer ) const;
virtual bool supportInPlaceEdit( const QgsMapLayer *layer ) const;
private:
@ -990,7 +990,7 @@ class CORE_EXPORT QgsProcessingFeatureBasedAlgorithm : public QgsProcessingAlgor
* \return true if the algorithm supports in-place editing
* \since QGIS 3.4
*/
virtual bool supportInPlaceEdit( const QgsVectorLayer *layer ) const override;
bool supportInPlaceEdit( const QgsMapLayer *layer ) const override;
/**
* Read the source from \a parameters and \a context and set it