32#include <QDesktopServices>
34#include <QApplication>
39#include <nlohmann/json.hpp>
44QgsProcessingAlgorithmDialogFeedback::QgsProcessingAlgorithmDialogFeedback()
48void QgsProcessingAlgorithmDialogFeedback::setProgressText(
const QString &text )
51 emit progressTextChanged( text );
54void QgsProcessingAlgorithmDialogFeedback::reportError(
const QString &error,
bool fatalError )
57 emit errorReported( error, fatalError );
60void QgsProcessingAlgorithmDialogFeedback::pushWarning(
const QString &warning )
63 emit warningPushed( warning );
66void QgsProcessingAlgorithmDialogFeedback::pushInfo(
const QString &info )
69 emit infoPushed( info );
72void QgsProcessingAlgorithmDialogFeedback::pushCommandInfo(
const QString &info )
75 emit commandInfoPushed( info );
78void QgsProcessingAlgorithmDialogFeedback::pushDebugInfo(
const QString &info )
81 emit debugInfoPushed( info );
84void QgsProcessingAlgorithmDialogFeedback::pushConsoleInfo(
const QString &info )
87 emit consoleInfoPushed( info );
90void QgsProcessingAlgorithmDialogFeedback::pushFormattedMessage(
const QString &html,
const QString &text )
93 emit formattedMessagePushed( html );
100QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *parent, Qt::WindowFlags flags, DialogMode mode )
101 : QDialog( parent, flags )
107 splitter->setCollapsible( 0,
false );
110 QSplitterHandle *splitterHandle = splitter->handle( 1 );
111 QVBoxLayout *handleLayout =
new QVBoxLayout();
112 handleLayout->setContentsMargins( 0, 0, 0, 0 );
113 mButtonCollapse =
new QToolButton( splitterHandle );
114 mButtonCollapse->setAutoRaise(
true );
115 mButtonCollapse->setFixedSize( 12, 12 );
116 mButtonCollapse->setCursor( Qt::ArrowCursor );
117 handleLayout->addWidget( mButtonCollapse );
118 handleLayout->addStretch();
119 splitterHandle->setLayout( handleLayout );
123 txtLog->setOpenLinks(
false );
124 connect( txtLog, &QTextBrowser::anchorClicked,
this, &QgsProcessingAlgorithmDialogBase::urlClicked );
127 splitter->restoreState( settings.
value( QStringLiteral(
"/Processing/dialogBaseSplitter" ), QByteArray() ).toByteArray() );
128 mSplitterState = splitter->saveState();
129 splitterChanged( 0, 0 );
132 mButtonRun = mButtonBox->button( QDialogButtonBox::Ok );
133 mButtonRun->setText( tr(
"Run" ) );
136 mButtonChangeParameters = mButtonBox->button( QDialogButtonBox::Yes );
137 mButtonChangeParameters->setText( tr(
"Change Parameters" ) );
139 buttonCancel->setEnabled(
false );
140 mButtonClose = mButtonBox->button( QDialogButtonBox::Close );
144 case DialogMode::Single:
146 mAdvancedButton =
new QPushButton( tr(
"Advanced" ) );
147 mAdvancedMenu =
new QMenu(
this );
148 mAdvancedButton->setMenu( mAdvancedMenu );
150 mContextSettingsAction =
new QAction( tr(
"Algorithm Settingsā¦" ), mAdvancedMenu );
152 mAdvancedMenu->addAction( mContextSettingsAction );
154 connect( mContextSettingsAction, &QAction::triggered,
this, [
this]
158 mTabWidget->setCurrentIndex( 0 );
160 if ( !mContextOptionsWidget )
162 mContextOptionsWidget =
new QgsProcessingContextOptionsWidget();
163 mContextOptionsWidget->setFromContext( processingContext() );
164 mContextOptionsWidget->setLogLevel( mLogLevel );
165 panel->openPanel( mContextOptionsWidget );
169 mOverrideDefaultContextSettings =
true;
170 mGeometryCheck = mContextOptionsWidget->invalidGeometryCheck();
171 mDistanceUnits = mContextOptionsWidget->distanceUnit();
172 mAreaUnits = mContextOptionsWidget->areaUnit();
173 mTemporaryFolderOverride = mContextOptionsWidget->temporaryFolder();
174 mMaximumThreads = mContextOptionsWidget->maximumThreads();
175 mLogLevel = mContextOptionsWidget->logLevel();
180 mAdvancedMenu->addSeparator();
182 QAction *copyAsPythonCommand =
new QAction( tr(
"Copy as Python Command" ), mAdvancedMenu );
185 mAdvancedMenu->addAction( copyAsPythonCommand );
186 connect( copyAsPythonCommand, &QAction::triggered,
this, [
this]
194 const QString command = alg->asPythonCommand( createProcessingParameters(), *context );
195 QMimeData *m =
new QMimeData();
196 m->setText( command );
197 QClipboard *cb = QApplication::clipboard();
200 cb->setMimeData( m, QClipboard::Selection );
202 cb->setMimeData( m, QClipboard::Clipboard );
206 mCopyAsQgisProcessCommand =
new QAction( tr(
"Copy as qgis_process Command" ), mAdvancedMenu );
208 mAdvancedMenu->addAction( mCopyAsQgisProcessCommand );
210 connect( mCopyAsQgisProcessCommand, &QAction::triggered,
this, [
this]
219 const QString command = alg->asQgisProcessCommand( createProcessingParameters(), *context, ok );
222 mMessageBar->pushMessage( tr(
"Current settings cannot be specified as arguments to qgis_process (Pipe parameters as JSON to qgis_process instead)" ),
Qgis::MessageLevel::Warning );
226 QMimeData *m =
new QMimeData();
227 m->setText( command );
228 QClipboard *cb = QApplication::clipboard();
231 cb->setMimeData( m, QClipboard::Selection );
233 cb->setMimeData( m, QClipboard::Clipboard );
238 mAdvancedMenu->addSeparator();
240 QAction *copyAsJson =
new QAction( tr(
"Copy as JSON" ), mAdvancedMenu );
243 mAdvancedMenu->addAction( copyAsJson );
244 connect( copyAsJson, &QAction::triggered,
this, [
this]
252 const QVariantMap properties = alg->asMap( createProcessingParameters(), *context );
255 QMimeData *m =
new QMimeData();
257 QClipboard *cb = QApplication::clipboard();
260 cb->setMimeData( m, QClipboard::Selection );
262 cb->setMimeData( m, QClipboard::Clipboard );
266 mPasteJsonAction =
new QAction( tr(
"Paste Settings" ), mAdvancedMenu );
269 mAdvancedMenu->addAction( mPasteJsonAction );
270 connect( mPasteJsonAction, &QAction::triggered,
this, [
this]
272 const QString text = QApplication::clipboard()->text();
273 if ( text.isEmpty() )
276 const QVariantMap parameterValues =
QgsJsonUtils::parseJson( text ).toMap().value( QStringLiteral(
"inputs" ) ).toMap();
277 if ( parameterValues.isEmpty() )
284 setParameters( preparedValues );
287 mButtonBox->addButton( mAdvancedButton, QDialogButtonBox::ResetRole );
291 case DialogMode::Batch:
297 connect( mAdvancedMenu, &QMenu::aboutToShow,
this, [ = ]
299 mCopyAsQgisProcessCommand->setEnabled(
algorithm()
301 mPasteJsonAction->setEnabled( !QApplication::clipboard()->text().isEmpty() );
305 connect( mButtonRun, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::runAlgorithm );
306 connect( mButtonChangeParameters, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::showParameters );
307 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProcessingAlgorithmDialogBase::closeClicked );
308 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProcessingAlgorithmDialogBase::openHelp );
309 connect( mButtonCollapse, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::toggleCollapsed );
310 connect( splitter, &QSplitter::splitterMoved,
this, &QgsProcessingAlgorithmDialogBase::splitterChanged );
312 connect( mButtonSaveLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::saveLog );
313 connect( mButtonCopyLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::copyLogToClipboard );
314 connect( mButtonClearLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::clearLog );
316 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged );
319 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
320 verticalLayout->insertWidget( 0, mMessageBar );
325QgsProcessingAlgorithmDialogBase::~QgsProcessingAlgorithmDialogBase() =
default;
327void QgsProcessingAlgorithmDialogBase::setParameters(
const QVariantMap & )
336 title = mAlgorithm->group().isEmpty()
338 : QStringLiteral(
"%1 - %2" ).arg(
QgsStringUtils::capitalize( mAlgorithm->group(),
Qgis::Capitalization::TitleCase ),
QgsStringUtils::capitalize( mAlgorithm->displayName(),
Qgis::Capitalization::TitleCase ) );
342 title = mAlgorithm->group().isEmpty()
343 ? mAlgorithm->displayName()
344 : QStringLiteral(
"%1 - %2" ).arg( mAlgorithm->group(), mAlgorithm->displayName() );
347 setWindowTitle( title );
349 const QString algHelp = formatHelp(
algorithm );
350 if ( algHelp.isEmpty() )
351 textShortHelp->hide();
354 textShortHelp->document()->setDefaultStyleSheet( QStringLiteral(
".summary { margin-left: 10px; margin-right: 10px; }\n"
355 "h2 { color: #555555; padding-bottom: 15px; }\n"
356 "a { text - decoration: none; color: #3498db; font-weight: bold; }\n"
357 "p, ul, li { color: #666666; }\n"
358 "b { color: #333333; }\n"
359 "dl dd { margin - bottom: 5px; }" ) );
360 textShortHelp->setHtml( algHelp );
361 connect( textShortHelp, &QTextBrowser::anchorClicked,
this, &QgsProcessingAlgorithmDialogBase::linkClicked );
362 textShortHelp->show();
367 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Help ) );
371 if ( !warning.isEmpty() )
379 return mAlgorithm.get();
382void QgsProcessingAlgorithmDialogBase::setMainWidget(
QgsPanelWidget *widget )
386 mMainWidget->deleteLater();
389 mPanelStack->setMainPanel( widget );
392 mMainWidget = widget;
401void QgsProcessingAlgorithmDialogBase::saveLogToFile(
const QString &path,
const LogFormat format )
403 QFile logFile( path );
404 if ( !logFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
408 QTextStream fout( &logFile );
412 case FormatPlainText:
413 fout << txtLog->toPlainText();
417 fout << txtLog->toHtml();
424 auto feedback = std::make_unique< QgsProcessingAlgorithmDialogFeedback >();
426 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::commandInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushCommandInfo );
427 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::consoleInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushConsoleInfo );
428 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::debugInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushDebugInfo );
429 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::errorReported,
this, &QgsProcessingAlgorithmDialogBase::reportError );
430 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::warningPushed,
this, &QgsProcessingAlgorithmDialogBase::pushWarning );
431 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::infoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushInfo );
432 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::formattedMessagePushed,
this, &QgsProcessingAlgorithmDialogBase::pushFormattedMessage );
433 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::progressTextChanged,
this, &QgsProcessingAlgorithmDialogBase::setProgressText );
435 return feedback.release();
438QDialogButtonBox *QgsProcessingAlgorithmDialogBase::buttonBox()
443QTabWidget *QgsProcessingAlgorithmDialogBase::tabWidget()
448void QgsProcessingAlgorithmDialogBase::showLog()
450 mTabWidget->setCurrentIndex( 1 );
453void QgsProcessingAlgorithmDialogBase::showParameters()
455 mTabWidget->setCurrentIndex( 0 );
458QPushButton *QgsProcessingAlgorithmDialogBase::runButton()
463QPushButton *QgsProcessingAlgorithmDialogBase::cancelButton()
468QPushButton *QgsProcessingAlgorithmDialogBase::changeParametersButton()
470 return mButtonChangeParameters;
473void QgsProcessingAlgorithmDialogBase::clearProgress()
475 progressBar->setMaximum( 0 );
478void QgsProcessingAlgorithmDialogBase::setExecuted(
bool executed )
480 mExecuted = executed;
483void QgsProcessingAlgorithmDialogBase::setExecutedAnyResult(
bool executedAnyResult )
485 mExecutedAnyResult = executedAnyResult;
488void QgsProcessingAlgorithmDialogBase::setResults(
const QVariantMap &results )
498void QgsProcessingAlgorithmDialogBase::openHelp()
500 QUrl algHelp = mAlgorithm->helpUrl();
501 if ( algHelp.isEmpty() && mAlgorithm->provider() )
503 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() ) ) );
506 if ( !algHelp.isEmpty() )
507 QDesktopServices::openUrl( algHelp );
510void QgsProcessingAlgorithmDialogBase::toggleCollapsed()
512 if ( mHelpCollapsed )
514 splitter->restoreState( mSplitterState );
515 mButtonCollapse->setArrowType( Qt::RightArrow );
519 mSplitterState = splitter->saveState();
520 splitter->setSizes( QList<int>() << 1 << 0 );
521 mButtonCollapse->setArrowType( Qt::LeftArrow );
523 mHelpCollapsed = !mHelpCollapsed;
526void QgsProcessingAlgorithmDialogBase::splitterChanged(
int,
int )
528 if ( splitter->sizes().at( 1 ) == 0 )
530 mHelpCollapsed =
true;
531 mButtonCollapse->setArrowType( Qt::LeftArrow );
535 mHelpCollapsed =
false;
536 mButtonCollapse->setArrowType( Qt::RightArrow );
540void QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged(
int )
542 updateRunButtonVisibility();
545void QgsProcessingAlgorithmDialogBase::linkClicked(
const QUrl &url )
547 QDesktopServices::openUrl( url.toString() );
550void QgsProcessingAlgorithmDialogBase::algExecuted(
bool successful,
const QVariantMap & )
552 mAlgorithmTask =
nullptr;
559 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
565 if ( isFinalized() && successful )
567 progressBar->setFormat( tr(
"Complete" ) );
571 if ( isFinalized() && !isVisible() )
578void QgsProcessingAlgorithmDialogBase::taskTriggered(
QgsTask *task )
580 if ( task == mAlgorithmTask )
584 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
590void QgsProcessingAlgorithmDialogBase::closeClicked()
596void QgsProcessingAlgorithmDialogBase::urlClicked(
const QUrl &url )
598 const QFileInfo file( url.toLocalFile() );
599 if ( file.exists() && !file.isDir() )
602 QDesktopServices::openUrl( url );
615void QgsProcessingAlgorithmDialogBase::reportError(
const QString &error,
bool fatalError )
617 setInfo( error,
true );
624void QgsProcessingAlgorithmDialogBase::pushWarning(
const QString &warning )
626 setInfo( warning,
false,
true,
true );
630void QgsProcessingAlgorithmDialogBase::pushInfo(
const QString &info )
636void QgsProcessingAlgorithmDialogBase::pushFormattedMessage(
const QString &html )
638 setInfo( html,
false,
false );
642void QgsProcessingAlgorithmDialogBase::pushCommandInfo(
const QString &command )
644 txtLog->append( QStringLiteral(
"<code>%1<code>" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) );
645 scrollToBottomOfLog();
649void QgsProcessingAlgorithmDialogBase::pushDebugInfo(
const QString &message )
651 txtLog->append( QStringLiteral(
"<span style=\"color:#777\">%1</span>" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
652 scrollToBottomOfLog();
656void QgsProcessingAlgorithmDialogBase::pushConsoleInfo(
const QString &info )
658 txtLog->append( QStringLiteral(
"<code style=\"color:#777\">%1</code>" ).arg( formatStringForLog( info.toHtmlEscaped() ) ) );
659 scrollToBottomOfLog();
663QDialog *QgsProcessingAlgorithmDialogBase::createProgressDialog()
665 QgsProcessingAlgorithmProgressDialog *dialog =
new QgsProcessingAlgorithmProgressDialog(
this );
666 dialog->setWindowModality( Qt::ApplicationModal );
667 dialog->setWindowTitle( windowTitle() );
668 dialog->setGeometry( geometry() );
669 connect( progressBar, &QProgressBar::valueChanged, dialog->progressBar(), &QProgressBar::setValue );
670 connect( dialog->cancelButton(), &QPushButton::clicked, buttonCancel, &QPushButton::click );
671 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
672 connect( txtLog, &QTextEdit::textChanged, dialog, [
this, dialog]()
674 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
675 QScrollBar *sb = dialog->logTextEdit()->verticalScrollBar();
676 sb->setValue( sb->maximum() );
681void QgsProcessingAlgorithmDialogBase::clearLog()
686void QgsProcessingAlgorithmDialogBase::saveLog()
689 const QString lastUsedDir = settings.
value( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QDir::homePath() ).toString();
692 const QString txtExt = tr(
"Text files" ) + QStringLiteral(
" (*.txt *.TXT)" );
693 const QString htmlExt = tr(
"HTML files" ) + QStringLiteral(
" (*.html *.HTML)" );
695 const QString path = QFileDialog::getSaveFileName(
this, tr(
"Save Log to File" ), lastUsedDir, txtExt +
";;" + htmlExt, &filter );
699 if ( path.isEmpty() )
704 settings.
setValue( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QFileInfo( path ).path() );
706 LogFormat format = FormatPlainText;
707 if ( filter == htmlExt )
711 saveLogToFile( path, format );
714void QgsProcessingAlgorithmDialogBase::copyLogToClipboard()
716 QMimeData *m =
new QMimeData();
717 m->setText( txtLog->toPlainText() );
718 m->setHtml( txtLog->toHtml() );
719 QClipboard *cb = QApplication::clipboard();
722 cb->setMimeData( m, QClipboard::Selection );
724 cb->setMimeData( m, QClipboard::Clipboard );
727void QgsProcessingAlgorithmDialogBase::closeEvent( QCloseEvent *e )
729 if ( !mHelpCollapsed )
732 settings.
setValue( QStringLiteral(
"/Processing/dialogBaseSplitter" ), splitter->saveState() );
735 QDialog::closeEvent( e );
737 if ( !mAlgorithmTask && isFinalized() )
746void QgsProcessingAlgorithmDialogBase::runAlgorithm()
751void QgsProcessingAlgorithmDialogBase::setPercentage(
double percent )
754 if ( progressBar->maximum() == 0 )
755 progressBar->setMaximum( 100 );
756 progressBar->setValue( percent );
760void QgsProcessingAlgorithmDialogBase::setProgressText(
const QString &text )
762 lblProgress->setText( text );
763 setInfo( text,
false );
764 scrollToBottomOfLog();
772 if ( !text.isEmpty() )
774 const QStringList paragraphs = text.split(
'\n' );
776 for (
const QString ¶graph : paragraphs )
778 help += QStringLiteral(
"<p>%1</p>" ).arg( paragraph );
797 result += QStringLiteral(
"<ul><li><i>%1</i></li></ul>" ).arg( flags.join( QLatin1String(
"</i></li><li><i>" ) ) );
801 result += QStringLiteral(
"<p><b>%1</b></p>" ).arg(
802 tr(
"Warning: This algorithm is a potential security risk if executed with unchecked inputs, and may result in system damage or data leaks." )
807 result += QStringLiteral(
"<p><b>%1</b></p>" ).arg(
808 tr(
"Warning: This algorithm has known issues. The results must be carefully validated by the user." )
815void QgsProcessingAlgorithmDialogBase::processEvents()
817 if ( mAlgorithmTask )
833 while ( ++nIters < 100 )
836 QCoreApplication::processEvents();
840void QgsProcessingAlgorithmDialogBase::scrollToBottomOfLog()
842 QScrollBar *sb = txtLog->verticalScrollBar();
843 sb->setValue( sb->maximum() );
846void QgsProcessingAlgorithmDialogBase::resetGui()
848 lblProgress->clear();
849 progressBar->setMaximum( 100 );
850 progressBar->setValue( 0 );
851 mButtonRun->setEnabled(
true );
852 mButtonChangeParameters->setEnabled(
true );
853 mButtonClose->setEnabled(
true );
856 mMainWidget->setEnabled(
true );
858 updateRunButtonVisibility();
859 resetAdditionalGui();
862void QgsProcessingAlgorithmDialogBase::updateRunButtonVisibility()
865 const bool runButtonVisible = mTabWidget->currentIndex() == 0;
866 mButtonRun->setVisible( runButtonVisible );
867 if ( runButtonVisible )
868 progressBar->resetFormat();
869 mButtonChangeParameters->setVisible( !runButtonVisible && mExecutedAnyResult && mButtonChangeParameters->isEnabled() );
872void QgsProcessingAlgorithmDialogBase::resetAdditionalGui()
877void QgsProcessingAlgorithmDialogBase::blockControlsWhileRunning()
879 mButtonRun->setEnabled(
false );
880 mButtonChangeParameters->setEnabled(
false );
883 mMainWidget->setEnabled(
false );
885 blockAdditionalControlsWhileRunning();
888void QgsProcessingAlgorithmDialogBase::blockAdditionalControlsWhileRunning()
898void QgsProcessingAlgorithmDialogBase::hideShortHelp()
900 textShortHelp->setVisible(
false );
905 mAlgorithmTask = task;
910QString QgsProcessingAlgorithmDialogBase::formatStringForLog(
const QString &
string )
913 s.replace(
'\n', QLatin1String(
"<br>" ) );
917bool QgsProcessingAlgorithmDialogBase::isFinalized()
929 if ( mOverrideDefaultContextSettings )
939void QgsProcessingAlgorithmDialogBase::setInfo(
const QString &message,
bool isError,
bool escapeHtml,
bool isWarning )
941 constexpr int MESSAGE_COUNT_LIMIT = 10000;
943 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
945 ++mMessageLoggedCount;
949 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
950 txtLog->append( QStringLiteral(
"<span style=\"color:red\">%1</span>" ).arg( tr(
"Message log truncated" ) ) );
951 else if ( isError || isWarning )
952 txtLog->append( QStringLiteral(
"<span style=\"color:%1\">%2</span>" ).arg( isError ? QStringLiteral(
"red" ) : QStringLiteral(
"#b85a20" ), escapeHtml ? formatStringForLog( message.toHtmlEscaped() ) : formatStringForLog( message ) ) );
953 else if ( escapeHtml )
954 txtLog->append( QStringLiteral(
"<span>%1</span" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
956 txtLog->append( QStringLiteral(
"<span>%1</span>" ).arg( formatStringForLog( message ) ) );
957 scrollToBottomOfLog();
961void QgsProcessingAlgorithmDialogBase::reject()
963 if ( !mAlgorithmTask && isFinalized() )
965 setAttribute( Qt::WA_DeleteOnClose );
974QgsProcessingAlgorithmProgressDialog::QgsProcessingAlgorithmProgressDialog( QWidget *parent )
980QProgressBar *QgsProcessingAlgorithmProgressDialog::progressBar()
985QPushButton *QgsProcessingAlgorithmProgressDialog::cancelButton()
987 return mButtonBox->button( QDialogButtonBox::Cancel );
990QTextEdit *QgsProcessingAlgorithmProgressDialog::logTextEdit()
995void QgsProcessingAlgorithmProgressDialog::reject()
1005QgsProcessingContextOptionsWidget::QgsProcessingContextOptionsWidget( QWidget *parent )
1009 setPanelTitle( tr(
"Algorithm Settings" ) );
1015 mTemporaryFolderWidget->setDialogTitle( tr(
"Select Temporary Directory" ) );
1017 mTemporaryFolderWidget->lineEdit()->setPlaceholderText( tr(
"Default" ) );
1048 mDistanceUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1078 mAreaUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1081 mThreadsSpinBox->setRange( 1, QThread::idealThreadCount() );
1093 whileBlocking( mComboInvalidFeatureFiltering )->setCurrentIndex( mComboInvalidFeatureFiltering->findData( QVariant::fromValue( context->
invalidGeometryCheck() ) ) );
1094 whileBlocking( mDistanceUnitsCombo )->setCurrentIndex( mDistanceUnitsCombo->findData( QVariant::fromValue( context->
distanceUnit() ) ) );
1095 whileBlocking( mAreaUnitsCombo )->setCurrentIndex( mAreaUnitsCombo->findData( QVariant::fromValue( context->
areaUnit() ) ) );
1098 whileBlocking( mLogLevelComboBox )->setCurrentIndex( mLogLevelComboBox->findData(
static_cast< int >( context->
logLevel() ) ) );
1111Qgis::AreaUnit QgsProcessingContextOptionsWidget::areaUnit()
const
1116QString QgsProcessingContextOptionsWidget::temporaryFolder()
1118 return mTemporaryFolderWidget->filePath();
1121int QgsProcessingContextOptionsWidget::maximumThreads()
const
1123 return mThreadsSpinBox->value();
1128 whileBlocking( mLogLevelComboBox )->setCurrentIndex( mLogLevelComboBox->findData(
static_cast< int >( level ) ) );
The Qgis class provides global constants for use throughout the application.
DistanceUnit
Units of distance.
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ NauticalMiles
Nautical miles.
@ SquareCentimeters
Square centimeters.
@ SquareInches
Square inches.
@ 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...
ProcessingAlgorithmDocumentationFlag
Flags describing algorithm behavior for documentation purposes.
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
@ NoCheck
No invalid geometry checking.
@ AbortOnInvalid
Close iterator on encountering any features with invalid geometry. This requires a slow geometry vali...
@ SkipInvalid
Skip any features with invalid geometry. This requires a slow geometry validity check for every featu...
@ NotAvailableInStandaloneTool
Algorithm should not be available from the standalone "qgis_process" tool. Used to flag algorithms wh...
@ SecurityRisk
The algorithm represents a potential security risk if executed with untrusted inputs.
@ DisplayNameIsLiteral
Algorithm's display name is a static literal string, and should not be translated or automatically fo...
@ KnownIssues
Algorithm has known issues.
ProcessingLogLevel
Logging level for algorithms to use when pushing feedback messages.
@ DefaultLevel
Default logging level.
@ Verbose
Verbose logging.
@ ModelDebug
Model debug level logging. Includes verbose logging and other outputs useful for debugging models.
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.
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 QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
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.
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.
virtual Qgis::ProcessingAlgorithmDocumentationFlags documentationFlags() const
Returns the flags describing algorithm behavior for documentation purposes.
Contains information about the context in which a processing algorithm is executed.
Qgis::AreaUnit areaUnit() const
Returns the area unit to use for area calculations.
void setLogLevel(Qgis::ProcessingLogLevel level)
Sets the logging level for algorithms to use when pushing feedback messages to users.
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 setInvalidGeometryCheck(Qgis::InvalidGeometryCheck check)
Sets the behavior used for checking invalid geometries in input layers.
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.
Qgis::ProcessingLogLevel logLevel() const
Returns the logging level for algorithms to use when pushing feedback messages to users.
Qgis::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.
Qgis::ProcessingAlgorithmFlags 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 pushFormattedMessage(const QString &html, const QString &text)
Pushes a pre-formatted message 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.
static QString documentationFlagToString(Qgis::ProcessingAlgorithmDocumentationFlag flag)
Converts a documentation flag to a translated string.
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.
Utility functions for working with strings.
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
const QList< T > qgsEnumList()
Returns a list all enum entries.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.