Skip to content
Permalink
Browse files

Most c++ algorithms can run safely in background threads

  • Loading branch information
nyalldawson committed Dec 5, 2017
1 parent 70785f8 commit c14e6ca772167267e04517ed7927cdfe39c6743f
Showing with 269 additions and 6 deletions.
  1. +2 −2 python/plugins/processing/gui/AlgorithmDialog.py
  2. +5 −0 src/3d/processing/qgsalgorithmtessellate.cpp
  3. +1 −0 src/3d/processing/qgsalgorithmtessellate.h
  4. +5 −0 src/analysis/processing/qgsalgorithmaddincrementalfield.cpp
  5. +1 −0 src/analysis/processing/qgsalgorithmaddincrementalfield.h
  6. +5 −0 src/analysis/processing/qgsalgorithmassignprojection.cpp
  7. +1 −0 src/analysis/processing/qgsalgorithmassignprojection.h
  8. +5 −0 src/analysis/processing/qgsalgorithmboundary.cpp
  9. +1 −0 src/analysis/processing/qgsalgorithmboundary.h
  10. +5 −0 src/analysis/processing/qgsalgorithmboundingbox.cpp
  11. +1 −0 src/analysis/processing/qgsalgorithmboundingbox.h
  12. +5 −0 src/analysis/processing/qgsalgorithmbuffer.cpp
  13. +1 −1 src/analysis/processing/qgsalgorithmbuffer.h
  14. +5 −0 src/analysis/processing/qgsalgorithmcentroid.cpp
  15. +1 −0 src/analysis/processing/qgsalgorithmcentroid.h
  16. +5 −0 src/analysis/processing/qgsalgorithmclip.cpp
  17. +1 −0 src/analysis/processing/qgsalgorithmclip.h
  18. +5 −0 src/analysis/processing/qgsalgorithmconvexhull.cpp
  19. +1 −0 src/analysis/processing/qgsalgorithmconvexhull.h
  20. +5 −0 src/analysis/processing/qgsalgorithmdissolve.cpp
  21. +1 −0 src/analysis/processing/qgsalgorithmdissolve.h
  22. +5 −0 src/analysis/processing/qgsalgorithmdropgeometry.cpp
  23. +1 −0 src/analysis/processing/qgsalgorithmdropgeometry.h
  24. +5 −0 src/analysis/processing/qgsalgorithmdropmzvalues.cpp
  25. +1 −0 src/analysis/processing/qgsalgorithmdropmzvalues.h
  26. +5 −0 src/analysis/processing/qgsalgorithmextenttolayer.cpp
  27. +1 −0 src/analysis/processing/qgsalgorithmextenttolayer.h
  28. +5 −0 src/analysis/processing/qgsalgorithmextractbyattribute.cpp
  29. +1 −0 src/analysis/processing/qgsalgorithmextractbyattribute.h
  30. +5 −0 src/analysis/processing/qgsalgorithmextractbyexpression.cpp
  31. +1 −0 src/analysis/processing/qgsalgorithmextractbyexpression.h
  32. +5 −0 src/analysis/processing/qgsalgorithmextractbyextent.cpp
  33. +1 −0 src/analysis/processing/qgsalgorithmextractbyextent.h
  34. +5 −0 src/analysis/processing/qgsalgorithmextractbylocation.cpp
  35. +1 −0 src/analysis/processing/qgsalgorithmextractbylocation.h
  36. +5 −0 src/analysis/processing/qgsalgorithmextractnodes.cpp
  37. +1 −0 src/analysis/processing/qgsalgorithmextractnodes.h
  38. +5 −0 src/analysis/processing/qgsalgorithmfiledownloader.cpp
  39. +1 −0 src/analysis/processing/qgsalgorithmfiledownloader.h
  40. +5 −0 src/analysis/processing/qgsalgorithmfixgeometries.cpp
  41. +1 −0 src/analysis/processing/qgsalgorithmfixgeometries.h
  42. +5 −0 src/analysis/processing/qgsalgorithmjoinbyattribute.cpp
  43. +1 −0 src/analysis/processing/qgsalgorithmjoinbyattribute.h
  44. +5 −0 src/analysis/processing/qgsalgorithmjoinwithlines.cpp
  45. +1 −0 src/analysis/processing/qgsalgorithmjoinwithlines.h
  46. +5 −0 src/analysis/processing/qgsalgorithmlineintersection.cpp
  47. +1 −0 src/analysis/processing/qgsalgorithmlineintersection.h
  48. +1 −1 src/analysis/processing/qgsalgorithmloadlayer.cpp
  49. +5 −0 src/analysis/processing/qgsalgorithmmeancoordinates.cpp
  50. +1 −0 src/analysis/processing/qgsalgorithmmeancoordinates.h
  51. +5 −0 src/analysis/processing/qgsalgorithmmergelines.cpp
  52. +1 −0 src/analysis/processing/qgsalgorithmmergelines.h
  53. +5 −0 src/analysis/processing/qgsalgorithmmergevector.cpp
  54. +1 −0 src/analysis/processing/qgsalgorithmmergevector.h
  55. +5 −0 src/analysis/processing/qgsalgorithmminimumenclosingcircle.cpp
  56. +1 −0 src/analysis/processing/qgsalgorithmminimumenclosingcircle.h
  57. +5 −0 src/analysis/processing/qgsalgorithmmultiparttosinglepart.cpp
  58. +1 −0 src/analysis/processing/qgsalgorithmmultiparttosinglepart.h
  59. +5 −0 src/analysis/processing/qgsalgorithmorderbyexpression.cpp
  60. +1 −0 src/analysis/processing/qgsalgorithmorderbyexpression.h
  61. +5 −0 src/analysis/processing/qgsalgorithmorientedminimumboundingbox.cpp
  62. +1 −0 src/analysis/processing/qgsalgorithmorientedminimumboundingbox.h
  63. +5 −0 src/analysis/processing/qgsalgorithmpackage.cpp
  64. +1 −0 src/analysis/processing/qgsalgorithmpackage.h
  65. +5 −0 src/analysis/processing/qgsalgorithmpromotetomultipart.cpp
  66. +1 −0 src/analysis/processing/qgsalgorithmpromotetomultipart.h
  67. +5 −0 src/analysis/processing/qgsalgorithmrasterlayeruniquevalues.cpp
  68. +1 −0 src/analysis/processing/qgsalgorithmrasterlayeruniquevalues.h
  69. +5 −0 src/analysis/processing/qgsalgorithmremoveduplicatenodes.cpp
  70. +1 −0 src/analysis/processing/qgsalgorithmremoveduplicatenodes.h
  71. +5 −0 src/analysis/processing/qgsalgorithmremovenullgeometry.cpp
  72. +1 −0 src/analysis/processing/qgsalgorithmremovenullgeometry.h
  73. +1 −1 src/analysis/processing/qgsalgorithmrenamelayer.cpp
  74. +5 −0 src/analysis/processing/qgsalgorithmsaveselectedfeatures.cpp
  75. +1 −0 src/analysis/processing/qgsalgorithmsaveselectedfeatures.h
  76. +5 −0 src/analysis/processing/qgsalgorithmsimplify.cpp
  77. +1 −0 src/analysis/processing/qgsalgorithmsimplify.h
  78. +5 −0 src/analysis/processing/qgsalgorithmsmooth.cpp
  79. +1 −0 src/analysis/processing/qgsalgorithmsmooth.h
  80. +5 −0 src/analysis/processing/qgsalgorithmsnaptogrid.cpp
  81. +1 −0 src/analysis/processing/qgsalgorithmsnaptogrid.h
  82. +5 −0 src/analysis/processing/qgsalgorithmsplitwithlines.cpp
  83. +1 −0 src/analysis/processing/qgsalgorithmsplitwithlines.h
  84. +1 −1 src/analysis/processing/qgsalgorithmstringconcatenation.cpp
  85. +5 −0 src/analysis/processing/qgsalgorithmsubdivide.cpp
  86. +1 −0 src/analysis/processing/qgsalgorithmsubdivide.h
  87. +5 −0 src/analysis/processing/qgsalgorithmtransect.cpp
  88. +1 −0 src/analysis/processing/qgsalgorithmtransect.h
  89. +5 −0 src/analysis/processing/qgsalgorithmtransform.cpp
  90. +1 −0 src/analysis/processing/qgsalgorithmtransform.h
  91. +5 −0 src/analysis/processing/qgsalgorithmtranslate.cpp
  92. +1 −0 src/analysis/processing/qgsalgorithmtranslate.h
@@ -28,7 +28,7 @@
from pprint import pformat
import time

from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtCore import QCoreApplication, Qt
from qgis.PyQt.QtWidgets import QMessageBox, QPushButton, QSizePolicy, QDialogButtonBox
from qgis.PyQt.QtGui import QColor, QPalette

@@ -241,14 +241,14 @@ def on_complete(ok, results):
feedback.pushInfo('')

self.cancelButton().setEnabled(False)

self.finish(ok, results, context, feedback)

if self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanRunInBackground:
task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback)
task.executed.connect(on_complete)
QgsApplication.taskManager().addTask(task)
else:
self.setWindowModality(Qt.ApplicationModal)
ok, results = execute(self.algorithm(), parameters, context, feedback)
on_complete(ok, results)

@@ -31,6 +31,11 @@ QString QgsTessellateAlgorithm::displayName() const
return QObject::tr( "Tessellate" );
}

QgsProcessingAlgorithm::Flags QgsTessellateAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QStringList QgsTessellateAlgorithm::tags() const
{
return QObject::tr( "3d,triangle" ).split( ',' );
@@ -36,6 +36,7 @@ class QgsTessellateAlgorithm : public QgsProcessingFeatureBasedAlgorithm
QgsTessellateAlgorithm() = default;
QString name() const override;
QString displayName() const override;
Flags flags() const override;
QStringList tags() const override;
QString group() const override;
QString shortHelpString() const override;
@@ -19,6 +19,11 @@

///@cond PRIVATE

QgsProcessingAlgorithm::Flags QgsAddIncrementalFieldAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsAddIncrementalFieldAlgorithm::name() const
{
return QStringLiteral( "addautoincrementalfield" );
@@ -34,6 +34,7 @@ class QgsAddIncrementalFieldAlgorithm : public QgsProcessingFeatureBasedAlgorith
public:

QgsAddIncrementalFieldAlgorithm() = default;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -19,6 +19,11 @@

///@cond PRIVATE

QgsProcessingAlgorithm::Flags QgsAssignProjectionAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsAssignProjectionAlgorithm::name() const
{
return QStringLiteral( "assignprojection" );
@@ -34,6 +34,7 @@ class QgsAssignProjectionAlgorithm : public QgsProcessingFeatureBasedAlgorithm
public:

QgsAssignProjectionAlgorithm() = default;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -19,6 +19,11 @@

///@cond PRIVATE

QgsProcessingAlgorithm::Flags QgsBoundaryAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsBoundaryAlgorithm::name() const
{
return QStringLiteral( "boundary" );
@@ -34,6 +34,7 @@ class QgsBoundaryAlgorithm : public QgsProcessingFeatureBasedAlgorithm
public:

QgsBoundaryAlgorithm() = default;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -19,6 +19,11 @@

///@cond PRIVATE

QgsProcessingAlgorithm::Flags QgsBoundingBoxAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsBoundingBoxAlgorithm::name() const
{
return QStringLiteral( "boundingboxes" );
@@ -34,6 +34,7 @@ class QgsBoundingBoxAlgorithm : public QgsProcessingFeatureBasedAlgorithm
public:

QgsBoundingBoxAlgorithm() = default;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -63,6 +63,11 @@ void QgsBufferAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Buffered" ), QgsProcessing::TypeVectorPolygon ) );
}

QgsProcessingAlgorithm::Flags QgsBufferAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsBufferAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm computes a buffer area for all the features in an input layer, using a fixed or dynamic distance.\n\n"
@@ -35,7 +35,7 @@ class QgsBufferAlgorithm : public QgsProcessingAlgorithm

QgsBufferAlgorithm() = default;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;

Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -49,6 +49,11 @@ QString QgsCentroidAlgorithm::outputName() const
return QObject::tr( "Centroids" );
}

QgsProcessingAlgorithm::Flags QgsCentroidAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

void QgsCentroidAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
@@ -34,6 +34,7 @@ class QgsCentroidAlgorithm : public QgsProcessingFeatureBasedAlgorithm
public:

QgsCentroidAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override;
@@ -40,6 +40,11 @@ QString QgsClipAlgorithm::group() const
return QObject::tr( "Vector overlay" );
}

QgsProcessingAlgorithm::Flags QgsClipAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsClipAlgorithm::groupId() const
{
return QStringLiteral( "vectoroverlay" );
@@ -34,6 +34,7 @@ class QgsClipAlgorithm : public QgsProcessingAlgorithm
public:

QgsClipAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override;
@@ -19,6 +19,11 @@

///@cond PRIVATE

QgsProcessingAlgorithm::Flags QgsConvexHullAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsConvexHullAlgorithm::name() const
{
return QStringLiteral( "convexhull" );
@@ -35,6 +35,7 @@ class QgsConvexHullAlgorithm : public QgsProcessingFeatureBasedAlgorithm
public:

QgsConvexHullAlgorithm() = default;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -23,6 +23,11 @@
// QgsCollectorAlgorithm
//

QgsProcessingAlgorithm::Flags QgsCollectorAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QVariantMap QgsCollectorAlgorithm::processCollection( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback,
const std::function<QgsGeometry( const QVector< QgsGeometry >& )> &collector, int maxQueueLength )
{
@@ -32,6 +32,7 @@ class QgsCollectorAlgorithm : public QgsProcessingAlgorithm
{
protected:

Flags flags() const override;
QVariantMap processCollection( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback,
const std::function<QgsGeometry( const QVector<QgsGeometry>& )> &collector, int maxQueueLength = 0 );
};
@@ -19,6 +19,11 @@

///@cond PRIVATE

QgsProcessingAlgorithm::Flags QgsDropGeometryAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsDropGeometryAlgorithm::name() const
{
return QStringLiteral( "dropgeometries" );
@@ -34,6 +34,7 @@ class QgsDropGeometryAlgorithm : public QgsProcessingFeatureBasedAlgorithm
public:

QgsDropGeometryAlgorithm() = default;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -19,6 +19,11 @@

///@cond PRIVATE

QgsProcessingAlgorithm::Flags QgsDropMZValuesAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsDropMZValuesAlgorithm::name() const
{
return QStringLiteral( "dropmzvalues" );
@@ -34,6 +34,7 @@ class QgsDropMZValuesAlgorithm : public QgsProcessingFeatureBasedAlgorithm
public:

QgsDropMZValuesAlgorithm() = default;
Flags flags() const override;
QString name() const override;
QString displayName() const override;
QStringList tags() const override;
@@ -24,6 +24,11 @@ QString QgsExtentToLayerAlgorithm::name() const
return QStringLiteral( "extenttolayer" );
}

QgsProcessingAlgorithm::Flags QgsExtentToLayerAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

void QgsExtentToLayerAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterExtent( QStringLiteral( "INPUT" ), QObject::tr( "Extent" ) ) );
@@ -34,6 +34,7 @@ class QgsExtentToLayerAlgorithm : public QgsProcessingAlgorithm
public:

QgsExtentToLayerAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override { return QObject::tr( "Create layer from extent" ); }
@@ -39,6 +39,11 @@ QString QgsExtractByAttributeAlgorithm::group() const
return QObject::tr( "Vector selection" );
}

QgsProcessingAlgorithm::Flags QgsExtractByAttributeAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

QString QgsExtractByAttributeAlgorithm::groupId() const
{
return QStringLiteral( "vectorselection" );
@@ -49,6 +49,7 @@ class QgsExtractByAttributeAlgorithm : public QgsProcessingAlgorithm
};

QgsExtractByAttributeAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override;
@@ -44,6 +44,11 @@ QString QgsExtractByExpressionAlgorithm::groupId() const
return QStringLiteral( "vectorselection" );
}

QgsProcessingAlgorithm::Flags QgsExtractByExpressionAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

void QgsExtractByExpressionAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
@@ -34,6 +34,7 @@ class QgsExtractByExpressionAlgorithm : public QgsProcessingAlgorithm
public:

QgsExtractByExpressionAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override;
@@ -44,6 +44,11 @@ QString QgsExtractByExtentAlgorithm::groupId() const
return QStringLiteral( "vectoroverlay" );
}

QgsProcessingAlgorithm::Flags QgsExtractByExtentAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

void QgsExtractByExtentAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
@@ -34,6 +34,7 @@ class QgsExtractByExtentAlgorithm : public QgsProcessingAlgorithm
public:

QgsExtractByExtentAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override;
@@ -286,6 +286,11 @@ QVariantMap QgsSelectByLocationAlgorithm::processAlgorithm( const QVariantMap &p
// QgsExtractByLocationAlgorithm
//

QgsProcessingAlgorithm::Flags QgsExtractByLocationAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

void QgsExtractByLocationAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterVectorLayer( QStringLiteral( "INPUT" ), QObject::tr( "Extract features from" ),
@@ -87,6 +87,7 @@ class QgsExtractByLocationAlgorithm : public QgsLocationBasedAlgorithm
public:

QgsExtractByLocationAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override;
@@ -59,6 +59,11 @@ QgsExtractNodesAlgorithm *QgsExtractNodesAlgorithm::createInstance() const
return new QgsExtractNodesAlgorithm();
}

QgsProcessingAlgorithm::Flags QgsExtractNodesAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

void QgsExtractNodesAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
@@ -34,6 +34,7 @@ class QgsExtractNodesAlgorithm : public QgsProcessingAlgorithm
public:

QgsExtractNodesAlgorithm() = default;
Flags flags() const override;
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
QString name() const override;
QString displayName() const override;
@@ -60,6 +60,11 @@ QgsFileDownloaderAlgorithm *QgsFileDownloaderAlgorithm::createInstance() const
return new QgsFileDownloaderAlgorithm();
}

QgsProcessingAlgorithm::Flags QgsFileDownloaderAlgorithm::flags() const
{
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}

void QgsFileDownloaderAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterString( QStringLiteral( "URL" ), tr( "URL" ), QVariant(), false, false ) );

0 comments on commit c14e6ca

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