Skip to content
Permalink
Browse files

Merge pull request #5807 from nyalldawson/alg_background

[processing] Add flag to indicate whether an algorithm is safe
  • Loading branch information
nyalldawson committed Jan 10, 2018
2 parents 6894c8e + 240c52a commit 0a3f9f60ffbc71b1c3c564611c7798f5571f02cd
Showing with 515 additions and 20 deletions.
  1. +1 −0 python/core/processing/qgsprocessingalgorithm.sip
  2. +7 −0 python/gui/processing/qgsprocessingalgorithmdialogbase.sip
  3. +28 −11 python/plugins/processing/gui/AlgorithmDialog.py
  4. +5 −0 src/3d/processing/qgsalgorithmtessellate.cpp
  5. +1 −0 src/3d/processing/qgsalgorithmtessellate.h
  6. +6 −0 src/analysis/network/qgsgraphanalyzer.cpp
  7. +5 −0 src/analysis/processing/qgsalgorithmaddincrementalfield.cpp
  8. +1 −0 src/analysis/processing/qgsalgorithmaddincrementalfield.h
  9. +5 −0 src/analysis/processing/qgsalgorithmassignprojection.cpp
  10. +1 −0 src/analysis/processing/qgsalgorithmassignprojection.h
  11. +5 −0 src/analysis/processing/qgsalgorithmboundary.cpp
  12. +1 −0 src/analysis/processing/qgsalgorithmboundary.h
  13. +5 −0 src/analysis/processing/qgsalgorithmboundingbox.cpp
  14. +1 −0 src/analysis/processing/qgsalgorithmboundingbox.h
  15. +5 −0 src/analysis/processing/qgsalgorithmbuffer.cpp
  16. +1 −1 src/analysis/processing/qgsalgorithmbuffer.h
  17. +5 −0 src/analysis/processing/qgsalgorithmcentroid.cpp
  18. +1 −0 src/analysis/processing/qgsalgorithmcentroid.h
  19. +5 −0 src/analysis/processing/qgsalgorithmclip.cpp
  20. +1 −0 src/analysis/processing/qgsalgorithmclip.h
  21. +5 −0 src/analysis/processing/qgsalgorithmconvexhull.cpp
  22. +1 −0 src/analysis/processing/qgsalgorithmconvexhull.h
  23. +5 −0 src/analysis/processing/qgsalgorithmdissolve.cpp
  24. +1 −0 src/analysis/processing/qgsalgorithmdissolve.h
  25. +5 −0 src/analysis/processing/qgsalgorithmdropgeometry.cpp
  26. +1 −0 src/analysis/processing/qgsalgorithmdropgeometry.h
  27. +5 −0 src/analysis/processing/qgsalgorithmdropmzvalues.cpp
  28. +1 −0 src/analysis/processing/qgsalgorithmdropmzvalues.h
  29. +5 −0 src/analysis/processing/qgsalgorithmextenttolayer.cpp
  30. +1 −0 src/analysis/processing/qgsalgorithmextenttolayer.h
  31. +5 −0 src/analysis/processing/qgsalgorithmextractbyattribute.cpp
  32. +1 −0 src/analysis/processing/qgsalgorithmextractbyattribute.h
  33. +5 −0 src/analysis/processing/qgsalgorithmextractbyexpression.cpp
  34. +1 −0 src/analysis/processing/qgsalgorithmextractbyexpression.h
  35. +5 −0 src/analysis/processing/qgsalgorithmextractbyextent.cpp
  36. +1 −0 src/analysis/processing/qgsalgorithmextractbyextent.h
  37. +5 −0 src/analysis/processing/qgsalgorithmextractbylocation.cpp
  38. +1 −0 src/analysis/processing/qgsalgorithmextractbylocation.h
  39. +5 −0 src/analysis/processing/qgsalgorithmextractnodes.cpp
  40. +1 −0 src/analysis/processing/qgsalgorithmextractnodes.h
  41. +5 −0 src/analysis/processing/qgsalgorithmfiledownloader.cpp
  42. +1 −0 src/analysis/processing/qgsalgorithmfiledownloader.h
  43. +5 −0 src/analysis/processing/qgsalgorithmfixgeometries.cpp
  44. +1 −0 src/analysis/processing/qgsalgorithmfixgeometries.h
  45. +5 −0 src/analysis/processing/qgsalgorithmjoinbyattribute.cpp
  46. +1 −0 src/analysis/processing/qgsalgorithmjoinbyattribute.h
  47. +5 −0 src/analysis/processing/qgsalgorithmjoinwithlines.cpp
  48. +1 −0 src/analysis/processing/qgsalgorithmjoinwithlines.h
  49. +5 −0 src/analysis/processing/qgsalgorithmlineintersection.cpp
  50. +1 −0 src/analysis/processing/qgsalgorithmlineintersection.h
  51. +1 −1 src/analysis/processing/qgsalgorithmloadlayer.cpp
  52. +5 −0 src/analysis/processing/qgsalgorithmmeancoordinates.cpp
  53. +1 −0 src/analysis/processing/qgsalgorithmmeancoordinates.h
  54. +5 −0 src/analysis/processing/qgsalgorithmmergelines.cpp
  55. +1 −0 src/analysis/processing/qgsalgorithmmergelines.h
  56. +5 −0 src/analysis/processing/qgsalgorithmmergevector.cpp
  57. +1 −0 src/analysis/processing/qgsalgorithmmergevector.h
  58. +5 −0 src/analysis/processing/qgsalgorithmminimumenclosingcircle.cpp
  59. +1 −0 src/analysis/processing/qgsalgorithmminimumenclosingcircle.h
  60. +5 −0 src/analysis/processing/qgsalgorithmmultiparttosinglepart.cpp
  61. +1 −0 src/analysis/processing/qgsalgorithmmultiparttosinglepart.h
  62. +5 −0 src/analysis/processing/qgsalgorithmorderbyexpression.cpp
  63. +1 −0 src/analysis/processing/qgsalgorithmorderbyexpression.h
  64. +5 −0 src/analysis/processing/qgsalgorithmorientedminimumboundingbox.cpp
  65. +1 −0 src/analysis/processing/qgsalgorithmorientedminimumboundingbox.h
  66. +5 −0 src/analysis/processing/qgsalgorithmpackage.cpp
  67. +1 −0 src/analysis/processing/qgsalgorithmpackage.h
  68. +5 −0 src/analysis/processing/qgsalgorithmpromotetomultipart.cpp
  69. +1 −0 src/analysis/processing/qgsalgorithmpromotetomultipart.h
  70. +5 −0 src/analysis/processing/qgsalgorithmrasterlayeruniquevalues.cpp
  71. +1 −0 src/analysis/processing/qgsalgorithmrasterlayeruniquevalues.h
  72. +5 −0 src/analysis/processing/qgsalgorithmremoveduplicatenodes.cpp
  73. +1 −0 src/analysis/processing/qgsalgorithmremoveduplicatenodes.h
  74. +5 −0 src/analysis/processing/qgsalgorithmremovenullgeometry.cpp
  75. +1 −0 src/analysis/processing/qgsalgorithmremovenullgeometry.h
  76. +1 −1 src/analysis/processing/qgsalgorithmrenamelayer.cpp
  77. +5 −0 src/analysis/processing/qgsalgorithmsaveselectedfeatures.cpp
  78. +1 −0 src/analysis/processing/qgsalgorithmsaveselectedfeatures.h
  79. +5 −0 src/analysis/processing/qgsalgorithmsimplify.cpp
  80. +1 −0 src/analysis/processing/qgsalgorithmsimplify.h
  81. +5 −0 src/analysis/processing/qgsalgorithmsmooth.cpp
  82. +1 −0 src/analysis/processing/qgsalgorithmsmooth.h
  83. +5 −0 src/analysis/processing/qgsalgorithmsnaptogrid.cpp
  84. +1 −0 src/analysis/processing/qgsalgorithmsnaptogrid.h
  85. +5 −0 src/analysis/processing/qgsalgorithmsplitwithlines.cpp
  86. +1 −0 src/analysis/processing/qgsalgorithmsplitwithlines.h
  87. +1 −1 src/analysis/processing/qgsalgorithmstringconcatenation.cpp
  88. +5 −0 src/analysis/processing/qgsalgorithmsubdivide.cpp
  89. +1 −0 src/analysis/processing/qgsalgorithmsubdivide.h
  90. +5 −0 src/analysis/processing/qgsalgorithmtransect.cpp
  91. +1 −0 src/analysis/processing/qgsalgorithmtransect.h
  92. +5 −0 src/analysis/processing/qgsalgorithmtransform.cpp
  93. +1 −0 src/analysis/processing/qgsalgorithmtransform.h
  94. +5 −0 src/analysis/processing/qgsalgorithmtranslate.cpp
  95. +1 −0 src/analysis/processing/qgsalgorithmtranslate.h
  96. +1 −0 src/core/processing/qgsprocessingalgorithm.h
  97. +90 −1 src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
  98. +51 −0 src/gui/processing/qgsprocessingalgorithmdialogbase.h
  99. +9 −4 src/gui/qgstaskmanagerwidget.cpp
  100. +55 −0 src/ui/processing/qgsprocessingalgorithmprogressdialogbase.ui
@@ -44,6 +44,7 @@ Abstract base class for processing algorithms.
FlagSupportsBatch,
FlagCanCancel,
FlagRequiresMatchingCrs,
FlagCanRunInBackground,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
@@ -133,6 +133,12 @@ Sets a progress text message.
void pushConsoleInfo( const QString &info );
%Docstring
Pushes a console info string to the dialog's log.
%End

QDialog *createProgressDialog();
%Docstring
Creates a modal progress dialog showing progress and log messages
from this dialog.
%End

protected:
@@ -210,6 +216,7 @@ Called when the algorithm has finished executing.
};



/************************************************************************
* This file has been generated automatically from *
* *
@@ -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

@@ -53,7 +53,7 @@
from processing.gui.ParametersPanel import ParametersPanel
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
from processing.gui.AlgorithmExecutor import executeIterating
from processing.gui.AlgorithmExecutor import executeIterating, execute
from processing.gui.Postprocessing import handleAlgorithmResults

from processing.tools import dataobjects
@@ -63,6 +63,7 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):

def __init__(self, alg):
super().__init__()
self.feedback_dialog = None

self.setAlgorithm(alg)
self.setMainWidget(self.getParametersPanel(alg, self))
@@ -196,12 +197,6 @@ def accept(self):

self.clearProgress()
self.setProgressText(self.tr('Processing algorithm...'))
# Make sure the Log tab is visible before executing the algorithm
try:
self.showLog()
self.repaint()
except:
pass

self.setInfo(
self.tr('<b>Algorithm \'{0}\' starting...</b>').format(self.algorithm().displayName()), escapeHtml=False)
@@ -215,6 +210,13 @@ def accept(self):
start_time = time.time()

if self.iterateParam:
# Make sure the Log tab is visible before executing the algorithm
try:
self.showLog()
self.repaint()
except:
pass

self.cancelButton().setEnabled(self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanCancel)
if executeIterating(self.algorithm(), parameters, self.iterateParam, context, feedback):
feedback.pushInfo(
@@ -240,12 +242,27 @@ def on_complete(ok, results):
self.tr('Execution failed after {0:0.2f} seconds'.format(time.time() - start_time)))
feedback.pushInfo('')

if self.feedback_dialog is not None:
self.feedback_dialog.close()
self.feedback_dialog.deleteLater()
self.feedback_dialog = None

self.cancelButton().setEnabled(False)

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

task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback)
task.executed.connect(on_complete)
QgsApplication.taskManager().addTask(task)
if self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanRunInBackground:
# Make sure the Log tab is visible before executing the algorithm
self.showLog()

task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback)
task.executed.connect(on_complete)
QgsApplication.taskManager().addTask(task)
else:
self.feedback_dialog = self.createProgressDialog()
self.feedback_dialog.show()
ok, results = execute(self.algorithm(), parameters, context, feedback)
on_complete(ok, results)

except AlgorithmDialogBase.InvalidParameterValue as e:
try:
@@ -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;
@@ -24,6 +24,12 @@

void QgsGraphAnalyzer::dijkstra( const QgsGraph *source, int startPointIdx, int criterionNum, QVector<int> *resultTree, QVector<double> *resultCost )
{
if ( startPointIdx < 0 || startPointIdx >= source->vertexCount() )
{
// invalid start point
return;
}

QVector< double > *result = nullptr;
if ( resultCost )
{
@@ -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" );

0 comments on commit 0a3f9f6

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