QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsprocessingalgorithmdialogbase.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingalgorithmdialogbase.cpp
3  ------------------------------------
4  Date : November 2017
5  Copyright : (C) 2017 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 #include "qgssettings.h"
18 #include "qgshelp.h"
19 #include "qgsmessagebar.h"
20 #include "qgsgui.h"
23 #include "qgstaskmanager.h"
25 #include "qgsstringutils.h"
26 #include <QToolButton>
27 #include <QDesktopServices>
28 #include <QScrollBar>
29 #include <QApplication>
30 #include <QClipboard>
31 #include <QFileDialog>
32 
33 
35 
36 QgsProcessingAlgorithmDialogFeedback::QgsProcessingAlgorithmDialogFeedback()
37 {
38 }
39 
40 void QgsProcessingAlgorithmDialogFeedback::setProgressText( const QString &text )
41 {
42  emit progressTextChanged( text );
43 }
44 
45 void QgsProcessingAlgorithmDialogFeedback::reportError( const QString &error, bool fatalError )
46 {
47  emit errorReported( error, fatalError );
48 }
49 
50 void QgsProcessingAlgorithmDialogFeedback::pushInfo( const QString &info )
51 {
52  emit infoPushed( info );
53 }
54 
55 void QgsProcessingAlgorithmDialogFeedback::pushCommandInfo( const QString &info )
56 {
57  emit commandInfoPushed( info );
58 }
59 
60 void QgsProcessingAlgorithmDialogFeedback::pushDebugInfo( const QString &info )
61 {
62  emit debugInfoPushed( info );
63 }
64 
65 void QgsProcessingAlgorithmDialogFeedback::pushConsoleInfo( const QString &info )
66 {
67  emit consoleInfoPushed( info );
68 }
69 
70 //
71 // QgsProcessingAlgorithmDialogBase
72 //
73 
74 QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *parent, Qt::WindowFlags flags )
75  : QDialog( parent, flags )
76 {
77  setupUi( this );
78 
79  //don't collapse parameters panel
80  splitter->setCollapsible( 0, false );
81 
82  // add collapse button to splitter
83  QSplitterHandle *splitterHandle = splitter->handle( 1 );
84  QVBoxLayout *handleLayout = new QVBoxLayout();
85  handleLayout->setContentsMargins( 0, 0, 0, 0 );
86  mButtonCollapse = new QToolButton( splitterHandle );
87  mButtonCollapse->setAutoRaise( true );
88  mButtonCollapse->setFixedSize( 12, 12 );
89  mButtonCollapse->setCursor( Qt::ArrowCursor );
90  handleLayout->addWidget( mButtonCollapse );
91  handleLayout->addStretch();
92  splitterHandle->setLayout( handleLayout );
93 
95 
96  QgsSettings settings;
97  splitter->restoreState( settings.value( QStringLiteral( "/Processing/dialogBaseSplitter" ), QByteArray() ).toByteArray() );
98  mSplitterState = splitter->saveState();
99  splitterChanged( 0, 0 );
100 
101  connect( mButtonBox, &QDialogButtonBox::rejected, this, &QgsProcessingAlgorithmDialogBase::closeClicked );
102  connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsProcessingAlgorithmDialogBase::accept );
103 
104  // Rename OK button to Run
105  mButtonRun = mButtonBox->button( QDialogButtonBox::Ok );
106  mButtonRun->setText( tr( "Run" ) );
107 
108  buttonCancel->setEnabled( false );
109  mButtonClose = mButtonBox->button( QDialogButtonBox::Close );
110 
111  connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsProcessingAlgorithmDialogBase::openHelp );
112  connect( mButtonCollapse, &QToolButton::clicked, this, &QgsProcessingAlgorithmDialogBase::toggleCollapsed );
113  connect( splitter, &QSplitter::splitterMoved, this, &QgsProcessingAlgorithmDialogBase::splitterChanged );
114 
115  connect( mButtonSaveLog, &QToolButton::clicked, this, &QgsProcessingAlgorithmDialogBase::saveLog );
116  connect( mButtonCopyLog, &QToolButton::clicked, this, &QgsProcessingAlgorithmDialogBase::copyLogToClipboard );
117  connect( mButtonClearLog, &QToolButton::clicked, this, &QgsProcessingAlgorithmDialogBase::clearLog );
118 
119  mMessageBar = new QgsMessageBar();
120  mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
121  verticalLayout->insertWidget( 0, mMessageBar );
122 
123  connect( QgsApplication::taskManager(), &QgsTaskManager::taskTriggered, this, &QgsProcessingAlgorithmDialogBase::taskTriggered );
124 }
125 
126 void QgsProcessingAlgorithmDialogBase::setAlgorithm( QgsProcessingAlgorithm *algorithm )
127 {
128  mAlgorithm = algorithm;
129  QString title;
131  title = mAlgorithm->displayName();
132  else
133  title = QgsStringUtils::capitalize( mAlgorithm->displayName(), QgsStringUtils::TitleCase );
134  setWindowTitle( title );
135 
136  QString algHelp = formatHelp( algorithm );
137  if ( algHelp.isEmpty() )
138  textShortHelp->hide();
139  else
140  {
141  textShortHelp->document()->setDefaultStyleSheet( QStringLiteral( ".summary { margin-left: 10px; margin-right: 10px; }\n"
142  "h2 { color: #555555; padding-bottom: 15px; }\n"
143  "a { text - decoration: none; color: #3498db; font-weight: bold; }\n"
144  "p { color: #666666; }\n"
145  "b { color: #333333; }\n"
146  "dl dd { margin - bottom: 5px; }" ) );
147  textShortHelp->setHtml( algHelp );
148  connect( textShortHelp, &QTextBrowser::anchorClicked, this, &QgsProcessingAlgorithmDialogBase::linkClicked );
149  }
150 
151  if ( !( algorithm->flags() & QgsProcessingAlgorithm::FlagNoThreading ) )
152  mButtonRun->setText( tr( "Run in Background" ) );
153 }
154 
156 {
157  return mAlgorithm;
158 }
159 
160 void QgsProcessingAlgorithmDialogBase::setMainWidget( QWidget *widget )
161 {
162  if ( mMainWidget )
163  {
164  mMainWidget->deleteLater();
165  }
166 
167  mMainWidget = widget;
168  mTabWidget->widget( 0 )->layout()->addWidget( mMainWidget );
169 }
170 
171 QWidget *QgsProcessingAlgorithmDialogBase::mainWidget()
172 {
173  return mMainWidget;
174 }
175 
176 QVariantMap QgsProcessingAlgorithmDialogBase::getParameterValues() const
177 {
178  return QVariantMap();
179 }
180 
181 void QgsProcessingAlgorithmDialogBase::saveLogToFile( const QString &path, const LogFormat format )
182 {
183  QFile logFile( path );
184  if ( !logFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
185  {
186  return;
187  }
188  QTextStream fout( &logFile );
189 
190  switch ( format )
191  {
192  case FormatPlainText:
193  fout << txtLog->toPlainText();
194  break;
195 
196  case FormatHtml:
197  fout << txtLog->toHtml();
198  break;
199  }
200 }
201 
202 QgsProcessingFeedback *QgsProcessingAlgorithmDialogBase::createFeedback()
203 {
204  auto feedback = qgis::make_unique< QgsProcessingAlgorithmDialogFeedback >();
205  connect( feedback.get(), &QgsProcessingFeedback::progressChanged, this, &QgsProcessingAlgorithmDialogBase::setPercentage );
206  connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::commandInfoPushed, this, &QgsProcessingAlgorithmDialogBase::pushCommandInfo );
207  connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::consoleInfoPushed, this, &QgsProcessingAlgorithmDialogBase::pushConsoleInfo );
208  connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::debugInfoPushed, this, &QgsProcessingAlgorithmDialogBase::pushDebugInfo );
209  connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::errorReported, this, &QgsProcessingAlgorithmDialogBase::reportError );
210  connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::infoPushed, this, &QgsProcessingAlgorithmDialogBase::pushInfo );
211  connect( feedback.get(), &QgsProcessingAlgorithmDialogFeedback::progressTextChanged, this, &QgsProcessingAlgorithmDialogBase::setProgressText );
212  connect( buttonCancel, &QPushButton::clicked, feedback.get(), &QgsProcessingFeedback::cancel );
213  return feedback.release();
214 }
215 
216 QDialogButtonBox *QgsProcessingAlgorithmDialogBase::buttonBox()
217 {
218  return mButtonBox;
219 }
220 
221 QTabWidget *QgsProcessingAlgorithmDialogBase::tabWidget()
222 {
223  return mTabWidget;
224 }
225 
226 void QgsProcessingAlgorithmDialogBase::showLog()
227 {
228  mTabWidget->setCurrentIndex( 1 );
229 }
230 
231 QPushButton *QgsProcessingAlgorithmDialogBase::runButton()
232 {
233  return mButtonRun;
234 }
235 
236 QPushButton *QgsProcessingAlgorithmDialogBase::cancelButton()
237 {
238  return buttonCancel;
239 }
240 
241 void QgsProcessingAlgorithmDialogBase::clearProgress()
242 {
243  progressBar->setMaximum( 0 );
244 }
245 
246 void QgsProcessingAlgorithmDialogBase::setExecuted( bool executed )
247 {
248  mExecuted = executed;
249 }
250 
251 void QgsProcessingAlgorithmDialogBase::setResults( const QVariantMap &results )
252 {
253  mResults = results;
254 }
255 
256 void QgsProcessingAlgorithmDialogBase::finished( bool, const QVariantMap &, QgsProcessingContext &, QgsProcessingFeedback * )
257 {
258 
259 }
260 
261 void QgsProcessingAlgorithmDialogBase::accept()
262 {
263 }
264 
265 void QgsProcessingAlgorithmDialogBase::openHelp()
266 {
267  QUrl algHelp = mAlgorithm->helpUrl();
268  if ( algHelp.isEmpty() )
269  {
270  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() ) ) );
271  }
272 
273  if ( !algHelp.isEmpty() )
274  QDesktopServices::openUrl( algHelp );
275 }
276 
277 void QgsProcessingAlgorithmDialogBase::toggleCollapsed()
278 {
279  if ( mHelpCollapsed )
280  {
281  splitter->restoreState( mSplitterState );
282  mButtonCollapse->setArrowType( Qt::RightArrow );
283  }
284  else
285  {
286  mSplitterState = splitter->saveState();
287  splitter->setSizes( QList<int>() << 1 << 0 );
288  mButtonCollapse->setArrowType( Qt::LeftArrow );
289  }
290  mHelpCollapsed = !mHelpCollapsed;
291 }
292 
293 void QgsProcessingAlgorithmDialogBase::splitterChanged( int, int )
294 {
295  if ( splitter->sizes().at( 1 ) == 0 )
296  {
297  mHelpCollapsed = true;
298  mButtonCollapse->setArrowType( Qt::LeftArrow );
299  }
300  else
301  {
302  mHelpCollapsed = false;
303  mButtonCollapse->setArrowType( Qt::RightArrow );
304  }
305 }
306 
307 void QgsProcessingAlgorithmDialogBase::linkClicked( const QUrl &url )
308 {
309  QDesktopServices::openUrl( url.toString() );
310 }
311 
312 void QgsProcessingAlgorithmDialogBase::algExecuted( bool successful, const QVariantMap & )
313 {
314  mAlgorithmTask = nullptr;
315 
316  if ( !successful )
317  {
318  // show dialog to display errors
319  show();
320  raise();
321  setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
322  activateWindow();
323  showLog();
324  }
325  else
326  {
327  // delete dialog if closed
328  if ( !isVisible() )
329  {
330  deleteLater();
331  }
332  }
333 }
334 
335 void QgsProcessingAlgorithmDialogBase::taskTriggered( QgsTask *task )
336 {
337  if ( task == mAlgorithmTask )
338  {
339  show();
340  raise();
341  setWindowState( ( windowState() & ~Qt::WindowMinimized ) | Qt::WindowActive );
342  activateWindow();
343  showLog();
344  }
345 }
346 
347 void QgsProcessingAlgorithmDialogBase::closeClicked()
348 {
349  reject();
350  close();
351 }
352 
353 void QgsProcessingAlgorithmDialogBase::reportError( const QString &error, bool fatalError )
354 {
355  setInfo( error, true );
356  if ( fatalError )
357  resetGui();
358  showLog();
359  processEvents();
360 }
361 
362 void QgsProcessingAlgorithmDialogBase::pushInfo( const QString &info )
363 {
364  setInfo( info );
365  processEvents();
366 }
367 
368 void QgsProcessingAlgorithmDialogBase::pushCommandInfo( const QString &command )
369 {
370  txtLog->append( QStringLiteral( "<code>%1<code>" ).arg( formatStringForLog( command.toHtmlEscaped() ) ) );
371  scrollToBottomOfLog();
372  processEvents();
373 }
374 
375 void QgsProcessingAlgorithmDialogBase::pushDebugInfo( const QString &message )
376 {
377  txtLog->append( QStringLiteral( "<span style=\"color:blue\">%1</span>" ).arg( formatStringForLog( message.toHtmlEscaped() ) ) );
378  scrollToBottomOfLog();
379  processEvents();
380 }
381 
382 void QgsProcessingAlgorithmDialogBase::pushConsoleInfo( const QString &info )
383 {
384  txtLog->append( QStringLiteral( "<code><span style=\"color:blue\">%1</darkgray></code>" ).arg( formatStringForLog( info.toHtmlEscaped() ) ) );
385  scrollToBottomOfLog();
386  processEvents();
387 }
388 
389 QDialog *QgsProcessingAlgorithmDialogBase::createProgressDialog()
390 {
391  QgsProcessingAlgorithmProgressDialog *dialog = new QgsProcessingAlgorithmProgressDialog( this );
392  dialog->setWindowModality( Qt::ApplicationModal );
393  dialog->setWindowTitle( windowTitle() );
394  connect( progressBar, &QProgressBar::valueChanged, dialog->progressBar(), &QProgressBar::setValue );
395  connect( dialog->cancelButton(), &QPushButton::clicked, buttonCancel, &QPushButton::click );
396  dialog->logTextEdit()->setHtml( txtLog->toHtml() );
397  connect( txtLog, &QTextEdit::textChanged, dialog, [this, dialog]()
398  {
399  dialog->logTextEdit()->setHtml( txtLog->toHtml() );
400  QScrollBar *sb = dialog->logTextEdit()->verticalScrollBar();
401  sb->setValue( sb->maximum() );
402  } );
403  return dialog;
404 }
405 
406 void QgsProcessingAlgorithmDialogBase::clearLog()
407 {
408  txtLog->clear();
409 }
410 
411 void QgsProcessingAlgorithmDialogBase::saveLog()
412 {
413  QgsSettings settings;
414  QString lastUsedDir = settings.value( QStringLiteral( "/Processing/lastUsedLogDirectory" ), QDir::homePath() ).toString();
415 
416  QString filter;
417  const QString txtExt = tr( "Text files" ) + QStringLiteral( " (*.txt *.TXT)" );
418  const QString htmlExt = tr( "HTML files" ) + QStringLiteral( " (*.html *.HTML)" );
419 
420  QString path = QFileDialog::getSaveFileName( this, tr( "Save Log to File" ), lastUsedDir, txtExt + ";;" + htmlExt, &filter );
421  if ( path.isEmpty() )
422  {
423  return;
424  }
425 
426  settings.setValue( QStringLiteral( "/Processing/lastUsedLogDirectory" ), QFileInfo( path ).path() );
427 
428  LogFormat format = FormatPlainText;
429  if ( filter == htmlExt )
430  {
431  format = FormatHtml;
432  }
433  saveLogToFile( path, format );
434 }
435 
436 void QgsProcessingAlgorithmDialogBase::copyLogToClipboard()
437 {
438  QMimeData *m = new QMimeData();
439  m->setText( txtLog->toPlainText() );
440  m->setHtml( txtLog->toHtml() );
441  QClipboard *cb = QApplication::clipboard();
442 
443 #ifdef Q_OS_LINUX
444  cb->setMimeData( m, QClipboard::Selection );
445 #endif
446  cb->setMimeData( m, QClipboard::Clipboard );
447 }
448 
449 void QgsProcessingAlgorithmDialogBase::closeEvent( QCloseEvent *e )
450 {
451  QDialog::closeEvent( e );
452 
453  if ( !mAlgorithmTask )
454  {
455  // when running a background task, the dialog is kept around and deleted only when the task
456  // completes. But if not running a task, we auto cleanup (later - gotta give callers a chance
457  // to retrieve results and execution status).
458  deleteLater();
459  }
460 }
461 
462 void QgsProcessingAlgorithmDialogBase::setPercentage( double percent )
463 {
464  // delay setting maximum progress value until we know algorithm reports progress
465  if ( progressBar->maximum() == 0 )
466  progressBar->setMaximum( 100 );
467  progressBar->setValue( percent );
468  processEvents();
469 }
470 
471 void QgsProcessingAlgorithmDialogBase::setProgressText( const QString &text )
472 {
473  lblProgress->setText( text );
474  setInfo( text, false );
475  scrollToBottomOfLog();
476  processEvents();
477 }
478 
479 QString QgsProcessingAlgorithmDialogBase::formatHelp( QgsProcessingAlgorithm *algorithm )
480 {
481  QString text = algorithm->shortHelpString();
482  if ( !text.isEmpty() )
483  {
484  QStringList paragraphs = text.split( '\n' );
485  QString help;
486  for ( const QString &paragraph : paragraphs )
487  {
488  help += QStringLiteral( "<p>%1</p>" ).arg( paragraph );
489  }
490  return QStringLiteral( "<h2>%1</h2>%2" ).arg( algorithm->displayName(), help );
491  }
492  else if ( !algorithm->shortDescription().isEmpty() )
493  {
494  return QStringLiteral( "<h2>%1</h2><p>%2</p>" ).arg( algorithm->displayName(), algorithm->shortDescription() );
495  }
496  else
497  return QString();
498 }
499 
500 void QgsProcessingAlgorithmDialogBase::processEvents()
501 {
502  if ( mAlgorithmTask )
503  {
504  // no need to call this - the algorithm is running in a thread.
505  // in fact, calling it causes a crash on Windows when the algorithm
506  // is running in a background thread... unfortunately we need something
507  // like this for non-threadable algorithms, otherwise there's no chance
508  // for users to hit cancel or see progress updates...
509  return;
510  }
511 
512  // So that we get a chance of hitting the Abort button
513 #ifdef Q_OS_LINUX
514  // For some reason on Windows hasPendingEvents() always return true,
515  // but one iteration is actually enough on Windows to get good interactivity
516  // whereas on Linux we must allow for far more iterations.
517  // For safety limit the number of iterations
518  int nIters = 0;
519  while ( QCoreApplication::hasPendingEvents() && ++nIters < 100 )
520 #endif
521  {
522  QCoreApplication::processEvents();
523  }
524 }
525 
526 void QgsProcessingAlgorithmDialogBase::scrollToBottomOfLog()
527 {
528  QScrollBar *sb = txtLog->verticalScrollBar();
529  sb->setValue( sb->maximum() );
530 }
531 
532 void QgsProcessingAlgorithmDialogBase::resetGui()
533 {
534  lblProgress->clear();
535  progressBar->setMaximum( 100 );
536  progressBar->setValue( 0 );
537  mButtonRun->setEnabled( true );
538  mButtonClose->setEnabled( true );
539 }
540 
541 QgsMessageBar *QgsProcessingAlgorithmDialogBase::messageBar()
542 {
543  return mMessageBar;
544 }
545 
546 void QgsProcessingAlgorithmDialogBase::hideShortHelp()
547 {
548  textShortHelp->setVisible( false );
549 }
550 
551 void QgsProcessingAlgorithmDialogBase::setCurrentTask( QgsProcessingAlgRunnerTask *task )
552 {
553  mAlgorithmTask = task;
554  connect( mAlgorithmTask, &QgsProcessingAlgRunnerTask::executed, this, &QgsProcessingAlgorithmDialogBase::algExecuted );
555  QgsApplication::taskManager()->addTask( mAlgorithmTask );
556 }
557 
558 QString QgsProcessingAlgorithmDialogBase::formatStringForLog( const QString &string )
559 {
560  QString s = string;
561  s.replace( '\n', QStringLiteral( "<br>" ) );
562  return s;
563 }
564 
565 void QgsProcessingAlgorithmDialogBase::setInfo( const QString &message, bool isError, bool escapeHtml )
566 {
567  if ( isError )
568  txtLog->append( QStringLiteral( "<span style=\"color:red\">%1</span>" ).arg( escapeHtml ? formatStringForLog( message.toHtmlEscaped() ) : formatStringForLog( message ) ) );
569  else if ( escapeHtml )
570  txtLog->append( formatStringForLog( message.toHtmlEscaped() ) );
571  else
572  txtLog->append( formatStringForLog( message ) );
573  scrollToBottomOfLog();
574  processEvents();
575 }
576 
577 //
578 // QgsProcessingAlgorithmProgressDialog
579 //
580 
581 QgsProcessingAlgorithmProgressDialog::QgsProcessingAlgorithmProgressDialog( QWidget *parent )
582  : QDialog( parent )
583 {
584  setupUi( this );
586 }
587 
588 QProgressBar *QgsProcessingAlgorithmProgressDialog::progressBar()
589 {
590  return mProgressBar;
591 }
592 
593 QPushButton *QgsProcessingAlgorithmProgressDialog::cancelButton()
594 {
595  return mButtonBox->button( QDialogButtonBox::Cancel );
596 }
597 
598 QTextEdit *QgsProcessingAlgorithmProgressDialog::logTextEdit()
599 {
600  return mTxtLog;
601 }
602 
603 void QgsProcessingAlgorithmProgressDialog::reject()
604 {
605 
606 }
607 
608 
609 
Base class for providing feedback from a processing algorithm.
void taskTriggered(QgsTask *task)
Emitted when a task is triggered.
void cancel()
Tells the internal routines that the current operation should be canceled. This should be run by the ...
Definition: qgsfeedback.h:85
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
Algorithm&#39;s display name is a static literal string, and should not be translated or automatically fo...
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users...
static QgsGui * instance()
Returns a pointer to the singleton instance.
Definition: qgsgui.cpp:36
virtual QString shortHelpString() const
Returns a localised short helper string for the algorithm.
Abstract base class for processing algorithms.
static QUrl helpUrl(const QString &key)
Returns URI of the help topic for the given key.
Definition: qgshelp.cpp:40
static QgsTaskManager * taskManager()
Returns the application&#39;s task manager, used for managing application wide background task handling...
void progressChanged(double progress)
Emitted when the feedback object reports a progress change.
static QString capitalize(const QString &string, Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
Algorithm is not thread safe and cannot be run in a background thread, e.g. for algorithms which mani...
long addTask(QgsTask *task, int priority=0)
Adds a task to the manager.
Abstract base class for long running background tasks.
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
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
virtual QString displayName() const =0
Returns the translated algorithm name, which should be used for any user-visible display of the algor...
virtual QString shortDescription() const
Returns an optional translated short description of the algorithm.
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...
Definition: qgsgui.cpp:82
QgsTask task which runs a QgsProcessingAlgorithm in a background task.
Contains information about the context in which a processing algorithm is executed.
void executed(bool successful, const QVariantMap &results)
Emitted when the algorithm has finished execution.