17#include "moc_qgsprocessingalgorithmdialogbase.cpp"
33#include <QDesktopServices>
35#include <QApplication>
40#include <nlohmann/json.hpp>
45QgsProcessingAlgorithmDialogFeedback::QgsProcessingAlgorithmDialogFeedback()
49void QgsProcessingAlgorithmDialogFeedback::setProgressText(
const QString &text )
52 emit progressTextChanged( text );
55void QgsProcessingAlgorithmDialogFeedback::reportError(
const QString &error,
bool fatalError )
58 emit errorReported( error, fatalError );
61void QgsProcessingAlgorithmDialogFeedback::pushWarning(
const QString &warning )
64 emit warningPushed( warning );
67void QgsProcessingAlgorithmDialogFeedback::pushInfo(
const QString &info )
70 emit infoPushed( info );
73void QgsProcessingAlgorithmDialogFeedback::pushCommandInfo(
const QString &info )
76 emit commandInfoPushed( info );
79void QgsProcessingAlgorithmDialogFeedback::pushDebugInfo(
const QString &info )
82 emit debugInfoPushed( info );
85void QgsProcessingAlgorithmDialogFeedback::pushConsoleInfo(
const QString &info )
88 emit consoleInfoPushed( info );
91void QgsProcessingAlgorithmDialogFeedback::pushFormattedMessage(
const QString &html,
const QString &text )
94 emit formattedMessagePushed( html );
101QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *parent, Qt::WindowFlags flags, DialogMode mode )
102 : QDialog( parent, flags )
108 splitter->setCollapsible( 0,
false );
111 QSplitterHandle *splitterHandle = splitter->handle( 1 );
112 QVBoxLayout *handleLayout =
new QVBoxLayout();
113 handleLayout->setContentsMargins( 0, 0, 0, 0 );
114 mButtonCollapse =
new QToolButton( splitterHandle );
115 mButtonCollapse->setAutoRaise(
true );
116 mButtonCollapse->setFixedSize( 12, 12 );
117 mButtonCollapse->setCursor( Qt::ArrowCursor );
118 handleLayout->addWidget( mButtonCollapse );
119 handleLayout->addStretch();
120 splitterHandle->setLayout( handleLayout );
124 txtLog->setOpenLinks(
false );
125 connect( txtLog, &QTextBrowser::anchorClicked,
this, &QgsProcessingAlgorithmDialogBase::urlClicked );
128 splitter->restoreState( settings.
value( QStringLiteral(
"/Processing/dialogBaseSplitter" ), QByteArray() ).toByteArray() );
129 mSplitterState = splitter->saveState();
130 splitterChanged( 0, 0 );
133 mButtonRun = mButtonBox->button( QDialogButtonBox::Ok );
134 mButtonRun->setText( tr(
"Run" ) );
137 mButtonChangeParameters = mButtonBox->button( QDialogButtonBox::Yes );
138 mButtonChangeParameters->setText( tr(
"Change Parameters" ) );
140 buttonCancel->setEnabled(
false );
141 mButtonClose = mButtonBox->button( QDialogButtonBox::Close );
145 case DialogMode::Single:
147 mAdvancedButton =
new QPushButton( tr(
"Advanced" ) );
148 mAdvancedMenu =
new QMenu(
this );
149 mAdvancedButton->setMenu( mAdvancedMenu );
151 mContextSettingsAction =
new QAction( tr(
"Algorithm Settingsā¦" ), mAdvancedMenu );
153 mAdvancedMenu->addAction( mContextSettingsAction );
155 connect( mContextSettingsAction, &QAction::triggered,
this, [
this]
159 mTabWidget->setCurrentIndex( 0 );
161 if ( !mContextOptionsWidget )
163 mContextOptionsWidget =
new QgsProcessingContextOptionsWidget();
164 mContextOptionsWidget->setFromContext( processingContext() );
165 mContextOptionsWidget->setLogLevel( mLogLevel );
166 panel->openPanel( mContextOptionsWidget );
170 mOverrideDefaultContextSettings =
true;
171 mGeometryCheck = mContextOptionsWidget->invalidGeometryCheck();
172 mDistanceUnits = mContextOptionsWidget->distanceUnit();
173 mAreaUnits = mContextOptionsWidget->areaUnit();
174 mTemporaryFolderOverride = mContextOptionsWidget->temporaryFolder();
175 mMaximumThreads = mContextOptionsWidget->maximumThreads();
176 mLogLevel = mContextOptionsWidget->logLevel();
181 mAdvancedMenu->addSeparator();
183 QAction *copyAsPythonCommand =
new QAction( tr(
"Copy as Python Command" ), mAdvancedMenu );
186 mAdvancedMenu->addAction( copyAsPythonCommand );
187 connect( copyAsPythonCommand, &QAction::triggered,
this, [
this]
195 const QString command = alg->asPythonCommand( createProcessingParameters(), *context );
196 QMimeData *m =
new QMimeData();
197 m->setText( command );
198 QClipboard *cb = QApplication::clipboard();
201 cb->setMimeData( m, QClipboard::Selection );
203 cb->setMimeData( m, QClipboard::Clipboard );
207 mCopyAsQgisProcessCommand =
new QAction( tr(
"Copy as qgis_process Command" ), mAdvancedMenu );
209 mAdvancedMenu->addAction( mCopyAsQgisProcessCommand );
211 connect( mCopyAsQgisProcessCommand, &QAction::triggered,
this, [
this]
220 const QString command = alg->asQgisProcessCommand( createProcessingParameters(), *context, ok );
223 mMessageBar->pushMessage( tr(
"Current settings cannot be specified as arguments to qgis_process (Pipe parameters as JSON to qgis_process instead)" ),
Qgis::MessageLevel::Warning );
227 QMimeData *m =
new QMimeData();
228 m->setText( command );
229 QClipboard *cb = QApplication::clipboard();
232 cb->setMimeData( m, QClipboard::Selection );
234 cb->setMimeData( m, QClipboard::Clipboard );
239 mAdvancedMenu->addSeparator();
241 QAction *copyAsJson =
new QAction( tr(
"Copy as JSON" ), mAdvancedMenu );
244 mAdvancedMenu->addAction( copyAsJson );
245 connect( copyAsJson, &QAction::triggered,
this, [
this]
253 const QVariantMap properties = alg->asMap( createProcessingParameters(), *context );
256 QMimeData *m =
new QMimeData();
258 QClipboard *cb = QApplication::clipboard();
261 cb->setMimeData( m, QClipboard::Selection );
263 cb->setMimeData( m, QClipboard::Clipboard );
267 mPasteJsonAction =
new QAction( tr(
"Paste Settings" ), mAdvancedMenu );
270 mAdvancedMenu->addAction( mPasteJsonAction );
271 connect( mPasteJsonAction, &QAction::triggered,
this, [
this]
273 const QString text = QApplication::clipboard()->text();
274 if ( text.isEmpty() )
277 const QVariantMap parameterValues =
QgsJsonUtils::parseJson( text ).toMap().value( QStringLiteral(
"inputs" ) ).toMap();
278 if ( parameterValues.isEmpty() )
285 setParameters( preparedValues );
288 mButtonBox->addButton( mAdvancedButton, QDialogButtonBox::ResetRole );
292 case DialogMode::Batch:
298 connect( mAdvancedMenu, &QMenu::aboutToShow,
this, [ = ]
300 mCopyAsQgisProcessCommand->setEnabled(
algorithm()
302 mPasteJsonAction->setEnabled( !QApplication::clipboard()->text().isEmpty() );
306 connect( mButtonRun, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::runAlgorithm );
307 connect( mButtonChangeParameters, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::showParameters );
308 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProcessingAlgorithmDialogBase::closeClicked );
309 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProcessingAlgorithmDialogBase::openHelp );
310 connect( mButtonCollapse, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::toggleCollapsed );
311 connect( splitter, &QSplitter::splitterMoved,
this, &QgsProcessingAlgorithmDialogBase::splitterChanged );
313 connect( mButtonSaveLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::saveLog );
314 connect( mButtonCopyLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::copyLogToClipboard );
315 connect( mButtonClearLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::clearLog );
317 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged );
320 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
321 verticalLayout->insertWidget( 0, mMessageBar );
326QgsProcessingAlgorithmDialogBase::~QgsProcessingAlgorithmDialogBase() =
default;
328void QgsProcessingAlgorithmDialogBase::setParameters(
const QVariantMap & )
337 title = mAlgorithm->group().isEmpty()
339 : QStringLiteral(
"%1 - %2" ).arg(
QgsStringUtils::capitalize( mAlgorithm->group(),
Qgis::Capitalization::TitleCase ),
QgsStringUtils::capitalize( mAlgorithm->displayName(),
Qgis::Capitalization::TitleCase ) );
343 title = mAlgorithm->group().isEmpty()
344 ? mAlgorithm->displayName()
345 : QStringLiteral(
"%1 - %2" ).arg( mAlgorithm->group(), mAlgorithm->displayName() );
348 setWindowTitle( title );
350 const QString algHelp = formatHelp(
algorithm );
351 if ( algHelp.isEmpty() )
352 textShortHelp->hide();
355 textShortHelp->document()->setDefaultStyleSheet( QStringLiteral(
".summary { margin-left: 10px; margin-right: 10px; }\n"
356 "h2 { color: #555555; padding-bottom: 15px; }\n"
357 "a { text - decoration: none; color: #3498db; font-weight: bold; }\n"
358 "p, ul, li { color: #666666; }\n"
359 "b { color: #333333; }\n"
360 "dl dd { margin - bottom: 5px; }" ) );
361 textShortHelp->setHtml( algHelp );
362 connect( textShortHelp, &QTextBrowser::anchorClicked,
this, &QgsProcessingAlgorithmDialogBase::linkClicked );
363 textShortHelp->show();
368 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Help ) );
372 if ( !warning.isEmpty() )
380 return mAlgorithm.get();
383void QgsProcessingAlgorithmDialogBase::setMainWidget(
QgsPanelWidget *widget )
387 mMainWidget->deleteLater();
390 mPanelStack->setMainPanel( widget );
393 mMainWidget = widget;
402void QgsProcessingAlgorithmDialogBase::saveLogToFile(
const QString &path,
const LogFormat format )
404 QFile logFile( path );
405 if ( !logFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
409 QTextStream fout( &logFile );
413 case FormatPlainText:
414 fout << txtLog->toPlainText();
418 fout << txtLog->toHtml();
425 auto feedback = std::make_unique< QgsProcessingAlgorithmDialogFeedback >();
427 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::commandInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushCommandInfo );
428 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::consoleInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushConsoleInfo );
429 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::debugInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushDebugInfo );
430 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::errorReported,
this, &QgsProcessingAlgorithmDialogBase::reportError );
431 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::warningPushed,
this, &QgsProcessingAlgorithmDialogBase::pushWarning );
432 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::infoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushInfo );
433 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::formattedMessagePushed,
this, &QgsProcessingAlgorithmDialogBase::pushFormattedMessage );
434 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::progressTextChanged,
this, &QgsProcessingAlgorithmDialogBase::setProgressText );
436 return feedback.release();
439QDialogButtonBox *QgsProcessingAlgorithmDialogBase::buttonBox()
444QTabWidget *QgsProcessingAlgorithmDialogBase::tabWidget()
449void QgsProcessingAlgorithmDialogBase::showLog()
451 mTabWidget->setCurrentIndex( 1 );
454void QgsProcessingAlgorithmDialogBase::showParameters()
456 mTabWidget->setCurrentIndex( 0 );
459QPushButton *QgsProcessingAlgorithmDialogBase::runButton()
464QPushButton *QgsProcessingAlgorithmDialogBase::cancelButton()
469QPushButton *QgsProcessingAlgorithmDialogBase::changeParametersButton()
471 return mButtonChangeParameters;
474void QgsProcessingAlgorithmDialogBase::clearProgress()
476 progressBar->setMaximum( 0 );
479void QgsProcessingAlgorithmDialogBase::setExecuted(
bool executed )
481 mExecuted = executed;
484void QgsProcessingAlgorithmDialogBase::setExecutedAnyResult(
bool executedAnyResult )
486 mExecutedAnyResult = executedAnyResult;
489void QgsProcessingAlgorithmDialogBase::setResults(
const QVariantMap &results )
499void QgsProcessingAlgorithmDialogBase::openHelp()
501 QUrl algHelp = mAlgorithm->helpUrl();
502 if ( algHelp.isEmpty() && mAlgorithm->provider() )
504 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() ) ) );
507 if ( !algHelp.isEmpty() )
508 QDesktopServices::openUrl( algHelp );
511void QgsProcessingAlgorithmDialogBase::toggleCollapsed()
513 if ( mHelpCollapsed )
515 splitter->restoreState( mSplitterState );
516 mButtonCollapse->setArrowType( Qt::RightArrow );
520 mSplitterState = splitter->saveState();
521 splitter->setSizes( QList<int>() << 1 << 0 );
522 mButtonCollapse->setArrowType( Qt::LeftArrow );
524 mHelpCollapsed = !mHelpCollapsed;
527void QgsProcessingAlgorithmDialogBase::splitterChanged(
int,
int )
529 if ( splitter->sizes().at( 1 ) == 0 )
531 mHelpCollapsed =
true;
532 mButtonCollapse->setArrowType( Qt::LeftArrow );
536 mHelpCollapsed =
false;
537 mButtonCollapse->setArrowType( Qt::RightArrow );
541void QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged(
int )
543 updateRunButtonVisibility();
546void QgsProcessingAlgorithmDialogBase::linkClicked(
const QUrl &url )
548 QDesktopServices::openUrl( url.toString() );
551void QgsProcessingAlgorithmDialogBase::algExecuted(
bool successful,
const QVariantMap & )
553 mAlgorithmTask =
nullptr;
560 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
566 if ( isFinalized() && successful )
568 progressBar->setFormat( tr(
"Complete" ) );
572 if ( isFinalized() && !isVisible() )
579void QgsProcessingAlgorithmDialogBase::taskTriggered(
QgsTask *task )
581 if ( task == mAlgorithmTask )
585 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
591void QgsProcessingAlgorithmDialogBase::closeClicked()
597void QgsProcessingAlgorithmDialogBase::urlClicked(
const QUrl &url )
599 const QFileInfo file( url.toLocalFile() );
600 if ( file.exists() && !file.isDir() )
603 QDesktopServices::openUrl( url );
616void QgsProcessingAlgorithmDialogBase::reportError(
const QString &error,
bool fatalError )
618 setInfo( error,
true );
625void QgsProcessingAlgorithmDialogBase::pushWarning(
const QString &warning )
627 setInfo( warning,
false,
true,
true );
631void QgsProcessingAlgorithmDialogBase::pushInfo(
const QString &info )
637void QgsProcessingAlgorithmDialogBase::pushFormattedMessage(
const QString &html )
639 setInfo( html,
false,
false );
643void QgsProcessingAlgorithmDialogBase::pushCommandInfo(
const QString &command )
645 txtLog->append( QStringLiteral(
"<code>%1<code>" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) );
646 scrollToBottomOfLog();
650void QgsProcessingAlgorithmDialogBase::pushDebugInfo(
const QString &message )
652 txtLog->append( QStringLiteral(
"<span style=\"color:#777\">%1</span>" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
653 scrollToBottomOfLog();
657void QgsProcessingAlgorithmDialogBase::pushConsoleInfo(
const QString &info )
659 txtLog->append( QStringLiteral(
"<code style=\"color:#777\">%1</code>" ).arg( formatStringForLog( info.toHtmlEscaped() ) ) );
660 scrollToBottomOfLog();
664QDialog *QgsProcessingAlgorithmDialogBase::createProgressDialog()
666 QgsProcessingAlgorithmProgressDialog *dialog =
new QgsProcessingAlgorithmProgressDialog(
this );
667 dialog->setWindowModality( Qt::ApplicationModal );
668 dialog->setWindowTitle( windowTitle() );
669 dialog->setGeometry( geometry() );
670 connect( progressBar, &QProgressBar::valueChanged, dialog->progressBar(), &QProgressBar::setValue );
671 connect( dialog->cancelButton(), &QPushButton::clicked, buttonCancel, &QPushButton::click );
672 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
673 connect( txtLog, &QTextEdit::textChanged, dialog, [
this, dialog]()
675 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
676 QScrollBar *sb = dialog->logTextEdit()->verticalScrollBar();
677 sb->setValue( sb->maximum() );
682void QgsProcessingAlgorithmDialogBase::clearLog()
687void QgsProcessingAlgorithmDialogBase::saveLog()
690 const QString lastUsedDir = settings.
value( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QDir::homePath() ).toString();
693 const QString txtExt = tr(
"Text files" ) + QStringLiteral(
" (*.txt *.TXT)" );
694 const QString htmlExt = tr(
"HTML files" ) + QStringLiteral(
" (*.html *.HTML)" );
696 const QString path = QFileDialog::getSaveFileName(
this, tr(
"Save Log to File" ), lastUsedDir, txtExt +
";;" + htmlExt, &filter );
700 if ( path.isEmpty() )
705 settings.
setValue( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QFileInfo( path ).path() );
707 LogFormat format = FormatPlainText;
708 if ( filter == htmlExt )
712 saveLogToFile( path, format );
715void QgsProcessingAlgorithmDialogBase::copyLogToClipboard()
717 QMimeData *m =
new QMimeData();
718 m->setText( txtLog->toPlainText() );
719 m->setHtml( txtLog->toHtml() );
720 QClipboard *cb = QApplication::clipboard();
723 cb->setMimeData( m, QClipboard::Selection );
725 cb->setMimeData( m, QClipboard::Clipboard );
728void QgsProcessingAlgorithmDialogBase::closeEvent( QCloseEvent *e )
730 if ( !mHelpCollapsed )
733 settings.
setValue( QStringLiteral(
"/Processing/dialogBaseSplitter" ), splitter->saveState() );
736 QDialog::closeEvent( e );
738 if ( !mAlgorithmTask && isFinalized() )
747void QgsProcessingAlgorithmDialogBase::runAlgorithm()
752void QgsProcessingAlgorithmDialogBase::setPercentage(
double percent )
755 if ( progressBar->maximum() == 0 )
756 progressBar->setMaximum( 100 );
757 progressBar->setValue( percent );
761void QgsProcessingAlgorithmDialogBase::setProgressText(
const QString &text )
763 lblProgress->setText( text );
764 setInfo( text,
false );
765 scrollToBottomOfLog();
773 if ( !text.isEmpty() )
775 const QStringList paragraphs = text.split(
'\n' );
777 for (
const QString ¶graph : paragraphs )
779 help += QStringLiteral(
"<p>%1</p>" ).arg( paragraph );
798 result += QStringLiteral(
"<ul><li><i>%1</i></li></ul>" ).arg( flags.join( QLatin1String(
"</i></li><li><i>" ) ) );
802 result += QStringLiteral(
"<p><b>%1</b></p>" ).arg(
803 tr(
"Warning: This algorithm is a potential security risk if executed with unchecked inputs, and may result in system damage or data leaks." )
808 result += QStringLiteral(
"<p><b>%1</b></p>" ).arg(
809 tr(
"Warning: This algorithm has known issues. The results must be carefully validated by the user." )
816void QgsProcessingAlgorithmDialogBase::processEvents()
818 if ( mAlgorithmTask )
834 while ( ++nIters < 100 )
837 QCoreApplication::processEvents();
841void QgsProcessingAlgorithmDialogBase::scrollToBottomOfLog()
843 QScrollBar *sb = txtLog->verticalScrollBar();
844 sb->setValue( sb->maximum() );
847void QgsProcessingAlgorithmDialogBase::resetGui()
849 lblProgress->clear();
850 progressBar->setMaximum( 100 );
851 progressBar->setValue( 0 );
852 mButtonRun->setEnabled(
true );
853 mButtonChangeParameters->setEnabled(
true );
854 mButtonClose->setEnabled(
true );
857 mMainWidget->setEnabled(
true );
859 updateRunButtonVisibility();
860 resetAdditionalGui();
863void QgsProcessingAlgorithmDialogBase::updateRunButtonVisibility()
866 const bool runButtonVisible = mTabWidget->currentIndex() == 0;
867 mButtonRun->setVisible( runButtonVisible );
868 if ( runButtonVisible )
869 progressBar->resetFormat();
870 mButtonChangeParameters->setVisible( !runButtonVisible && mExecutedAnyResult && mButtonChangeParameters->isEnabled() );
873void QgsProcessingAlgorithmDialogBase::resetAdditionalGui()
878void QgsProcessingAlgorithmDialogBase::blockControlsWhileRunning()
880 mButtonRun->setEnabled(
false );
881 mButtonChangeParameters->setEnabled(
false );
884 mMainWidget->setEnabled(
false );
886 blockAdditionalControlsWhileRunning();
889void QgsProcessingAlgorithmDialogBase::blockAdditionalControlsWhileRunning()
899void QgsProcessingAlgorithmDialogBase::hideShortHelp()
901 textShortHelp->setVisible(
false );
906 mAlgorithmTask = task;
911QString QgsProcessingAlgorithmDialogBase::formatStringForLog(
const QString &
string )
914 s.replace(
'\n', QLatin1String(
"<br>" ) );
918bool QgsProcessingAlgorithmDialogBase::isFinalized()
930 if ( mOverrideDefaultContextSettings )
940void QgsProcessingAlgorithmDialogBase::setInfo(
const QString &message,
bool isError,
bool escapeHtml,
bool isWarning )
942 constexpr int MESSAGE_COUNT_LIMIT = 10000;
944 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
946 ++mMessageLoggedCount;
950 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
951 txtLog->append( QStringLiteral(
"<span style=\"color:red\">%1</span>" ).arg( tr(
"Message log truncated" ) ) );
952 else if ( isError || isWarning )
953 txtLog->append( QStringLiteral(
"<span style=\"color:%1\">%2</span>" ).arg( isError ? QStringLiteral(
"red" ) : QStringLiteral(
"#b85a20" ), escapeHtml ? formatStringForLog( message.toHtmlEscaped() ) : formatStringForLog( message ) ) );
954 else if ( escapeHtml )
955 txtLog->append( QStringLiteral(
"<span>%1</span" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
957 txtLog->append( QStringLiteral(
"<span>%1</span>" ).arg( formatStringForLog( message ) ) );
958 scrollToBottomOfLog();
962void QgsProcessingAlgorithmDialogBase::reject()
964 if ( !mAlgorithmTask && isFinalized() )
966 setAttribute( Qt::WA_DeleteOnClose );
975QgsProcessingAlgorithmProgressDialog::QgsProcessingAlgorithmProgressDialog( QWidget *parent )
981QProgressBar *QgsProcessingAlgorithmProgressDialog::progressBar()
986QPushButton *QgsProcessingAlgorithmProgressDialog::cancelButton()
988 return mButtonBox->button( QDialogButtonBox::Cancel );
991QTextEdit *QgsProcessingAlgorithmProgressDialog::logTextEdit()
996void QgsProcessingAlgorithmProgressDialog::reject()
1006QgsProcessingContextOptionsWidget::QgsProcessingContextOptionsWidget( QWidget *parent )
1010 setPanelTitle( tr(
"Algorithm Settings" ) );
1016 mTemporaryFolderWidget->setDialogTitle( tr(
"Select Temporary Directory" ) );
1018 mTemporaryFolderWidget->lineEdit()->setPlaceholderText( tr(
"Default" ) );
1049 mDistanceUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1079 mAreaUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1082 mThreadsSpinBox->setRange( 1, QThread::idealThreadCount() );
1094 whileBlocking( mComboInvalidFeatureFiltering )->setCurrentIndex( mComboInvalidFeatureFiltering->findData( QVariant::fromValue( context->
invalidGeometryCheck() ) ) );
1095 whileBlocking( mDistanceUnitsCombo )->setCurrentIndex( mDistanceUnitsCombo->findData( QVariant::fromValue( context->
distanceUnit() ) ) );
1096 whileBlocking( mAreaUnitsCombo )->setCurrentIndex( mAreaUnitsCombo->findData( QVariant::fromValue( context->
areaUnit() ) ) );
1099 whileBlocking( mLogLevelComboBox )->setCurrentIndex( mLogLevelComboBox->findData(
static_cast< int >( context->
logLevel() ) ) );
1112Qgis::AreaUnit QgsProcessingContextOptionsWidget::areaUnit()
const
1117QString QgsProcessingContextOptionsWidget::temporaryFolder()
1119 return mTemporaryFolderWidget->filePath();
1122int QgsProcessingContextOptionsWidget::maximumThreads()
const
1124 return mThreadsSpinBox->value();
1129 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.