mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-04 00:06:46 -05:00
Merge pull request #34928 from gacarrillor/adjust_run_button_status_in_alg_dialog
[processing][needs-docs] Adjust status of controls executing an algorithm dialog
This commit is contained in:
commit
01c7cb1814
@ -73,6 +73,11 @@ Returns the main widget for the dialog, usually a panel for configuring algorith
|
||||
void showLog();
|
||||
%Docstring
|
||||
Switches the dialog to the log page.
|
||||
%End
|
||||
|
||||
void showParameters();
|
||||
%Docstring
|
||||
Switches the dialog to the parameters page.
|
||||
%End
|
||||
|
||||
bool wasExecuted() const;
|
||||
@ -195,6 +200,11 @@ Returns the dialog's run button.
|
||||
QPushButton *cancelButton();
|
||||
%Docstring
|
||||
Returns the dialog's cancel button.
|
||||
%End
|
||||
|
||||
QPushButton *changeParametersButton();
|
||||
%Docstring
|
||||
Returns the dialog's change parameters button.
|
||||
%End
|
||||
|
||||
QDialogButtonBox *buttonBox();
|
||||
@ -221,6 +231,12 @@ Sets whether the algorithm was executed through the dialog.
|
||||
.. seealso:: :py:func:`setResults`
|
||||
%End
|
||||
|
||||
void setExecutedAnyResult( bool executedAnyResult );
|
||||
%Docstring
|
||||
Sets whether the algorithm was executed through the dialog (no matter the result).
|
||||
%End
|
||||
|
||||
|
||||
void setResults( const QVariantMap &results );
|
||||
%Docstring
|
||||
Sets the algorithm results.
|
||||
@ -238,6 +254,29 @@ Displays an info ``message`` in the dialog's log.
|
||||
void resetGui();
|
||||
%Docstring
|
||||
Resets the dialog's gui, ready for another algorithm execution.
|
||||
%End
|
||||
|
||||
virtual void resetAdditionalGui();
|
||||
%Docstring
|
||||
For subclasses to register their own GUI controls to be reset, ready
|
||||
for another algorithm execution.
|
||||
%End
|
||||
|
||||
void updateRunButtonVisibility();
|
||||
%Docstring
|
||||
Sets visibility for mutually exclusive buttons Run and Change Parameters.
|
||||
%End
|
||||
|
||||
void blockControlsWhileRunning();
|
||||
%Docstring
|
||||
Blocks run and changeParameters buttons and parameters tab while the
|
||||
algorithm is running.
|
||||
%End
|
||||
|
||||
virtual void blockAdditionalControlsWhileRunning();
|
||||
%Docstring
|
||||
For subclasses to register their own GUI controls to be blocked while
|
||||
the algorithm is running.
|
||||
%End
|
||||
|
||||
QgsMessageBar *messageBar();
|
||||
|
||||
@ -90,6 +90,8 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
self.buttonBox().button(QDialogButtonBox.Close).setText(QCoreApplication.translate("AlgorithmDialog", "Cancel"))
|
||||
self.setWindowTitle(self.windowTitle() + ' | ' + self.active_layer.name())
|
||||
|
||||
self.updateRunButtonVisibility()
|
||||
|
||||
def getParametersPanel(self, alg, parent):
|
||||
return ParametersPanel(parent, alg, self.in_place)
|
||||
|
||||
@ -99,6 +101,14 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
dlg.show()
|
||||
dlg.exec_()
|
||||
|
||||
def resetAdditionalGui(self):
|
||||
if not self.in_place:
|
||||
self.runAsBatchButton.setEnabled(True)
|
||||
|
||||
def blockAdditionalControlsWhileRunning(self):
|
||||
if not self.in_place:
|
||||
self.runAsBatchButton.setEnabled(False)
|
||||
|
||||
def setParameters(self, parameters):
|
||||
self.mainWidget().setParameters(parameters)
|
||||
|
||||
@ -189,7 +199,9 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
QMessageBox.warning(
|
||||
self, self.tr('Unable to execute algorithm'), msg)
|
||||
return
|
||||
self.runButton().setEnabled(False)
|
||||
|
||||
self.blockControlsWhileRunning()
|
||||
self.setExecutedAnyResult(True)
|
||||
self.cancelButton().setEnabled(False)
|
||||
buttons = self.mainWidget().iterateButtons
|
||||
self.iterateParam = None
|
||||
|
||||
@ -77,6 +77,8 @@ class BatchAlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
self.btnRunSingle.clicked.connect(self.runAsSingle)
|
||||
self.buttonBox().addButton(self.btnRunSingle, QDialogButtonBox.ResetRole) # reset role to ensure left alignment
|
||||
|
||||
self.updateRunButtonVisibility()
|
||||
|
||||
def runAsSingle(self):
|
||||
self.close()
|
||||
|
||||
@ -85,6 +87,12 @@ class BatchAlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
dlg.show()
|
||||
dlg.exec_()
|
||||
|
||||
def resetAdditionalGui(self):
|
||||
self.btnRunSingle.setEnabled(True)
|
||||
|
||||
def blockAdditionalControlsWhileRunning(self):
|
||||
self.btnRunSingle.setEnabled(False)
|
||||
|
||||
def runAlgorithm(self):
|
||||
alg_parameters = []
|
||||
|
||||
@ -106,7 +114,8 @@ class BatchAlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
|
||||
with OverrideCursor(Qt.WaitCursor):
|
||||
|
||||
self.mainWidget().setEnabled(False)
|
||||
self.blockControlsWhileRunning()
|
||||
self.setExecutedAnyResult(True)
|
||||
self.cancelButton().setEnabled(True)
|
||||
|
||||
# Make sure the Log tab is visible before executing the algorithm
|
||||
@ -178,7 +187,6 @@ class BatchAlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
||||
self.loadHTMLResults(results['results'], count)
|
||||
|
||||
self.createSummaryTable(algorithm_results, errors)
|
||||
self.mainWidget().setEnabled(True)
|
||||
self.resetGui()
|
||||
|
||||
def loadHTMLResults(self, results, num):
|
||||
|
||||
@ -105,6 +105,10 @@ QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *par
|
||||
buttonCancel->setEnabled( false );
|
||||
mButtonClose = mButtonBox->button( QDialogButtonBox::Close );
|
||||
|
||||
mButtonChangeParameters = new QPushButton( tr( "Change Parameters" ) );
|
||||
mButtonBox->addButton( mButtonChangeParameters, QDialogButtonBox::ActionRole );
|
||||
|
||||
connect( mButtonChangeParameters, &QPushButton::clicked, this, &QgsProcessingAlgorithmDialogBase::showParameters );
|
||||
connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsProcessingAlgorithmDialogBase::openHelp );
|
||||
connect( mButtonCollapse, &QToolButton::clicked, this, &QgsProcessingAlgorithmDialogBase::toggleCollapsed );
|
||||
connect( splitter, &QSplitter::splitterMoved, this, &QgsProcessingAlgorithmDialogBase::splitterChanged );
|
||||
@ -113,6 +117,8 @@ QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *par
|
||||
connect( mButtonCopyLog, &QToolButton::clicked, this, &QgsProcessingAlgorithmDialogBase::copyLogToClipboard );
|
||||
connect( mButtonClearLog, &QToolButton::clicked, this, &QgsProcessingAlgorithmDialogBase::clearLog );
|
||||
|
||||
connect( mTabWidget, &QTabWidget::currentChanged, this, &QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged );
|
||||
|
||||
mMessageBar = new QgsMessageBar();
|
||||
mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
|
||||
verticalLayout->insertWidget( 0, mMessageBar );
|
||||
@ -239,6 +245,11 @@ void QgsProcessingAlgorithmDialogBase::showLog()
|
||||
mTabWidget->setCurrentIndex( 1 );
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::showParameters()
|
||||
{
|
||||
mTabWidget->setCurrentIndex( 0 );
|
||||
}
|
||||
|
||||
QPushButton *QgsProcessingAlgorithmDialogBase::runButton()
|
||||
{
|
||||
return mButtonRun;
|
||||
@ -249,6 +260,11 @@ QPushButton *QgsProcessingAlgorithmDialogBase::cancelButton()
|
||||
return buttonCancel;
|
||||
}
|
||||
|
||||
QPushButton *QgsProcessingAlgorithmDialogBase::changeParametersButton()
|
||||
{
|
||||
return mButtonChangeParameters;
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::clearProgress()
|
||||
{
|
||||
progressBar->setMaximum( 0 );
|
||||
@ -259,6 +275,11 @@ void QgsProcessingAlgorithmDialogBase::setExecuted( bool executed )
|
||||
mExecuted = executed;
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::setExecutedAnyResult( bool executedAnyResult )
|
||||
{
|
||||
mExecutedAnyResult = executedAnyResult;
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::setResults( const QVariantMap &results )
|
||||
{
|
||||
mResults = results;
|
||||
@ -311,6 +332,11 @@ void QgsProcessingAlgorithmDialogBase::splitterChanged( int, int )
|
||||
}
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged( int )
|
||||
{
|
||||
updateRunButtonVisibility();
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::linkClicked( const QUrl &url )
|
||||
{
|
||||
QDesktopServices::openUrl( url.toString() );
|
||||
@ -553,7 +579,43 @@ void QgsProcessingAlgorithmDialogBase::resetGui()
|
||||
progressBar->setMaximum( 100 );
|
||||
progressBar->setValue( 0 );
|
||||
mButtonRun->setEnabled( true );
|
||||
mButtonChangeParameters->setEnabled( true );
|
||||
mButtonClose->setEnabled( true );
|
||||
if ( mMainWidget )
|
||||
{
|
||||
mMainWidget->setEnabled( true );
|
||||
}
|
||||
updateRunButtonVisibility();
|
||||
resetAdditionalGui();
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::updateRunButtonVisibility()
|
||||
{
|
||||
// Activate run button if current tab is Parameters
|
||||
bool runButtonVisible = mTabWidget->currentIndex() == 0;
|
||||
mButtonRun->setVisible( runButtonVisible );
|
||||
mButtonChangeParameters->setVisible( !runButtonVisible && mExecutedAnyResult && mButtonChangeParameters->isEnabled() );
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::resetAdditionalGui()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::blockControlsWhileRunning()
|
||||
{
|
||||
mButtonRun->setEnabled( false );
|
||||
mButtonChangeParameters->setEnabled( false );
|
||||
if ( mMainWidget )
|
||||
{
|
||||
mMainWidget->setEnabled( false );
|
||||
}
|
||||
blockAdditionalControlsWhileRunning();
|
||||
}
|
||||
|
||||
void QgsProcessingAlgorithmDialogBase::blockAdditionalControlsWhileRunning()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QgsMessageBar *QgsProcessingAlgorithmDialogBase::messageBar()
|
||||
|
||||
@ -133,6 +133,11 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
|
||||
*/
|
||||
void showLog();
|
||||
|
||||
/**
|
||||
* Switches the dialog to the parameters page.
|
||||
*/
|
||||
void showParameters();
|
||||
|
||||
/**
|
||||
* Returns TRUE if an algorithm was executed in the dialog.
|
||||
* \see results()
|
||||
@ -244,6 +249,11 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
|
||||
*/
|
||||
QPushButton *cancelButton();
|
||||
|
||||
/**
|
||||
* Returns the dialog's change parameters button.
|
||||
*/
|
||||
QPushButton *changeParametersButton();
|
||||
|
||||
/**
|
||||
* Returns the dialog's button box.
|
||||
*/
|
||||
@ -266,6 +276,12 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
|
||||
*/
|
||||
void setExecuted( bool executed );
|
||||
|
||||
/**
|
||||
* Sets whether the algorithm was executed through the dialog (no matter the result).
|
||||
*/
|
||||
void setExecutedAnyResult( bool executedAnyResult );
|
||||
|
||||
|
||||
/**
|
||||
* Sets the algorithm results.
|
||||
* \see results()
|
||||
@ -283,6 +299,29 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
|
||||
*/
|
||||
void resetGui();
|
||||
|
||||
/**
|
||||
* For subclasses to register their own GUI controls to be reset, ready
|
||||
* for another algorithm execution.
|
||||
*/
|
||||
virtual void resetAdditionalGui();
|
||||
|
||||
/**
|
||||
* Sets visibility for mutually exclusive buttons Run and Change Parameters.
|
||||
*/
|
||||
void updateRunButtonVisibility();
|
||||
|
||||
/**
|
||||
* Blocks run and changeParameters buttons and parameters tab while the
|
||||
* algorithm is running.
|
||||
*/
|
||||
void blockControlsWhileRunning();
|
||||
|
||||
/**
|
||||
* For subclasses to register their own GUI controls to be blocked while
|
||||
* the algorithm is running.
|
||||
*/
|
||||
virtual void blockAdditionalControlsWhileRunning();
|
||||
|
||||
/**
|
||||
* Returns the dialog's message bar.
|
||||
*/
|
||||
@ -324,6 +363,7 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
|
||||
void toggleCollapsed();
|
||||
|
||||
void splitterChanged( int pos, int index );
|
||||
void mTabWidget_currentChanged( int index );
|
||||
void linkClicked( const QUrl &url );
|
||||
void algExecuted( bool successful, const QVariantMap &results );
|
||||
void taskTriggered( QgsTask *task );
|
||||
@ -333,11 +373,13 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::
|
||||
|
||||
QPushButton *mButtonRun = nullptr;
|
||||
QPushButton *mButtonClose = nullptr;
|
||||
QPushButton *mButtonChangeParameters = nullptr;
|
||||
QByteArray mSplitterState;
|
||||
QToolButton *mButtonCollapse = nullptr;
|
||||
QgsMessageBar *mMessageBar = nullptr;
|
||||
|
||||
bool mExecuted = false;
|
||||
bool mExecutedAnyResult = false;
|
||||
QVariantMap mResults;
|
||||
QWidget *mMainWidget = nullptr;
|
||||
std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user