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] {
158 mTabWidget->setCurrentIndex( 0 );
160 if ( !mContextOptionsWidget )
162 mContextOptionsWidget =
new QgsProcessingContextOptionsWidget();
163 mContextOptionsWidget->setFromContext( processingContext() );
164 mContextOptionsWidget->setLogLevel( mLogLevel );
165 panel->openPanel( mContextOptionsWidget );
168 mOverrideDefaultContextSettings =
true;
169 mGeometryCheck = mContextOptionsWidget->invalidGeometryCheck();
170 mDistanceUnits = mContextOptionsWidget->distanceUnit();
171 mAreaUnits = mContextOptionsWidget->areaUnit();
172 mTemporaryFolderOverride = mContextOptionsWidget->temporaryFolder();
173 mMaximumThreads = mContextOptionsWidget->maximumThreads();
174 mLogLevel = mContextOptionsWidget->logLevel();
179 mAdvancedMenu->addSeparator();
181 QAction *copyAsPythonCommand =
new QAction( tr(
"Copy as Python Command" ), mAdvancedMenu );
184 mAdvancedMenu->addAction( copyAsPythonCommand );
185 connect( copyAsPythonCommand, &QAction::triggered,
this, [
this] {
192 const QString command = alg->asPythonCommand( createProcessingParameters(), *context );
193 QMimeData *m =
new QMimeData();
194 m->setText( command );
195 QClipboard *cb = QApplication::clipboard();
198 cb->setMimeData( m, QClipboard::Selection );
200 cb->setMimeData( m, QClipboard::Clipboard );
204 mCopyAsQgisProcessCommand =
new QAction( tr(
"Copy as qgis_process Command" ), mAdvancedMenu );
206 mAdvancedMenu->addAction( mCopyAsQgisProcessCommand );
208 connect( mCopyAsQgisProcessCommand, &QAction::triggered,
this, [
this] {
216 const QString command = alg->asQgisProcessCommand( createProcessingParameters(), *context, ok );
219 mMessageBar->pushMessage( tr(
"Current settings cannot be specified as arguments to qgis_process (Pipe parameters as JSON to qgis_process instead)" ),
Qgis::MessageLevel::Warning );
223 QMimeData *m =
new QMimeData();
224 m->setText( command );
225 QClipboard *cb = QApplication::clipboard();
228 cb->setMimeData( m, QClipboard::Selection );
230 cb->setMimeData( m, QClipboard::Clipboard );
235 mAdvancedMenu->addSeparator();
237 QAction *copyAsJson =
new QAction( tr(
"Copy as JSON" ), mAdvancedMenu );
240 mAdvancedMenu->addAction( copyAsJson );
241 connect( copyAsJson, &QAction::triggered,
this, [
this] {
248 const QVariantMap properties = alg->asMap( createProcessingParameters(), *context );
251 QMimeData *m =
new QMimeData();
253 QClipboard *cb = QApplication::clipboard();
256 cb->setMimeData( m, QClipboard::Selection );
258 cb->setMimeData( m, QClipboard::Clipboard );
262 mPasteJsonAction =
new QAction( tr(
"Paste Settings" ), mAdvancedMenu );
265 mAdvancedMenu->addAction( mPasteJsonAction );
266 connect( mPasteJsonAction, &QAction::triggered,
this, [
this] {
267 const QString text = QApplication::clipboard()->text();
268 if ( text.isEmpty() )
271 const QVariantMap parameterValues =
QgsJsonUtils::parseJson( text ).toMap().value( QStringLiteral(
"inputs" ) ).toMap();
272 if ( parameterValues.isEmpty() )
279 setParameters( preparedValues );
282 mButtonBox->addButton( mAdvancedButton, QDialogButtonBox::ResetRole );
286 case DialogMode::Batch:
292 connect( mAdvancedMenu, &QMenu::aboutToShow,
this, [=] {
294 mPasteJsonAction->setEnabled( !QApplication::clipboard()->text().isEmpty() );
298 connect( mButtonRun, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::runAlgorithm );
299 connect( mButtonChangeParameters, &QPushButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::showParameters );
300 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QgsProcessingAlgorithmDialogBase::closeClicked );
301 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsProcessingAlgorithmDialogBase::openHelp );
302 connect( mButtonCollapse, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::toggleCollapsed );
303 connect( splitter, &QSplitter::splitterMoved,
this, &QgsProcessingAlgorithmDialogBase::splitterChanged );
305 connect( mButtonSaveLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::saveLog );
306 connect( mButtonCopyLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::copyLogToClipboard );
307 connect( mButtonClearLog, &QToolButton::clicked,
this, &QgsProcessingAlgorithmDialogBase::clearLog );
309 connect( mTabWidget, &QTabWidget::currentChanged,
this, &QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged );
312 mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
313 verticalLayout->insertWidget( 0, mMessageBar );
318QgsProcessingAlgorithmDialogBase::~QgsProcessingAlgorithmDialogBase() =
default;
320void QgsProcessingAlgorithmDialogBase::setParameters(
const QVariantMap & )
329 title = mAlgorithm->group().isEmpty()
331 : QStringLiteral(
"%1 - %2" ).arg(
QgsStringUtils::capitalize( mAlgorithm->group(),
Qgis::Capitalization::TitleCase ),
QgsStringUtils::capitalize( mAlgorithm->displayName(),
Qgis::Capitalization::TitleCase ) );
335 title = mAlgorithm->group().isEmpty()
336 ? mAlgorithm->displayName()
337 : QStringLiteral(
"%1 - %2" ).arg( mAlgorithm->group(), mAlgorithm->displayName() );
340 setWindowTitle( title );
342 const QString algHelp = formatHelp(
algorithm );
343 if ( algHelp.isEmpty() )
344 textShortHelp->hide();
347 textShortHelp->document()->setDefaultStyleSheet( QStringLiteral(
".summary { margin-left: 10px; margin-right: 10px; }\n"
348 "h2 { color: #555555; padding-bottom: 15px; }\n"
349 "a { text - decoration: none; color: #3498db; font-weight: bold; }\n"
350 "p, ul, li { color: #666666; }\n"
351 "b { color: #333333; }\n"
352 "dl dd { margin - bottom: 5px; }" ) );
353 textShortHelp->setHtml( algHelp );
354 connect( textShortHelp, &QTextBrowser::anchorClicked,
this, &QgsProcessingAlgorithmDialogBase::linkClicked );
355 textShortHelp->show();
360 mButtonBox->removeButton( mButtonBox->button( QDialogButtonBox::Help ) );
364 if ( !warning.isEmpty() )
372 return mAlgorithm.get();
375void QgsProcessingAlgorithmDialogBase::setMainWidget(
QgsPanelWidget *widget )
379 mMainWidget->deleteLater();
382 mPanelStack->setMainPanel( widget );
385 mMainWidget = widget;
394void QgsProcessingAlgorithmDialogBase::saveLogToFile(
const QString &path,
const LogFormat format )
396 QFile logFile( path );
397 if ( !logFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
401 QTextStream fout( &logFile );
405 case FormatPlainText:
406 fout << txtLog->toPlainText();
410 fout << txtLog->toHtml();
417 auto feedback = std::make_unique<QgsProcessingAlgorithmDialogFeedback>();
419 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::commandInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushCommandInfo );
420 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::consoleInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushConsoleInfo );
421 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::debugInfoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushDebugInfo );
422 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::errorReported,
this, &QgsProcessingAlgorithmDialogBase::reportError );
423 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::warningPushed,
this, &QgsProcessingAlgorithmDialogBase::pushWarning );
424 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::infoPushed,
this, &QgsProcessingAlgorithmDialogBase::pushInfo );
425 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::formattedMessagePushed,
this, &QgsProcessingAlgorithmDialogBase::pushFormattedMessage );
426 connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::progressTextChanged,
this, &QgsProcessingAlgorithmDialogBase::setProgressText );
428 return feedback.release();
431QDialogButtonBox *QgsProcessingAlgorithmDialogBase::buttonBox()
436QTabWidget *QgsProcessingAlgorithmDialogBase::tabWidget()
441void QgsProcessingAlgorithmDialogBase::showLog()
443 mTabWidget->setCurrentIndex( 1 );
446void QgsProcessingAlgorithmDialogBase::showParameters()
448 mTabWidget->setCurrentIndex( 0 );
451QPushButton *QgsProcessingAlgorithmDialogBase::runButton()
456QPushButton *QgsProcessingAlgorithmDialogBase::cancelButton()
461QPushButton *QgsProcessingAlgorithmDialogBase::changeParametersButton()
463 return mButtonChangeParameters;
466void QgsProcessingAlgorithmDialogBase::clearProgress()
468 progressBar->setMaximum( 0 );
471void QgsProcessingAlgorithmDialogBase::setExecuted(
bool executed )
473 mExecuted = executed;
476void QgsProcessingAlgorithmDialogBase::setExecutedAnyResult(
bool executedAnyResult )
478 mExecutedAnyResult = executedAnyResult;
481void QgsProcessingAlgorithmDialogBase::setResults(
const QVariantMap &results )
490void QgsProcessingAlgorithmDialogBase::openHelp()
492 QUrl algHelp = mAlgorithm->helpUrl();
493 if ( algHelp.isEmpty() && mAlgorithm->provider() )
495 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().replace(
"_",
"-" ) ) ) );
498 if ( !algHelp.isEmpty() )
499 QDesktopServices::openUrl( algHelp );
502void QgsProcessingAlgorithmDialogBase::toggleCollapsed()
504 if ( mHelpCollapsed )
506 splitter->restoreState( mSplitterState );
507 mButtonCollapse->setArrowType( Qt::RightArrow );
511 mSplitterState = splitter->saveState();
512 splitter->setSizes( QList<int>() << 1 << 0 );
513 mButtonCollapse->setArrowType( Qt::LeftArrow );
515 mHelpCollapsed = !mHelpCollapsed;
518void QgsProcessingAlgorithmDialogBase::splitterChanged(
int,
int )
520 if ( splitter->sizes().at( 1 ) == 0 )
522 mHelpCollapsed =
true;
523 mButtonCollapse->setArrowType( Qt::LeftArrow );
527 mHelpCollapsed =
false;
528 mButtonCollapse->setArrowType( Qt::RightArrow );
532void QgsProcessingAlgorithmDialogBase::mTabWidget_currentChanged(
int )
534 updateRunButtonVisibility();
537void QgsProcessingAlgorithmDialogBase::linkClicked(
const QUrl &url )
539 QDesktopServices::openUrl( url.toString() );
542void QgsProcessingAlgorithmDialogBase::algExecuted(
bool successful,
const QVariantMap & )
544 mAlgorithmTask =
nullptr;
551 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
557 if ( isFinalized() && successful )
559 progressBar->setFormat( tr(
"Complete" ) );
563 if ( isFinalized() && !isVisible() )
570void QgsProcessingAlgorithmDialogBase::taskTriggered(
QgsTask *task )
572 if ( task == mAlgorithmTask )
576 setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
582void QgsProcessingAlgorithmDialogBase::closeClicked()
588void QgsProcessingAlgorithmDialogBase::urlClicked(
const QUrl &url )
590 const QFileInfo file( url.toLocalFile() );
591 if ( file.exists() && !file.isDir() )
594 QDesktopServices::openUrl( url );
607void QgsProcessingAlgorithmDialogBase::reportError(
const QString &error,
bool fatalError )
609 setInfo( error,
true );
616void QgsProcessingAlgorithmDialogBase::pushWarning(
const QString &warning )
618 setInfo( warning,
false,
true,
true );
622void QgsProcessingAlgorithmDialogBase::pushInfo(
const QString &info )
628void QgsProcessingAlgorithmDialogBase::pushFormattedMessage(
const QString &html )
630 setInfo( html,
false,
false );
634void QgsProcessingAlgorithmDialogBase::pushCommandInfo(
const QString &command )
636 txtLog->append( QStringLiteral(
"<code>%1<code>" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) );
637 scrollToBottomOfLog();
641void QgsProcessingAlgorithmDialogBase::pushDebugInfo(
const QString &message )
643 txtLog->append( QStringLiteral(
"<span style=\"color:#777\">%1</span>" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
644 scrollToBottomOfLog();
648void QgsProcessingAlgorithmDialogBase::pushConsoleInfo(
const QString &info )
650 txtLog->append( QStringLiteral(
"<code style=\"color:#777\">%1</code>" ).arg( formatStringForLog( info.toHtmlEscaped() ) ) );
651 scrollToBottomOfLog();
655QDialog *QgsProcessingAlgorithmDialogBase::createProgressDialog()
657 QgsProcessingAlgorithmProgressDialog *dialog =
new QgsProcessingAlgorithmProgressDialog(
this );
658 dialog->setWindowModality( Qt::ApplicationModal );
659 dialog->setWindowTitle( windowTitle() );
660 dialog->setGeometry( geometry() );
661 connect( progressBar, &QProgressBar::valueChanged, dialog->progressBar(), &QProgressBar::setValue );
662 connect( dialog->cancelButton(), &QPushButton::clicked, buttonCancel, &QPushButton::click );
663 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
664 connect( txtLog, &QTextEdit::textChanged, dialog, [
this, dialog]() {
665 dialog->logTextEdit()->setHtml( txtLog->toHtml() );
666 QScrollBar *sb = dialog->logTextEdit()->verticalScrollBar();
667 sb->setValue( sb->maximum() );
672void QgsProcessingAlgorithmDialogBase::clearLog()
677void QgsProcessingAlgorithmDialogBase::saveLog()
680 const QString lastUsedDir = settings.
value( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QDir::homePath() ).toString();
683 const QString txtExt = tr(
"Text files" ) + QStringLiteral(
" (*.txt *.TXT)" );
684 const QString htmlExt = tr(
"HTML files" ) + QStringLiteral(
" (*.html *.HTML)" );
686 const QString path = QFileDialog::getSaveFileName(
this, tr(
"Save Log to File" ), lastUsedDir, txtExt +
";;" + htmlExt, &filter );
690 if ( path.isEmpty() )
695 settings.
setValue( QStringLiteral(
"/Processing/lastUsedLogDirectory" ), QFileInfo( path ).path() );
697 LogFormat format = FormatPlainText;
698 if ( filter == htmlExt )
702 saveLogToFile( path, format );
705void QgsProcessingAlgorithmDialogBase::copyLogToClipboard()
707 QMimeData *m =
new QMimeData();
708 m->setText( txtLog->toPlainText() );
709 m->setHtml( txtLog->toHtml() );
710 QClipboard *cb = QApplication::clipboard();
713 cb->setMimeData( m, QClipboard::Selection );
715 cb->setMimeData( m, QClipboard::Clipboard );
718void QgsProcessingAlgorithmDialogBase::closeEvent( QCloseEvent *e )
720 if ( !mHelpCollapsed )
723 settings.
setValue( QStringLiteral(
"/Processing/dialogBaseSplitter" ), splitter->saveState() );
726 QDialog::closeEvent( e );
728 if ( !mAlgorithmTask && isFinalized() )
737void QgsProcessingAlgorithmDialogBase::runAlgorithm()
741void QgsProcessingAlgorithmDialogBase::setPercentage(
double percent )
744 if ( progressBar->maximum() == 0 )
745 progressBar->setMaximum( 100 );
746 progressBar->setValue( percent );
750void QgsProcessingAlgorithmDialogBase::setProgressText(
const QString &text )
752 lblProgress->setText( text );
753 setInfo( text,
false );
754 scrollToBottomOfLog();
762 if ( !text.isEmpty() )
764 const QStringList paragraphs = text.split(
'\n' );
766 for (
const QString ¶graph : paragraphs )
768 help += QStringLiteral(
"<p>%1</p>" ).arg( paragraph );
787 result += QStringLiteral(
"<ul><li><i>%1</i></li></ul>" ).arg( flags.join( QLatin1String(
"</i></li><li><i>" ) ) );
791 result += QStringLiteral(
"<p><b>%1</b></p>" ).arg( tr(
"Warning: This algorithm is a potential security risk if executed with unchecked inputs, and may result in system damage or data leaks." ) );
795 result += QStringLiteral(
"<p><b>%1</b></p>" ).arg( tr(
"Warning: This algorithm has known issues. The results must be carefully validated by the user." ) );
801void QgsProcessingAlgorithmDialogBase::processEvents()
803 if ( mAlgorithmTask )
819 while ( ++nIters < 100 )
822 QCoreApplication::processEvents();
826void QgsProcessingAlgorithmDialogBase::scrollToBottomOfLog()
828 QScrollBar *sb = txtLog->verticalScrollBar();
829 sb->setValue( sb->maximum() );
832void QgsProcessingAlgorithmDialogBase::resetGui()
834 lblProgress->clear();
835 progressBar->setMaximum( 100 );
836 progressBar->setValue( 0 );
837 mButtonRun->setEnabled(
true );
838 mButtonChangeParameters->setEnabled(
true );
839 mButtonClose->setEnabled(
true );
842 mMainWidget->setEnabled(
true );
844 updateRunButtonVisibility();
845 resetAdditionalGui();
848void QgsProcessingAlgorithmDialogBase::updateRunButtonVisibility()
851 const bool runButtonVisible = mTabWidget->currentIndex() == 0;
852 mButtonRun->setVisible( runButtonVisible );
853 if ( runButtonVisible )
854 progressBar->resetFormat();
855 mButtonChangeParameters->setVisible( !runButtonVisible && mExecutedAnyResult && mButtonChangeParameters->isEnabled() );
858void QgsProcessingAlgorithmDialogBase::resetAdditionalGui()
862void QgsProcessingAlgorithmDialogBase::blockControlsWhileRunning()
864 mButtonRun->setEnabled(
false );
865 mButtonChangeParameters->setEnabled(
false );
868 mMainWidget->setEnabled(
false );
870 blockAdditionalControlsWhileRunning();
873void QgsProcessingAlgorithmDialogBase::blockAdditionalControlsWhileRunning()
882void QgsProcessingAlgorithmDialogBase::hideShortHelp()
884 textShortHelp->setVisible(
false );
889 mAlgorithmTask = task;
894QString QgsProcessingAlgorithmDialogBase::formatStringForLog(
const QString &
string )
897 s.replace(
'\n', QLatin1String(
"<br>" ) );
901bool QgsProcessingAlgorithmDialogBase::isFinalized()
913 if ( mOverrideDefaultContextSettings )
923void QgsProcessingAlgorithmDialogBase::setInfo(
const QString &message,
bool isError,
bool escapeHtml,
bool isWarning )
925 constexpr int MESSAGE_COUNT_LIMIT = 10000;
927 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
929 ++mMessageLoggedCount;
933 if ( mMessageLoggedCount == MESSAGE_COUNT_LIMIT )
934 txtLog->append( QStringLiteral(
"<span style=\"color:red\">%1</span>" ).arg( tr(
"Message log truncated" ) ) );
935 else if ( isError || isWarning )
936 txtLog->append( QStringLiteral(
"<span style=\"color:%1\">%2</span>" ).arg( isError ? QStringLiteral(
"red" ) : QStringLiteral(
"#b85a20" ), escapeHtml ? formatStringForLog( message.toHtmlEscaped() ) : formatStringForLog( message ) ) );
937 else if ( escapeHtml )
938 txtLog->append( QStringLiteral(
"<span>%1</span" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
940 txtLog->append( QStringLiteral(
"<span>%1</span>" ).arg( formatStringForLog( message ) ) );
941 scrollToBottomOfLog();
945void QgsProcessingAlgorithmDialogBase::reject()
947 if ( !mAlgorithmTask && isFinalized() )
949 setAttribute( Qt::WA_DeleteOnClose );
958QgsProcessingAlgorithmProgressDialog::QgsProcessingAlgorithmProgressDialog( QWidget *parent )
964QProgressBar *QgsProcessingAlgorithmProgressDialog::progressBar()
969QPushButton *QgsProcessingAlgorithmProgressDialog::cancelButton()
971 return mButtonBox->button( QDialogButtonBox::Cancel );
974QTextEdit *QgsProcessingAlgorithmProgressDialog::logTextEdit()
979void QgsProcessingAlgorithmProgressDialog::reject()
988QgsProcessingContextOptionsWidget::QgsProcessingContextOptionsWidget( QWidget *parent )
992 setPanelTitle( tr(
"Algorithm Settings" ) );
998 mTemporaryFolderWidget->setDialogTitle( tr(
"Select Temporary Directory" ) );
1000 mTemporaryFolderWidget->lineEdit()->setPlaceholderText( tr(
"Default" ) );
1031 mDistanceUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1061 mAreaUnitsCombo->addItem( title, QVariant::fromValue( unit ) );
1064 mThreadsSpinBox->setRange( 1, QThread::idealThreadCount() );
1076 whileBlocking( mComboInvalidFeatureFiltering )->setCurrentIndex( mComboInvalidFeatureFiltering->findData( QVariant::fromValue( context->
invalidGeometryCheck() ) ) );
1077 whileBlocking( mDistanceUnitsCombo )->setCurrentIndex( mDistanceUnitsCombo->findData( QVariant::fromValue( context->
distanceUnit() ) ) );
1078 whileBlocking( mAreaUnitsCombo )->setCurrentIndex( mAreaUnitsCombo->findData( QVariant::fromValue( context->
areaUnit() ) ) );
1081 whileBlocking( mLogLevelComboBox )->setCurrentIndex( mLogLevelComboBox->findData(
static_cast<int>( context->
logLevel() ) ) );
1094Qgis::AreaUnit QgsProcessingContextOptionsWidget::areaUnit()
const
1099QString QgsProcessingContextOptionsWidget::temporaryFolder()
1101 return mTemporaryFolderWidget->filePath();
1104int QgsProcessingContextOptionsWidget::maximumThreads()
const
1106 return mThreadsSpinBox->value();
1111 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.