Fix ownership of algorithm instance used by processing dialog

This commit is contained in:
Nyall Dawson 2018-11-17 14:49:37 +10:00
parent 4d97d20635
commit 47bf1f49d8
3 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -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 ) )
{
@ -156,7 +158,7 @@ void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *alg
QgsProcessingAlgorithm *QgsProcessingAlgorithmDialogBase::algorithm()
{
return mAlgorithm;
return mAlgorithm.get();
}
void QgsProcessingAlgorithmDialogBase::setMainWidget( QWidget *widget )

View File

@ -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.
@ -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;