QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsprocessingalgorithmdialogbase.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsprocessingalgorithmdialogbase.h
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 
16 #ifndef QGSPROCESSINGALGORITHMDIALOGBASE_H
17 #define QGSPROCESSINGALGORITHMDIALOGBASE_H
18 
19 #include "qgis.h"
20 #include "qgis_gui.h"
21 #include "ui_qgsprocessingalgorithmdialogbase.h"
22 #include "ui_qgsprocessingalgorithmprogressdialogbase.h"
26 
28 
30 class QToolButton;
31 class QgsProcessingAlgorithmDialogBase;
32 class QgsMessageBar;
34 class QgsTask;
35 
36 #ifndef SIP_RUN
37 
44 class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
45 {
46  Q_OBJECT
47 
48  public:
49 
53  QgsProcessingAlgorithmDialogFeedback();
54 
55  signals:
56 
57  void progressTextChanged( const QString &text );
58  void errorReported( const QString &text, bool fatalError );
59  void warningPushed( const QString &text );
60  void infoPushed( const QString &text );
61  void commandInfoPushed( const QString &text );
62  void debugInfoPushed( const QString &text );
63  void consoleInfoPushed( const QString &text );
64 
65  public slots:
66 
67  void setProgressText( const QString &text ) override;
68  void reportError( const QString &error, bool fatalError ) override;
69  void pushWarning( const QString &info ) override;
70  void pushInfo( const QString &info ) override;
71  void pushCommandInfo( const QString &info ) override;
72  void pushDebugInfo( const QString &info ) override;
73  void pushConsoleInfo( const QString &info ) override;
74 
75 };
76 #endif
77 
84 class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsProcessingParametersGenerator, public QgsProcessingContextGenerator, private Ui::QgsProcessingDialogBase
85 {
86  Q_OBJECT
87 
88  public:
89 
94  enum LogFormat
95  {
96  FormatPlainText,
97  FormatHtml,
98  };
99 
105  enum class DialogMode : int
106  {
107  Single,
108  Batch,
109  };
110  Q_ENUM( QgsProcessingAlgorithmDialogBase::DialogMode )
111 
112 
115  QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), QgsProcessingAlgorithmDialogBase::DialogMode mode = QgsProcessingAlgorithmDialogBase::DialogMode::Single );
116  ~QgsProcessingAlgorithmDialogBase() override;
117 
125  void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
126 
132 
137  void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
138 
143  QgsPanelWidget *mainWidget();
144 
148  void showLog();
149 
155  bool wasExecuted() const { return mExecuted; }
156 
162  QVariantMap results() const { return mResults; }
163 
168  QgsProcessingFeedback *createFeedback() SIP_FACTORY;
169 
176  void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
177 
184  QgsProcessingContext::LogLevel logLevel() const;
185 
192  void setLogLevel( QgsProcessingContext::LogLevel level );
193 
199  virtual void setParameters( const QVariantMap &values );
200 
201  public slots:
202 
208  void reportError( const QString &error, bool fatalError );
209 
213  void pushWarning( const QString &warning );
214 
218  void pushInfo( const QString &info );
219 
223  void pushDebugInfo( const QString &message );
224 
228  void pushCommandInfo( const QString &info );
229 
233  void setPercentage( double percent );
234 
238  void setProgressText( const QString &text );
239 
243  void pushConsoleInfo( const QString &info );
244 
249  QDialog *createProgressDialog();
250 
255  void clearLog();
256 
262  void saveLog();
263 
268  void copyLogToClipboard();
269 
273  void showParameters();
274 
275  void reject() override;
276 
277  protected:
278 
279  void closeEvent( QCloseEvent *e ) override;
280 
284  QPushButton *runButton();
285 
289  QPushButton *cancelButton();
290 
294  QPushButton *changeParametersButton();
295 
299  QDialogButtonBox *buttonBox();
300 
304  QTabWidget *tabWidget();
305 
309  void clearProgress();
310 
316  void setExecuted( bool executed );
317 
321  void setExecutedAnyResult( bool executedAnyResult );
322 
328  void setResults( const QVariantMap &results );
329 
333  void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
334 
338  void resetGui();
339 
344  virtual void resetAdditionalGui();
345 
349  void updateRunButtonVisibility();
350 
355  void blockControlsWhileRunning();
356 
361  virtual void blockAdditionalControlsWhileRunning();
362 
366  QgsMessageBar *messageBar();
367 
371  void hideShortHelp();
372 
377  void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
378 
384  static QString formatStringForLog( const QString &string );
385 
386  signals:
387 
393  void algorithmFinished( bool successful, const QVariantMap &result );
394 
395  protected slots:
396 
400  virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
401 
405  virtual void runAlgorithm();
406 
407  private slots:
408 
409  void openHelp();
410  void toggleCollapsed();
411 
412  void splitterChanged( int pos, int index );
413  void mTabWidget_currentChanged( int index );
414  void linkClicked( const QUrl &url );
415  void algExecuted( bool successful, const QVariantMap &results );
416  void taskTriggered( QgsTask *task );
417  void closeClicked();
418 
419  private:
420 
421  DialogMode mMode = DialogMode::Single;
422 
423  QPushButton *mButtonRun = nullptr;
424  QPushButton *mButtonClose = nullptr;
425  QPushButton *mButtonChangeParameters = nullptr;
426  QByteArray mSplitterState;
427  QToolButton *mButtonCollapse = nullptr;
428  QgsMessageBar *mMessageBar = nullptr;
429  QPushButton *mAdvancedButton = nullptr;
430  QMenu *mAdvancedMenu = nullptr;
431  QAction *mCopyAsQgisProcessCommand = nullptr;
432  QAction *mPasteJsonAction = nullptr;
433 
434  bool mExecuted = false;
435  bool mExecutedAnyResult = false;
436  QVariantMap mResults;
437  QgsPanelWidget *mMainWidget = nullptr;
438  std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
439  QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
440 
441  bool mHelpCollapsed = false;
442 
443  int mMessageLoggedCount = 0;
444 
445  QgsProcessingContext::LogLevel mLogLevel = QgsProcessingContext::DefaultLevel;
446 
447  QString formatHelp( QgsProcessingAlgorithm *algorithm );
448  void scrollToBottomOfLog();
449  void processEvents();
450 
451 };
452 
453 #ifndef SIP_RUN
454 
461 class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
462 {
463  Q_OBJECT
464 
465  public:
466 
470  QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
471 
475  QProgressBar *progressBar();
476 
480  QPushButton *cancelButton();
481 
485  QTextEdit *logTextEdit();
486 
487  public slots:
488 
489  void reject() override;
490 
491 };
492 
493 #endif
494 
496 
497 #endif // QGSPROCESSINGALGORITHMDIALOGBASE_H
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
Base class for any widget that can be shown as a inline panel.
QgsTask task which runs a QgsProcessingAlgorithm in a background task.
Abstract base class for processing algorithms.
An interface for objects which can create Processing contexts.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
An interface for objects which can create sets of parameter values for processing algorithms.
Abstract base class for long running background tasks.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
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
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76