Skip to content

Commit 8b4bf88

Browse files
committedJun 5, 2017
Add native c++ algorithm provider
1 parent b64a71d commit 8b4bf88

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed
 

‎src/core/processing/qgsnativealgorithms.cpp‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,43 @@
2626

2727
///@cond PRIVATE
2828

29+
QgsNativeAlgorithms::QgsNativeAlgorithms( QObject *parent )
30+
: QgsProcessingProvider( parent )
31+
{}
32+
33+
QIcon QgsNativeAlgorithms::icon() const
34+
{
35+
return QgsApplication::getThemeIcon( QStringLiteral( "/providerQgis.svg" ) );
36+
}
37+
38+
QString QgsNativeAlgorithms::svgIconPath() const
39+
{
40+
return QgsApplication::iconPath( QStringLiteral( "providerQgis.svg" ) );
41+
}
42+
43+
QString QgsNativeAlgorithms::id() const
44+
{
45+
return QStringLiteral( "native" );
46+
}
47+
48+
QString QgsNativeAlgorithms::name() const
49+
{
50+
return tr( "QGIS" );
51+
}
52+
53+
bool QgsNativeAlgorithms::supportsNonFileBasedOutput() const
54+
{
55+
return true;
56+
}
57+
58+
void QgsNativeAlgorithms::loadAlgorithms()
59+
{
60+
addAlgorithm( new QgsCentroidAlgorithm() );
61+
addAlgorithm( new QgsBufferAlgorithm() );
62+
}
63+
64+
65+
2966
QgsCentroidAlgorithm::QgsCentroidAlgorithm()
3067
{
3168
addParameter( new QgsProcessingParameterVector( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );

‎src/core/processing/qgsnativealgorithms.h‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,28 @@
2121
#include "qgis_core.h"
2222
#include "qgis.h"
2323
#include "qgsprocessingalgorithm.h"
24+
#include "qgsprocessingprovider.h"
2425

2526
///@cond PRIVATE
2627

28+
class QgsNativeAlgorithms: public QgsProcessingProvider
29+
{
30+
public:
31+
32+
QgsNativeAlgorithms( QObject *parent = nullptr );
33+
34+
QIcon icon() const override;
35+
QString svgIconPath() const override;
36+
QString id() const override;
37+
QString name() const override;
38+
bool supportsNonFileBasedOutput() const override;
39+
40+
protected:
41+
42+
void loadAlgorithms() override;
43+
44+
};
45+
2746
/**
2847
* Native centroid algorithm.
2948
*/
@@ -54,7 +73,7 @@ class QgsBufferAlgorithm : public QgsProcessingAlgorithm
5473

5574
QgsBufferAlgorithm();
5675

57-
QString name() const override { return QStringLiteral( "fixeddistancebuffer" ); }
76+
QString name() const override { return QStringLiteral( "buffer" ); }
5877
QString displayName() const override { return QObject::tr( "Buffer" ); }
5978
virtual QStringList tags() const override { return QObject::tr( "buffer,grow" ).split( ',' ); }
6079
QString group() const override { return QObject::tr( "Vector geometry tools" ); }

‎src/core/qgsapplication.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include "gps/qgsgpsconnectionregistry.h"
4242
#include "processing/qgsprocessingregistry.h"
43+
#include "processing/qgsnativealgorithms.h"
4344

4445
#include <QDir>
4546
#include <QFile>
@@ -1578,6 +1579,7 @@ QgsApplication::ApplicationMembers::ApplicationMembers()
15781579
mGpsConnectionRegistry = new QgsGPSConnectionRegistry();
15791580
mPluginLayerRegistry = new QgsPluginLayerRegistry();
15801581
mProcessingRegistry = new QgsProcessingRegistry();
1582+
mProcessingRegistry->addProvider( new QgsNativeAlgorithms( mProcessingRegistry ) );
15811583
mAnnotationRegistry = new QgsAnnotationRegistry();
15821584
}
15831585

0 commit comments

Comments
 (0)
Please sign in to comment.