Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[feature] Add action in advanced menu for processing algorithm to copy
equivalent qgis_process command

Allows for easy generation of qgis_process commands via the QGIS gui
  • Loading branch information
nyalldawson committed Dec 16, 2021
1 parent fe471ea commit b4cb7ba
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Expand Up @@ -158,15 +158,51 @@ QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *par
}
} );

mCopyAsQgisProcessCommand = new QAction( tr( "Copy as qgis_process Command" ), mAdvancedMenu );
mCopyAsQgisProcessCommand->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "mActionTerminal.svg" ) ) );

mAdvancedMenu->addAction( mCopyAsQgisProcessCommand );
connect( mCopyAsQgisProcessCommand, &QAction::triggered, this, [this]
{
if ( const QgsProcessingAlgorithm *alg = algorithm() )
{
QgsProcessingContext *context = processingContext();
if ( !context )
return;

bool ok = false;
const QString command = alg->asQgisProcessCommand( createProcessingParameters(), *context, ok );
if ( ! ok )
{
mMessageBar->pushMessage( tr( "Current settings are not compatible with qgis_process" ), Qgis::MessageLevel::Warning );
}
else
{
QMimeData *m = new QMimeData();
m->setText( command );
QClipboard *cb = QApplication::clipboard();

#ifdef Q_OS_LINUX
cb->setMimeData( m, QClipboard::Selection );
#endif
cb->setMimeData( m, QClipboard::Clipboard );
}
}
} );

mButtonBox->addButton( mAdvancedButton, QDialogButtonBox::ResetRole );
break;
}

case DialogMode::Batch:
break;

}

connect( mAdvancedMenu, &QMenu::aboutToShow, this, [ = ]
{
mCopyAsQgisProcessCommand->setEnabled( algorithm()&& !( algorithm()->flags() & QgsProcessingAlgorithm::FlagNotAvailableInStandaloneTool ) );
} );

connect( mButtonRun, &QPushButton::clicked, this, &QgsProcessingAlgorithmDialogBase::runAlgorithm );
connect( mButtonChangeParameters, &QPushButton::clicked, this, &QgsProcessingAlgorithmDialogBase::showParameters );
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsProcessingAlgorithmDialogBase::closeClicked );
Expand Down
1 change: 1 addition & 0 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.h
Expand Up @@ -421,6 +421,7 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsPr
QgsMessageBar *mMessageBar = nullptr;
QPushButton *mAdvancedButton = nullptr;
QMenu *mAdvancedMenu = nullptr;
QAction *mCopyAsQgisProcessCommand = nullptr;

bool mExecuted = false;
bool mExecutedAnyResult = false;
Expand Down

0 comments on commit b4cb7ba

Please sign in to comment.