31#include <QDesktopServices>
33#include <QApplication>
38#include <nlohmann/json.hpp>
43QgsProcessingAlgorithmDialogFeedback::QgsProcessingAlgorithmDialogFeedback()
47void QgsProcessingAlgorithmDialogFeedback::setProgressText(
const QString &text )
50 emit progressTextChanged( text );
53void QgsProcessingAlgorithmDialogFeedback::reportError(
const QString &error,
bool fatalError )
56 emit errorReported( error, fatalError );
59void QgsProcessingAlgorithmDialogFeedback::pushWarning(
const QString &warning )
62 emit warningPushed( warning );
65void QgsProcessingAlgorithmDialogFeedback::pushInfo(
const QString &info )
68 emit infoPushed( info );
71void QgsProcessingAlgorithmDialogFeedback::pushCommandInfo(
const QString &info )
74 emit commandInfoPushed( info );
77void QgsProcessingAlgorithmDialogFeedback::pushDebugInfo(
const QString &info )
80 emit debugInfoPushed( info );
83void QgsProcessingAlgorithmDialogFeedback::pushConsoleInfo(
const QString &info )
86 emit consoleInfoPushed( info );
93QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *parent, Qt::WindowFlags flags, DialogMode mode )
94 : QDialog( parent, flags )
100 splitter->setCollapsible( 0,
false );
103 QSplitterHandle *splitterHandle = splitter->handle( 1 );
104 QVBoxLayout *handleLayout =
new QVBoxLayout();
105 handleLayout->setContentsMargins( 0, 0, 0, 0 );
106 mButtonCollapse =
new QToolButton( splitterHandle );
107 mButtonCollapse->setAutoRaise(
true );
108 mButtonCollapse->setFixedSize( 12, 12 );
109 mButtonCollapse->setCursor( Qt::ArrowCursor );
110 handleLayout->addWidget( mButtonCollapse );
111 handleLayout->addStretch();
112 splitterHandle->setLayout( handleLayout );
117 splitter->restoreState( settings.
value( QStringLiteral(
"/Processing/dialogBaseSplitter" ), QByteArray() ).toByteArray() );
118 mSplitterState = splitter->saveState();
119 splitterChanged( 0, 0 );
122 mButtonRun = mButtonBox->button( QDialogButtonBox::Ok );
123 mButtonRun->setText( tr(
"Run" ) );
126 mButtonChangeParameters = mButtonBox->button( QDialogButtonBox::Yes );
127 mButtonChangeParameters->setText( tr(
"Change Parameters" ) );
129 buttonCancel->setEnabled(
false );
130 mButtonClose = mButtonBox->button( QDialogButtonBox::Close );
134 case DialogMode::Single:
136 mAdvancedButton =
new QPushButton( tr(
"Advanced" ) );
137 mAdvancedMenu =
new QMenu(
this );
138 mAdvancedButton->setMenu( mAdvancedMenu );
140 mContextSettingsAction =
new QAction( tr(
"Algorithm Settingsā¦" ), mAdvancedMenu );
142 mAdvancedMenu->addAction( mContextSettingsAction );
144 connect( mContextSettingsAction, &QAction::triggered,
this, [
this]
148 mTabWidget->setCurrentIndex( 0 );
150 if ( !mContextOptionsWidget )
152 mContextOptionsWidget =
new QgsProcessingContextOptionsWidget();
153 mContextOptionsWidget->setFromContext( processingContext() );
154 mContextOptionsWidget->setLogLevel( mLogLevel );
155 panel->openPanel( mContextOptionsWidget );
159 mOverrideDefaultContextSettings =
true;
160 mGeometryCheck = mContextOptionsWidget->invalidGeometryCheck();
161 mDistanceUnits = mContextOptionsWidget->distanceUnit();
162 mAreaUnits = mContextOptionsWidget->areaUnit();
163 mTemporaryFolderOverride = mContextOptionsWidget->temporaryFolder();
164 mMaximumThreads = mContextOptionsWidget->maximumThreads();
165 mLogLevel = mContextOptionsWidget->logLevel();
170 mAdvancedMenu->addSeparator();
172 QAction *copyAsPythonCommand =
new QAction( tr(
"Copy as Python Command" ), mAdvancedMenu );
175 mAdvancedMenu->addAction( copyAsPythonCommand );
176 connect( copyAsPythonCommand, &QAction::triggered,
this, [
this]
184 const QString command = alg->asPythonCommand( createProcessingParameters(), *context );
185 QMimeData *m =
new QMimeData();
186 m->setText( command );
187 QClipboard *cb = QApplication::clipboard();
190 cb->setMimeData( m, QClipboard::Selection );
192 cb->setMimeData( m, QClipboard::Clipboard );
196 mCopyAsQgisProcessCommand =
new QAction( tr(
"Copy as qgis_process Command" ), mAdvancedMenu );
198 mAdvancedMenu->addAction( mCopyAsQgisProcessCommand );
200 connect( mCopyAsQgisProcessCommand, &QAction::triggered,
this, [
this]
209 const QString command = alg->asQgisProcessCommand( createProcessingParameters(), *context, ok );
212 mMessageBar->pushMessage( tr(
"Current settings cannot be specified as arguments to qgis_process (Pipe parameters as JSON to qgis_process instead)" ),
Qgis::MessageLevel::Warning );
216 QMimeData *m =
new QMimeData();
217 m->setText( command );
218 QClipboard *cb = QApplication::clipboard();
221 cb->setMimeData( m, QClipboard::Selection );
223 cb->setMimeData( m, QClipboard::Clipboard );
228 mAdvancedMenu->addSeparator();
230 QAction *copyAsJson =
new QAction( tr(
"Copy as JSON" ), mAdvancedMenu );
233 mAdvancedMenu->addAction( copyAsJson );
234 connect( copyAsJson, &QAction::triggered,
this, [
this]
242 const QVariantMap properties = alg->asMap( createProcessingParameters(), *context );
245 QMimeData *m =
new QMimeData();
247 QClipboard *cb = QApplication::clipboard();
250 cb->setMimeData( m, QClipboard::Selection );
252 cb->setMimeData( m, QClipboard::Clipboard );
256 mPasteJsonAction =
new QAction( tr(
"Paste Settings" ), mAdvancedMenu );
259 mAdvancedMenu->addAction( mPasteJsonAction );
260 connect( mPasteJsonAction, &QAction::triggered,
this, [
this]
262 const QString text = QApplication::clipboard()->text();
263 if ( text.isEmpty() )
266 const QVariantMap parameterValues =
QgsJsonUtils::parseJson( text ).toMap().value( QStringLiteral(
"inputs" ) ).toMap();
267 if ( parameterValues.isEmpty() )
274 setParameters( preparedValues );
277 mButtonBox->addButton( mAdvancedButton, QDialogButtonBox::ResetRole );
281 case DialogMode::Batch:
287 connect( mAdvancedMenu, &QMenu::aboutToShow,
this, [ = ]
289 mCopyAsQgisProcessCommand->setEnabled(
algorithm()
291 mPasteJsonAction->setEnabled( !QApplication::clipboard()->text().isEmpty() );
295 connect( mButtonRun, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::runAlgorithm );
296 connect( mButtonChangeParameters, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::showParameters );
297 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProcessingAlgorithmDialogBase::closeClicked );
298 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProcessingAlgorithmDialogBase::openHelp );
299 connect( mButtonCollapse, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::toggleCollapsed );
300 connect( splitter, &QSplitter::splitterMoved,
this, &QgsProcessingAlgorithmDialogBase::splitterChanged );
302 connect( mButtonSaveLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::saveLog );
303 connect( mButtonCopyLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::copyLogToClipboard );
304 connect( mButtonClearLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::clearLog );
306 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged );
309 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
310 verticalLayout->insertWidget( 0, mMessageBar );
315QgsProcessingAlgorithmDialogBase::~QgsProcessingAlgorithmDialogBase() =
default;
317void QgsProcessingAlgorithmDialogBase::setParameters(
const QVariantMap & )
330 title = mAlgorithm->displayName();
332 setWindowTitle( title );
334 const QString algHelp = formatHelp(
algorithm );
335 if ( algHelp.isEmpty() )
336 textShortHelp->hide();
339 textShortHelp->document()->setDefaultStyleSheet( QStringLiteral(
".summary { margin-left: 10px; margin-right: 10px; }\n"
340 "h2 { color: #555555; padding-bottom: 15px; }\n"
341 "a { text - decoration: none; color: #3498db; font-weight: bold; }\n"
342 "p { color: #666666; }\n"
343 "b { color: #333333; }\n"
344 "dl dd { margin - bottom: 5px; }" ) );
345 textShortHelp->setHtml( algHelp );
346 connect( textShortHelp, &QTextBrowser::anchorClicked,
this, &QgsProcessingAlgorithmDialogBase::linkClicked );
347 textShortHelp->show();
352 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Help ) );
356 if ( !warning.isEmpty() )
364 return mAlgorithm.get();
367void QgsProcessingAlgorithmDialogBase::setMainWidget(
QgsPanelWidget *widget )
371 mMainWidget->deleteLater();
374 mPanelStack->setMainPanel( widget );
377 mMainWidget = widget;
386void QgsProcessingAlgorithmDialogBase::saveLogToFile(
const QString &path,
const LogFormat format )
388 QFile logFile( path );
389 if ( !logFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
393 QTextStream fout( &logFile );
397 case FormatPlainText:
398 fout << txtLog->toPlainText();
402 fout << txtLog->toHtml();
409 auto feedback = std::make_unique< QgsProcessingAlgorithmDialogFeedback >();
411 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::commandInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushCommandInfo );
412 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::consoleInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushConsoleInfo );
413 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::debugInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushDebugInfo );
414 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::errorReported,
this, &QgsProcessingAlgorithmDialogBase::reportError );
415 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::warningPushed,
this, &QgsProcessingAlgorithmDialogBase::pushWarning );
416 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::infoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushInfo );
417 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::progressTextChanged,
this, &QgsProcessingAlgorithmDialogBase::setProgressText );
419 return feedback.release();
422QDialogButtonBox *QgsProcessingAlgorithmDialogBase::buttonBox()
427QTabWidget *QgsProcessingAlgorithmDialogBase::tabWidget()
432void QgsProcessingAlgorithmDialogBase::showLog()
434 mTabWidget->setCurrentIndex( 1 );
437void QgsProcessingAlgorithmDialogBase::showParameters()
439 mTabWidget->setCurrentIndex( 0 );
442QPushButton *QgsProcessingAlgorithmDialogBase::runButton()
447QPushButton *QgsProcessingAlgorithmDialogBase::cancelButton()
452QPushButton *QgsProcessingAlgorithmDialogBase::changeParametersButton()
454 return mButtonChangeParameters;
457void QgsProcessingAlgorithmDialogBase::clearProgress()
459 progressBar->setMaximum( 0 );
462void QgsProcessingAlgorithmDialogBase::setExecuted(
bool executed )
464 mExecuted = executed;
467void QgsProcessingAlgorithmDialogBase::setExecutedAnyResult(
bool executedAnyResult )
469 mExecutedAnyResult = executedAnyResult;
472void QgsProcessingAlgorithmDialogBase::setResults(
const QVariantMap &results )
482void QgsProcessingAlgorithmDialogBase::openHelp()
484 QUrl algHelp = mAlgorithm->helpUrl();
485 if ( algHelp.isEmpty() && mAlgorithm->provider() )
487 algHelp =
QgsHelp::helpUrl( QStringLiteral(
"processing_algs/%1/%2.html#%3" ).arg( mAlgorithm->provider()->helpId(), mAlgorithm->groupId(), QStringLiteral(
"%1%2" ).arg( mAlgorithm->provider()->helpId() ).arg( mAlgorithm->name() ) ) );
490 if ( !algHelp.isEmpty() )
491 QDesktopServices::openUrl( algHelp );
494void QgsProcessingAlgorithmDialogBase::toggleCollapsed()
496 if ( mHelpCollapsed )
498 splitter->restoreState( mSplitterState );
499 mButtonCollapse->setArrowType( Qt::RightArrow );
503 mSplitterState = splitter->saveState();
504 splitter->setSizes( QList<int>() << 1 << 0 );
505 mButtonCollapse->setArrowType( Qt::LeftArrow );
507 mHelpCollapsed = !mHelpCollapsed;
510void QgsProcessingAlgorithmDialogBase::splitterChanged(
int,
int )
512 if ( splitter->sizes().at( 1 ) == 0 )
514 mHelpCollapsed =
true;
515 mButtonCollapse->setArrowType( Qt::LeftArrow );
519 mHelpCollapsed =
false;
520 mButtonCollapse->setArrowType( Qt::RightArrow );
524void QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged(
int )
526 updateRunButtonVisibility();
529void QgsProcessingAlgorithmDialogBase::linkClicked(
const QUrl &url )
531 QDesktopServices::openUrl( url.toString() );
534void QgsProcessingAlgorithmDialogBase::algExecuted(
bool successful,
const QVariantMap & )
536 mAlgorithmTask =
nullptr;
543 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
549 if ( isFinalized() && successful )
551 progressBar->setFormat( tr(
"Complete" ) );
555 if ( isFinalized() && !isVisible() )
562void QgsProcessingAlgorithmDialogBase::taskTriggered(
QgsTask *task )
564 if ( task == mAlgorithmTask )
568 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
574void QgsProcessingAlgorithmDialogBase::closeClicked()
590void QgsProcessingAlgorithmDialogBase::reportError(
const QString &error,
bool fatalError )
592 setInfo( error,
true );
599void QgsProcessingAlgorithmDialogBase::pushWarning(
const QString &warning )
601 setInfo( warning,
false,
true,
true );
605void QgsProcessingAlgorithmDialogBase::pushInfo(
const QString &info )
611void QgsProcessingAlgorithmDialogBase::pushCommandInfo(
const QString &command )
613 txtLog->append( QStringLiteral(
"<code>%1<code>" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) );
614 scrollToBottomOfLog();
618void QgsProcessingAlgorithmDialogBase::pushDebugInfo(
const QString &message )
620 txtLog->append( QStringLiteral(
"<span style=\"color:#777\">%1</span>" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
621 scrollToBottomOfLog();
625void QgsProcessingAlgorithmDialogBase::pushConsoleInfo(
const QString &info )
627 txtLog->append( QStringLiteral(
"<code style=\"color:#777\">%1</code>" ).arg( formatStringForLog( info.toHtmlEscaped() ) ) );
628 scrollToBottomOfLog();
632QDialog *QgsProcessingAlgorithmDialogBase::createProgressDialog()
634 QgsProcessingAlgorithmProgressDialog *dialog =
new QgsProcessingAlgorithmProgressDialog(
this );
635 dialog->setWindowModality( Qt::ApplicationModal );
636 dialog->setWindowTitle( windowTitle() );
637 dialog->setGeometry( geometry() );
638 connect( progressBar, &QProgressBar::valueChanged, dialog->progressBar(), &QProgressBar::setValue );
639 connect( dialog->cancelButton(), &QPushButton::clicked, buttonCancel, &QPushButton::click );
640 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
641 connect( txtLog, &QTextEdit::textChanged, dialog, [
this, dialog]()
643 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
644 QScrollBar *sb = dialog->logTextEdit()->verticalScrollBar();
645 sb->setValue( sb->maximum() );
650void QgsProcessingAlgorithmDialogBase::clearLog()
655void QgsProcessingAlgorithmDialogBase::saveLog()
658 const QString lastUsedDir = settings.
value( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QDir::homePath() ).toString();
661 const QString txtExt = tr(
"Text files" ) + QStringLiteral(
" (*.txt *.TXT)" );
662 const QString htmlExt = tr(
"HTML files" ) + QStringLiteral(
" (*.html *.HTML)" );
664 const QString path = QFileDialog::getSaveFileName(
this, tr(
"Save Log to File" ), lastUsedDir, txtExt +
";;" + htmlExt, &filter );
668 if ( path.isEmpty() )
673 settings.
setValue( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QFileInfo( path ).path() );
675 LogFormat format = FormatPlainText;
676 if ( filter == htmlExt )
680 saveLogToFile( path, format );
683void QgsProcessingAlgorithmDialogBase::copyLogToClipboard()
685 QMimeData *m =
new QMimeData();
686 m->setText( txtLog->toPlainText() );
687 m->setHtml( txtLog->toHtml() );
688 QClipboard *cb = QApplication::clipboard();
691 cb->setMimeData( m, QClipboard::Selection );
693 cb->setMimeData( m, QClipboard::Clipboard );
696void QgsProcessingAlgorithmDialogBase::closeEvent( QCloseEvent *e )
698 if ( !mHelpCollapsed )
701 settings.
setValue( QStringLiteral(
"/Processing/dialogBaseSplitter" ), splitter->saveState() );
704 QDialog::closeEvent( e );
706 if ( !mAlgorithmTask && isFinalized() )
715void QgsProcessingAlgorithmDialogBase::runAlgorithm()
720void QgsProcessingAlgorithmDialogBase::setPercentage(
double percent )
723 if ( progressBar->maximum() == 0 )
724 progressBar->setMaximum( 100 );
725 progressBar->setValue( percent );
729void QgsProcessingAlgorithmDialogBase::setProgressText(
const QString &text )
731 lblProgress->setText( text );
732 setInfo( text,
false );
733 scrollToBottomOfLog();
740 if ( !text.isEmpty() )
742 const QStringList paragraphs = text.split(
'\n' );
744 for (
const QString ¶graph : paragraphs )
746 help += QStringLiteral(
"<p>%1</p>" ).arg( paragraph );
758void QgsProcessingAlgorithmDialogBase::processEvents()
760 if ( mAlgorithmTask )
776 while ( ++nIters < 100 )
779 QCoreApplication::processEvents();
783void QgsProcessingAlgorithmDialogBase::scrollToBottomOfLog()
785 QScrollBar *sb = txtLog->verticalScrollBar();
786 sb->setValue( sb->maximum() );
789void QgsProcessingAlgorithmDialogBase::resetGui()
791 lblProgress->clear();
792 progressBar->setMaximum( 100 );
793 progressBar->setValue( 0 );
794 mButtonRun->setEnabled(
true );
795 mButtonChangeParameters->setEnabled(
true );
796 mButtonClose->setEnabled(
true );
799 mMainWidget->setEnabled(
true );
801 updateRunButtonVisibility();
802 resetAdditionalGui();
805void QgsProcessingAlgorithmDialogBase::updateRunButtonVisibility()
808 const bool runButtonVisible = mTabWidget->currentIndex() == 0;
809 mButtonRun->setVisible( runButtonVisible );
810 if ( runButtonVisible )
811 progressBar->resetFormat();
812 mButtonChangeParameters->setVisible( !runButtonVisible && mExecutedAnyResult && mButtonChangeParameters->isEnabled() );
815void QgsProcessingAlgorithmDialogBase::resetAdditionalGui()
820void QgsProcessingAlgorithmDialogBase::blockControlsWhileRunning()
822 mButtonRun->setEnabled(
false );
823 mButtonChangeParameters->setEnabled(
false );
826 mMainWidget->setEnabled(
false );
828 blockAdditionalControlsWhileRunning();
831void QgsProcessingAlgorithmDialogBase::blockAdditionalControlsWhileRunning()
841void QgsProcessingAlgorithmDialogBase::hideShortHelp()
843 textShortHelp->setVisible(
false );
848 mAlgorithmTask = task;
853QString QgsProcessingAlgorithmDialogBase::formatStringForLog(
const QString &
string )
856 s.replace(
'\n', QLatin1String(
"<br>" ) );
860bool QgsProcessingAlgorithmDialogBase::isFinalized()
872 if ( mOverrideDefaultContextSettings )
882void QgsProcessingAlgorithmDialogBase::setInfo(
const QString &message,
bool isError,
bool escapeHtml,
bool isWarning )
884 constexpr int MESSAGE_COUNT_LIMIT = 10000;
886 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
888 ++mMessageLoggedCount;
892 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
893 txtLog->append( QStringLiteral(
"<span style=\"color:red\">%1</span>" ).arg( tr(
"Message log truncated" ) ) );
894 else if ( isError || isWarning )
895 txtLog->append( QStringLiteral(
"<span style=\"color:%1\">%2</span>" ).arg( isError ? QStringLiteral(
"red" ) : QStringLiteral(
"#b85a20" ), escapeHtml ? formatStringForLog( message.toHtmlEscaped() ) : formatStringForLog( message ) ) );
896 else if ( escapeHtml )
897 txtLog->append( QStringLiteral(
"<span>%1</span" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
899 txtLog->append( QStringLiteral(
"<span>%1</span>" ).arg( formatStringForLog( message ) ) );
900 scrollToBottomOfLog();
904void QgsProcessingAlgorithmDialogBase::reject()
906 if ( !mAlgorithmTask && isFinalized() )
908 setAttribute( Qt::WA_DeleteOnClose );
917QgsProcessingAlgorithmProgressDialog::QgsProcessingAlgorithmProgressDialog( QWidget *parent )
923QProgressBar *QgsProcessingAlgorithmProgressDialog::progressBar()
928QPushButton *QgsProcessingAlgorithmProgressDialog::cancelButton()
930 return mButtonBox->button( QDialogButtonBox::Cancel );
933QTextEdit *QgsProcessingAlgorithmProgressDialog::logTextEdit()
938void QgsProcessingAlgorithmProgressDialog::reject()
948QgsProcessingContextOptionsWidget::QgsProcessingContextOptionsWidget( QWidget *parent )
952 setPanelTitle( tr(
"Algorithm Settings" ) );
958 mTemporaryFolderWidget->setDialogTitle( tr(
"Select Temporary Directory" ) );
960 mTemporaryFolderWidget->lineEdit()->setPlaceholderText( tr(
"Default" ) );
991 mDistanceUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1021 mAreaUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1024 mThreadsSpinBox->setRange( 1, QThread::idealThreadCount() );
1036 whileBlocking( mComboInvalidFeatureFiltering )->setCurrentIndex( mComboInvalidFeatureFiltering->findData(
static_cast< int >( context->
invalidGeometryCheck() ) ) );
1037 whileBlocking( mDistanceUnitsCombo )->setCurrentIndex( mDistanceUnitsCombo->findData( QVariant::fromValue( context->
distanceUnit() ) ) );
1038 whileBlocking( mAreaUnitsCombo )->setCurrentIndex( mAreaUnitsCombo->findData( QVariant::fromValue( context->
areaUnit() ) ) );
1041 whileBlocking( mLogLevelComboBox )->setCurrentIndex( mLogLevelComboBox->findData(
static_cast< int >( context->
logLevel() ) ) );
1054Qgis::AreaUnit QgsProcessingContextOptionsWidget::areaUnit()
const
1059QString QgsProcessingContextOptionsWidget::temporaryFolder()
1061 return mTemporaryFolderWidget->filePath();
1064int QgsProcessingContextOptionsWidget::maximumThreads()
const
1066 return mThreadsSpinBox->value();
1071 whileBlocking( mLogLevelComboBox )->setCurrentIndex( mLogLevelComboBox->findData(
static_cast< int >( level ) ) );
DistanceUnit
Units of distance.
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ Inches
Inches (since QGIS 3.32)
@ NauticalMiles
Nautical miles.
@ SquareCentimeters
Square centimeters.
@ SquareInches
Square inches (since QGIS 3.32)
@ SquareNauticalMiles
Square nautical miles.
@ SquareMillimeters
Square millimeters.
@ SquareYards
Square yards.
@ SquareKilometers
Square kilometers.
@ SquareMeters
Square meters.
@ Unknown
Unknown areal unit.
@ SquareDegrees
Square degrees, for planar geographic CRS area measurements.
@ SquareMiles
Square miles.
@ Warning
Warning message.
@ TitleCase
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsTaskManager * taskManager()
Returns the application's task manager, used for managing application wide background task handling.
InvalidGeometryCheck
Handling of features with invalid geometries.
@ GeometryNoCheck
No invalid geometry checking.
@ GeometryAbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ GeometrySkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
@ HigDialogTitleIsTitleCase
Dialog titles should be title case.
static QgsGui::HigFlags higFlags()
Returns the platform's HIG flags.
static QUrl helpUrl(const QString &key)
Returns URI of the help topic for the given key.
static QVariant parseJson(const std::string &jsonString)
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and ...
static json jsonFromVariant(const QVariant &v)
Converts a QVariant v to a json object.
A bar for displaying non-blocking messages to the user.
QgsTask task which runs a QgsProcessingAlgorithm in a background task.
void executed(bool successful, const QVariantMap &results)
Emitted when the algorithm has finished execution.
Abstract base class for processing algorithms.
virtual QString helpUrl() const
Returns a url pointing to the algorithm's help page.
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
@ FlagNotAvailableInStandaloneTool
Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms wh...
@ FlagDisplayNameIsLiteral
Algorithm's display name is a static literal string, and should not be translated or automatically fo...
virtual QString displayName() const =0
Returns the translated algorithm name, which should be used for any user-visible display of the algor...
QgsProcessingProvider * provider() const
Returns the provider to which this algorithm belongs.
Contains information about the context in which a processing algorithm is executed.
LogLevel
Logging level for algorithms to use when pushing feedback messages.
@ Verbose
Verbose logging.
@ DefaultLevel
Default logging level.
@ ModelDebug
Model debug level logging. Includes verbose logging and other outputs useful for debugging models (si...
Qgis::AreaUnit areaUnit() const
Returns the area unit to use for area calculations.
void setMaximumThreads(int threads)
Sets the (optional) number of threads to use when running algorithms.
void setDistanceUnit(Qgis::DistanceUnit unit)
Sets the unit to use for distance calculations.
void setAreaUnit(Qgis::AreaUnit areaUnit)
Sets the unit to use for area calculations.
Qgis::DistanceUnit distanceUnit() const
Returns the distance unit to use for distance calculations.
void setLogLevel(LogLevel level)
Sets the logging level for algorithms to use when pushing feedback messages to users.
void setInvalidGeometryCheck(QgsFeatureRequest::InvalidGeometryCheck check)
Sets the behavior used for checking invalid geometries in input layers.
LogLevel logLevel() const
Returns the logging level for algorithms to use when pushing feedback messages to users.
QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const
Returns the behavior used for checking invalid geometries in input layers.
void setTemporaryFolder(const QString &folder)
Sets the (optional) temporary folder to use when running algorithms.
QString temporaryFolder() const
Returns the (optional) temporary folder to use when running algorithms.
int maximumThreads() const
Returns the (optional) number of threads to use when running algorithms.
QgsProcessingAlgorithm::Flags flags() const override
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
Base class for providing feedback from a processing algorithm.
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
virtual QString helpId() const
Returns the provider help id string, used for creating QgsHelp urls for algorithms belong to this pro...
virtual QString warningMessage() const
Returns an optional warning message to show users when running algorithms from this provider.
static QVariantMap preprocessQgisProcessParameters(const QVariantMap ¶meters, bool &ok, QString &error)
Pre-processes a set of parameter values for the qgis_process command.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
void taskTriggered(QgsTask *task)
Emitted when a task is triggered.
Abstract base class for long running background tasks.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into allowing algorithms to be written in pure substantial changes are required in order to port existing x Processing algorithms for QGIS x The most significant changes are outlined not GeoAlgorithm For algorithms which operate on features one by consider subclassing the QgsProcessingFeatureBasedAlgorithm class This class allows much of the boilerplate code for looping over features from a vector layer to be bypassed and instead requires implementation of a processFeature method Ensure that your algorithm(or algorithm 's parent class) implements the new pure virtual createInstance(self) call
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.