QGIS API Documentation  3.21.0-Master (5b68dc587e)
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 
172  QgsProcessingContext::LogLevel logLevel() const;
173 
180  void setLogLevel( QgsProcessingContext::LogLevel level );
181 
182  public slots:
183 
189  void reportError( const QString &error, bool fatalError );
190 
194  void pushWarning( const QString &warning );
195 
199  void pushInfo( const QString &info );
200 
204  void pushDebugInfo( const QString &message );
205 
209  void pushCommandInfo( const QString &info );
210 
214  void setPercentage( double percent );
215 
219  void setProgressText( const QString &text );
220 
224  void pushConsoleInfo( const QString &info );
225 
230  QDialog *createProgressDialog();
231 
236  void clearLog();
237 
243  void saveLog();
244 
249  void copyLogToClipboard();
250 
254  void showParameters();
255 
256  void reject() override;
257 
258  protected:
259 
260  void closeEvent( QCloseEvent *e ) override;
261 
265  QPushButton *runButton();
266 
270  QPushButton *cancelButton();
271 
275  QPushButton *changeParametersButton();
276 
280  QDialogButtonBox *buttonBox();
281 
285  QTabWidget *tabWidget();
286 
290  void clearProgress();
291 
297  void setExecuted( bool executed );
298 
302  void setExecutedAnyResult( bool executedAnyResult );
303 
309  void setResults( const QVariantMap &results );
310 
314  void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
315 
319  void resetGui();
320 
325  virtual void resetAdditionalGui();
326 
330  void updateRunButtonVisibility();
331 
336  void blockControlsWhileRunning();
337 
342  virtual void blockAdditionalControlsWhileRunning();
343 
347  QgsMessageBar *messageBar();
348 
352  void hideShortHelp();
353 
358  void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
359 
365  static QString formatStringForLog( const QString &string );
366 
367  signals:
368 
374  void algorithmFinished( bool successful, const QVariantMap &result );
375 
376  protected slots:
377 
381  virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
382 
386  virtual void runAlgorithm();
387 
388  private slots:
389 
390  void openHelp();
391  void toggleCollapsed();
392 
393  void splitterChanged( int pos, int index );
394  void mTabWidget_currentChanged( int index );
395  void linkClicked( const QUrl &url );
396  void algExecuted( bool successful, const QVariantMap &results );
397  void taskTriggered( QgsTask *task );
398  void closeClicked();
399 
400  private:
401 
402  QPushButton *mButtonRun = nullptr;
403  QPushButton *mButtonClose = nullptr;
404  QPushButton *mButtonChangeParameters = nullptr;
405  QByteArray mSplitterState;
406  QToolButton *mButtonCollapse = nullptr;
407  QgsMessageBar *mMessageBar = nullptr;
408 
409  bool mExecuted = false;
410  bool mExecutedAnyResult = false;
411  QVariantMap mResults;
412  QgsPanelWidget *mMainWidget = nullptr;
413  std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
414  QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
415 
416  bool mHelpCollapsed = false;
417 
418  int mMessageLoggedCount = 0;
419 
420  QgsProcessingContext::LogLevel mLogLevel = QgsProcessingContext::DefaultLevel;
421 
422  QString formatHelp( QgsProcessingAlgorithm *algorithm );
423  void scrollToBottomOfLog();
424  void processEvents();
425 
426 };
427 
428 #ifndef SIP_RUN
429 
436 class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
437 {
438  Q_OBJECT
439 
440  public:
441 
445  QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
446 
450  QProgressBar *progressBar();
451 
455  QPushButton *cancelButton();
456 
460  QTextEdit *logTextEdit();
461 
462  public slots:
463 
464  void reject() override;
465 
466 };
467 
468 #endif
469 
471 
472 #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