QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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, private Ui::QgsProcessingDialogBase
85 {
86  Q_OBJECT
87 
88  public:
89 
94  enum LogFormat
95  {
96  FormatPlainText,
97  FormatHtml,
98  };
99 
103  QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags() );
104  ~QgsProcessingAlgorithmDialogBase() override;
105 
113  void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
114 
120 
125  void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
126 
131  QgsPanelWidget *mainWidget();
132 
136  void showLog();
137 
143  bool wasExecuted() const { return mExecuted; }
144 
150  QVariantMap results() const { return mResults; }
151 
156  QgsProcessingFeedback *createFeedback() SIP_FACTORY;
157 
164  void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
165 
166  public slots:
167 
173  void reportError( const QString &error, bool fatalError );
174 
178  void pushWarning( const QString &warning );
179 
183  void pushInfo( const QString &info );
184 
188  void pushDebugInfo( const QString &message );
189 
193  void pushCommandInfo( const QString &info );
194 
198  void setPercentage( double percent );
199 
203  void setProgressText( const QString &text );
204 
208  void pushConsoleInfo( const QString &info );
209 
214  QDialog *createProgressDialog();
215 
220  void clearLog();
221 
227  void saveLog();
228 
233  void copyLogToClipboard();
234 
238  void showParameters();
239 
240  void reject() override;
241 
242  protected:
243 
244  void closeEvent( QCloseEvent *e ) override;
245 
249  QPushButton *runButton();
250 
254  QPushButton *cancelButton();
255 
259  QPushButton *changeParametersButton();
260 
264  QDialogButtonBox *buttonBox();
265 
269  QTabWidget *tabWidget();
270 
274  void clearProgress();
275 
281  void setExecuted( bool executed );
282 
286  void setExecutedAnyResult( bool executedAnyResult );
287 
293  void setResults( const QVariantMap &results );
294 
298  void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
299 
303  void resetGui();
304 
309  virtual void resetAdditionalGui();
310 
314  void updateRunButtonVisibility();
315 
320  void blockControlsWhileRunning();
321 
326  virtual void blockAdditionalControlsWhileRunning();
327 
331  QgsMessageBar *messageBar();
332 
336  void hideShortHelp();
337 
342  void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
343 
349  static QString formatStringForLog( const QString &string );
350 
351  signals:
352 
358  void algorithmFinished( bool successful, const QVariantMap &result );
359 
360  protected slots:
361 
365  virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
366 
370  virtual void runAlgorithm();
371 
372  private slots:
373 
374  void openHelp();
375  void toggleCollapsed();
376 
377  void splitterChanged( int pos, int index );
378  void mTabWidget_currentChanged( int index );
379  void linkClicked( const QUrl &url );
380  void algExecuted( bool successful, const QVariantMap &results );
381  void taskTriggered( QgsTask *task );
382  void closeClicked();
383 
384  private:
385 
386  QPushButton *mButtonRun = nullptr;
387  QPushButton *mButtonClose = nullptr;
388  QPushButton *mButtonChangeParameters = nullptr;
389  QByteArray mSplitterState;
390  QToolButton *mButtonCollapse = nullptr;
391  QgsMessageBar *mMessageBar = nullptr;
392 
393  bool mExecuted = false;
394  bool mExecutedAnyResult = false;
395  QVariantMap mResults;
396  QgsPanelWidget *mMainWidget = nullptr;
397  std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
398  QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
399 
400  bool mHelpCollapsed = false;
401 
402  QString formatHelp( QgsProcessingAlgorithm *algorithm );
403  void scrollToBottomOfLog();
404  void processEvents();
405 
406 };
407 
408 #ifndef SIP_RUN
409 
416 class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
417 {
418  Q_OBJECT
419 
420  public:
421 
425  QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
426 
430  QProgressBar *progressBar();
431 
435  QPushButton *cancelButton();
436 
440  QTextEdit *logTextEdit();
441 
442  public slots:
443 
444  void reject() override;
445 
446 };
447 
448 #endif
449 
451 
452 #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.
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