Skip to content

Commit 47bf1f4

Browse files
committedNov 23, 2018
Fix ownership of algorithm instance used by processing dialog
1 parent 4d97d20 commit 47bf1f4

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed
 

‎python/gui/auto_generated/processing/qgsprocessingalgorithmdialogbase.sip.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ Base class for processing algorithm dialogs.
3838
%Docstring
3939
Constructor for QgsProcessingAlgorithmDialogBase.
4040
%End
41+
~QgsProcessingAlgorithmDialogBase();
4142

42-
void setAlgorithm( QgsProcessingAlgorithm *algorithm );
43+
void setAlgorithm( QgsProcessingAlgorithm *algorithm /Transfer/ );
4344
%Docstring
4445
Sets the ``algorithm`` to run in the dialog.
4546

47+
Ownership of the algorithm instance is transferred to the dialog.
48+
4649
.. seealso:: :py:func:`algorithm`
4750
%End
4851

‎src/gui/processing/qgsprocessingalgorithmdialogbase.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *par
119119
connect( QgsApplication::taskManager(), &QgsTaskManager::taskTriggered, this, &QgsProcessingAlgorithmDialogBase::taskTriggered );
120120
}
121121

122+
QgsProcessingAlgorithmDialogBase::~QgsProcessingAlgorithmDialogBase() = default;
123+
122124
void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *algorithm )
123125
{
124-
mAlgorithm = algorithm;
126+
mAlgorithm.reset( algorithm );
125127
QString title;
126128
if ( ( QgsGui::higFlags() & QgsGui::HigDialogTitleIsTitleCase ) && !( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral ) )
127129
{
@@ -156,7 +158,7 @@ void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *alg
156158

157159
QgsProcessingAlgorithm *QgsProcessingAlgorithmDialogBase::algorithm()
158160
{
159-
return mAlgorithm;
161+
return mAlgorithm.get();
160162
}
161163

162164
void QgsProcessingAlgorithmDialogBase::setMainWidget( QWidget *widget )

‎src/gui/processing/qgsprocessingalgorithmdialogbase.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
9999
* Constructor for QgsProcessingAlgorithmDialogBase.
100100
*/
101101
QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = nullptr );
102+
~QgsProcessingAlgorithmDialogBase() override;
102103

103104
/**
104105
* Sets the \a algorithm to run in the dialog.
106+
*
107+
* Ownership of the algorithm instance is transferred to the dialog.
108+
*
105109
* \see algorithm()
106110
*/
107-
void setAlgorithm( QgsProcessingAlgorithm *algorithm );
111+
void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
108112

109113
/**
110114
* Returns the algorithm running in the dialog.
@@ -333,7 +337,7 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
333337
bool mExecuted = false;
334338
QVariantMap mResults;
335339
QWidget *mMainWidget = nullptr;
336-
QgsProcessingAlgorithm *mAlgorithm = nullptr;
340+
std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
337341
QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
338342

339343
bool mHelpCollapsed = false;

0 commit comments

Comments
 (0)
Please sign in to comment.