Skip to content
Permalink
Browse files

Add a cancel button for algorithms which support cancelation

  • Loading branch information
nyalldawson committed Jun 6, 2017
1 parent 39d20a4 commit ab6442889150b929f03aaacdb6fdb19e0442c4e5
@@ -28,6 +28,7 @@ class QgsProcessingAlgorithm
FlagHideFromToolbox,
FlagHideFromModeler,
FlagSupportsBatch,
FlagCanCancel,
FlagDeprecated,
};
typedef QFlags<QgsProcessingAlgorithm::Flag> Flags;
@@ -128,6 +129,7 @@ class QgsProcessingAlgorithm
virtual Flags flags() const;
%Docstring
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Default flags are FlagSupportsBatch and FlagCanCancel.
:rtype: Flags
%End

@@ -36,7 +36,8 @@
QgsProcessingParameterDefinition,
QgsProcessingOutputVectorLayer,
QgsProcessingFeatureSinkDefinition,
QgsProcessingParameterFeatureSink)
QgsProcessingParameterFeatureSink,
QgsProcessingAlgorithm)
from qgis.gui import QgsMessageBar
from qgis.utils import iface

@@ -229,7 +230,9 @@ def accept(self):
#command = self.alg.getAsCommand()
#if command:
# ProcessingLog.addToLog(command)
self.buttonCancel.setEnabled(self.alg.flags() & QgsProcessingAlgorithm.FlagCanCancel)
result = executeAlgorithm(self.alg, parameters, context, self.feedback)
self.buttonCancel.setEnabled(False)
self.finish(result, context)
#TODO
#else:
@@ -84,6 +84,7 @@ def __init__(self, alg):

self.feedback = AlgorithmDialogFeedback(self)
self.feedback.progressChanged.connect(self.setPercentage)
self.buttonCancel.clicked.connect(self.feedback.cancel)

self.settings = QgsSettings()
self.restoreGeometry(self.settings.value("/Processing/dialogBase", QByteArray()))
@@ -96,6 +97,8 @@ def __init__(self, alg):
self.btnRun = self.buttonBox.button(QDialogButtonBox.Ok)
self.btnRun.setText(self.tr('Run'))

self.buttonCancel.setEnabled(False)

self.btnClose = self.buttonBox.button(QDialogButtonBox.Close)

self.setWindowTitle(self.alg.displayName())
@@ -29,7 +29,16 @@
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
@@ -42,7 +51,16 @@
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@@ -62,7 +80,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@@ -104,11 +131,25 @@
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
</widget>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
@@ -64,7 +64,7 @@ QString QgsProcessingAlgorithm::svgIconPath() const

QgsProcessingAlgorithm::Flags QgsProcessingAlgorithm::flags() const
{
return FlagSupportsBatch;
return FlagSupportsBatch | FlagCanCancel;
}

bool QgsProcessingAlgorithm::canExecute( QString * ) const
@@ -48,6 +48,7 @@ class CORE_EXPORT QgsProcessingAlgorithm
FlagHideFromToolbox = 1 << 1, //!< Algorithm should be hidden from the toolbox
FlagHideFromModeler = 1 << 2, //!< Algorithm should be hidden from the modeler
FlagSupportsBatch = 1 << 3, //!< Algorithm supports batch mode
FlagCanCancel = 1 << 4, //!< Algorithm can be canceled
FlagDeprecated = FlagHideFromToolbox | FlagHideFromModeler, //!< Algorithm is deprecated
};
Q_DECLARE_FLAGS( Flags, Flag )
@@ -140,6 +141,7 @@ class CORE_EXPORT QgsProcessingAlgorithm

/**
* Returns the flags indicating how and when the algorithm operates and should be exposed to users.
* Default flags are FlagSupportsBatch and FlagCanCancel.
*/
virtual Flags flags() const;

0 comments on commit ab64428

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