Navigation Menu

Skip to content

Commit

Permalink
Fix ownership of algorithm instance used by processing dialog
Browse files Browse the repository at this point in the history
(cherry picked from commit a350b42)
  • Loading branch information
nyalldawson committed Nov 23, 2018
1 parent 049c65c commit d1cec84
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Expand Up @@ -38,11 +38,14 @@ Base class for processing algorithm dialogs.
%Docstring
Constructor for QgsProcessingAlgorithmDialogBase.
%End
~QgsProcessingAlgorithmDialogBase();

void setAlgorithm( QgsProcessingAlgorithm *algorithm );
void setAlgorithm( QgsProcessingAlgorithm *algorithm /Transfer/ );
%Docstring
Sets the ``algorithm`` to run in the dialog.

Ownership of the algorithm instance is transferred to the dialog.

.. seealso:: :py:func:`algorithm`
%End

Expand Down
6 changes: 4 additions & 2 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Expand Up @@ -119,9 +119,11 @@ QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *par
connect( QgsApplication::taskManager(), &QgsTaskManager::taskTriggered, this, &QgsProcessingAlgorithmDialogBase::taskTriggered );
}

QgsProcessingAlgorithmDialogBase::~QgsProcessingAlgorithmDialogBase() = default;

void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *algorithm )
{
mAlgorithm = algorithm;
mAlgorithm.reset( algorithm );
QString title;
if ( ( QgsGui::higFlags() & QgsGui::HigDialogTitleIsTitleCase ) && !( algorithm->flags() & QgsProcessingAlgorithm::FlagDisplayNameIsLiteral ) )
{
Expand Down Expand Up @@ -156,7 +158,7 @@ void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *alg

QgsProcessingAlgorithm *QgsProcessingAlgorithmDialogBase::algorithm()
{
return mAlgorithm;
return mAlgorithm.get();
}

void QgsProcessingAlgorithmDialogBase::setMainWidget( QWidget *widget )
Expand Down
8 changes: 6 additions & 2 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.h
Expand Up @@ -99,12 +99,16 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
* Constructor for QgsProcessingAlgorithmDialogBase.
*/
QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = nullptr );
~QgsProcessingAlgorithmDialogBase() override;

/**
* Sets the \a algorithm to run in the dialog.
*
* Ownership of the algorithm instance is transferred to the dialog.
*
* \see algorithm()
*/
void setAlgorithm( QgsProcessingAlgorithm *algorithm );
void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );

/**
* Returns the algorithm running in the dialog.
Expand Down Expand Up @@ -333,7 +337,7 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
bool mExecuted = false;
QVariantMap mResults;
QWidget *mMainWidget = nullptr;
QgsProcessingAlgorithm *mAlgorithm = nullptr;
std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;

bool mHelpCollapsed = false;
Expand Down

0 comments on commit d1cec84

Please sign in to comment.