Skip to content

Commit

Permalink
Code shuffle to move QgsProxyFeatureSink to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 7, 2020
1 parent 70bbfca commit c987e50
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 75 deletions.
35 changes: 0 additions & 35 deletions python/core/auto_generated/qgsfeaturesink.sip.in
Expand Up @@ -77,41 +77,6 @@ QFlags<QgsFeatureSink::Flag> operator|(QgsFeatureSink::Flag f1, QFlags<QgsFeatur



class QgsProxyFeatureSink : QgsFeatureSink
{
%Docstring
A simple feature sink which proxies feature addition on to another feature sink.

This class is designed to allow factory methods which always return new QgsFeatureSink
objects. Since it is not always possible to create an entirely new QgsFeatureSink
(e.g. if the feature sink is a layer's data provider), a new :py:class:`QgsProxyFeatureSink`
can instead be returned which forwards features on to the destination sink. The
proxy sink can be safely deleted without affecting the destination sink.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsfeaturesink.h"
%End
public:

QgsProxyFeatureSink( QgsFeatureSink *sink );
%Docstring
Constructs a new QgsProxyFeatureSink which forwards features onto a destination ``sink``.
%End
virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = 0 );
virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = 0 );
virtual bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = 0 );

QgsFeatureSink *destinationSink();
%Docstring
Returns the destination QgsFeatureSink which the proxy will forward features to.
%End

};


/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
58 changes: 58 additions & 0 deletions python/core/auto_generated/qgsproxyfeaturesink.sip.in
@@ -0,0 +1,58 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsproxyfeaturesink.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsProxyFeatureSink : QgsFeatureSink
{
%Docstring
A simple feature sink which proxies feature addition on to another feature sink.

This class is designed to allow factory methods which always return new QgsFeatureSink
objects. Since it is not always possible to create an entirely new QgsFeatureSink
(e.g. if the feature sink is a layer's data provider), a new QgsProxyFeatureSink
can instead be returned which forwards features on to the destination sink. The
proxy sink can be safely deleted without affecting the destination sink.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsproxyfeaturesink.h"
%End
public:

QgsProxyFeatureSink( QgsFeatureSink *sink );
%Docstring
Constructs a new QgsProxyFeatureSink which forwards features onto a destination ``sink``.
%End
virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = 0 );
virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = 0 );
virtual bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = 0 );

QgsFeatureSink *destinationSink();
%Docstring
Returns the destination QgsFeatureSink which the proxy will forward features to.
%End

};






/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsproxyfeaturesink.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Expand Up @@ -167,6 +167,7 @@
%Include auto_generated/qgsproviderconnectionmodel.sip
%Include auto_generated/qgsprovidermetadata.sip
%Include auto_generated/qgsproviderregistry.sip
%Include auto_generated/qgsproxyfeaturesink.sip
%Include auto_generated/qgsproxyprogresstask.sip
%Include auto_generated/qgspythonrunner.sip
%Include auto_generated/qgsrange.sip
Expand Down
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -360,6 +360,7 @@ SET(QGIS_CORE_SRCS
qgsproviderconnectionmodel.cpp
qgsprovidermetadata.cpp
qgsproviderregistry.cpp
qgsproxyfeaturesink.cpp
qgsproxyprogresstask.cpp
qgspythonrunner.cpp
qgsreadwritecontext.cpp
Expand Down Expand Up @@ -901,6 +902,7 @@ SET(QGIS_CORE_HDRS
qgsproviderconnectionmodel.h
qgsprovidermetadata.h
qgsproviderregistry.h
qgsproxyfeaturesink.h
qgsproxyprogresstask.h
qgspythonrunner.h
qgsrange.h
Expand Down
1 change: 1 addition & 0 deletions src/core/processing/qgsprocessingutils.h
Expand Up @@ -26,6 +26,7 @@
#include "qgsprocessing.h"
#include "qgsfeaturesink.h"
#include "qgsfeaturesource.h"
#include "qgsproxyfeaturesink.h"

class QgsMeshLayer;
class QgsProject;
Expand Down
4 changes: 0 additions & 4 deletions src/core/qgsfeaturesink.cpp
Expand Up @@ -42,7 +42,3 @@ bool QgsFeatureSink::addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::
return result;
}


QgsProxyFeatureSink::QgsProxyFeatureSink( QgsFeatureSink *sink )
: mSink( sink )
{}
36 changes: 0 additions & 36 deletions src/core/qgsfeaturesink.h
Expand Up @@ -102,42 +102,6 @@ class CORE_EXPORT QgsFeatureSink

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureSink::Flags )


/**
* \class QgsProxyFeatureSink
* \ingroup core
* A simple feature sink which proxies feature addition on to another feature sink.
*
* This class is designed to allow factory methods which always return new QgsFeatureSink
* objects. Since it is not always possible to create an entirely new QgsFeatureSink
* (e.g. if the feature sink is a layer's data provider), a new QgsProxyFeatureSink
* can instead be returned which forwards features on to the destination sink. The
* proxy sink can be safely deleted without affecting the destination sink.
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProxyFeatureSink : public QgsFeatureSink
{
public:

/**
* Constructs a new QgsProxyFeatureSink which forwards features onto a destination \a sink.
*/
QgsProxyFeatureSink( QgsFeatureSink *sink );
bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeature( feature, flags ); }
bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeatures( features, flags ); }
bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeatures( iterator, flags ); }

/**
* Returns the destination QgsFeatureSink which the proxy will forward features to.
*/
QgsFeatureSink *destinationSink() { return mSink; }

private:

QgsFeatureSink *mSink = nullptr;
};

Q_DECLARE_METATYPE( QgsFeatureSink * )

#endif // QGSFEATURESINK_H
23 changes: 23 additions & 0 deletions src/core/qgsproxyfeaturesink.cpp
@@ -0,0 +1,23 @@
/***************************************************************************
qgsproxyfeaturesink.cpp
----------------------
begin : April 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsproxyfeaturesink.h"


QgsProxyFeatureSink::QgsProxyFeatureSink( QgsFeatureSink *sink )
: mSink( sink )
{}
66 changes: 66 additions & 0 deletions src/core/qgsproxyfeaturesink.h
@@ -0,0 +1,66 @@
/***************************************************************************
qgsproxyfeaturesink.h
----------------------
begin : April 2020
copyright : (C) 2020 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSPROXYFEATURESINK_H
#define QGSPROXYFEATURESINK_H

#include "qgis_core.h"
#include "qgis.h"
#include "qgsfeaturesink.h"


/**
* \class QgsProxyFeatureSink
* \ingroup core
* A simple feature sink which proxies feature addition on to another feature sink.
*
* This class is designed to allow factory methods which always return new QgsFeatureSink
* objects. Since it is not always possible to create an entirely new QgsFeatureSink
* (e.g. if the feature sink is a layer's data provider), a new QgsProxyFeatureSink
* can instead be returned which forwards features on to the destination sink. The
* proxy sink can be safely deleted without affecting the destination sink.
*
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProxyFeatureSink : public QgsFeatureSink
{
public:

/**
* Constructs a new QgsProxyFeatureSink which forwards features onto a destination \a sink.
*/
QgsProxyFeatureSink( QgsFeatureSink *sink );
bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeature( feature, flags ); }
bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeatures( features, flags ); }
bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeatures( iterator, flags ); }

/**
* Returns the destination QgsFeatureSink which the proxy will forward features to.
*/
QgsFeatureSink *destinationSink() { return mSink; }

private:

QgsFeatureSink *mSink = nullptr;
};


#endif // QGSPROXYFEATURESINK_H




0 comments on commit c987e50

Please sign in to comment.