QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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"
25 
27 
29 class QToolButton;
30 class QgsProcessingAlgorithmDialogBase;
31 class QgsMessageBar;
33 class QgsTask;
34 
35 #ifndef SIP_RUN
36 
43 class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
44 {
45  Q_OBJECT
46 
47  public:
48 
52  QgsProcessingAlgorithmDialogFeedback() = default;
53 
54  signals:
55 
56  void progressTextChanged( const QString &text );
57  void errorReported( const QString &text, bool fatalError );
58  void infoPushed( const QString &text );
59  void commandInfoPushed( const QString &text );
60  void debugInfoPushed( const QString &text );
61  void consoleInfoPushed( const QString &text );
62 
63  public slots:
64 
65  void setProgressText( const QString &text ) override;
66  void reportError( const QString &error, bool fatalError ) override;
67  void pushInfo( const QString &info ) override;
68  void pushCommandInfo( const QString &info ) override;
69  void pushDebugInfo( const QString &info ) override;
70  void pushConsoleInfo( const QString &info ) override;
71 
72 
73 };
74 #endif
75 
82 class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, private Ui::QgsProcessingDialogBase
83 {
84  Q_OBJECT
85 
86  public:
87 
92  enum LogFormat
93  {
94  FormatPlainText,
95  FormatHtml,
96  };
97 
101  QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = nullptr );
102  ~QgsProcessingAlgorithmDialogBase() override;
103 
111  void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
112 
118 
123  void setMainWidget( QWidget *widget SIP_TRANSFER );
124 
129  QWidget *mainWidget();
130 
134  void showLog();
135 
141  bool wasExecuted() const { return mExecuted; }
142 
148  QVariantMap results() const { return mResults; }
149 
154  QgsProcessingFeedback *createFeedback() SIP_FACTORY;
155 
159  virtual QVariantMap getParameterValues() const;
160 
167  void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
168 
169  public slots:
170 
176  void reportError( const QString &error, bool fatalError );
177 
181  void pushInfo( const QString &info );
182 
186  void pushDebugInfo( const QString &message );
187 
191  void pushCommandInfo( const QString &info );
192 
196  void setPercentage( double percent );
197 
201  void setProgressText( const QString &text );
202 
206  void pushConsoleInfo( const QString &info );
207 
212  QDialog *createProgressDialog();
213 
218  void clearLog();
219 
225  void saveLog();
226 
231  void copyLogToClipboard();
232 
233  protected:
234 
235  void closeEvent( QCloseEvent *e ) override;
236 
240  QPushButton *runButton();
241 
245  QPushButton *cancelButton();
246 
250  QDialogButtonBox *buttonBox();
251 
255  QTabWidget *tabWidget();
256 
260  void clearProgress();
261 
267  void setExecuted( bool executed );
268 
274  void setResults( const QVariantMap &results );
275 
279  void setInfo( const QString &message, bool isError = false, bool escapeHtml = true );
280 
284  void resetGui();
285 
289  QgsMessageBar *messageBar();
290 
294  void hideShortHelp();
295 
300  void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
301 
307  static QString formatStringForLog( const QString &string );
308 
309  protected slots:
310 
314  virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
315 
319  virtual void runAlgorithm();
320 
321  private slots:
322 
323  void openHelp();
324  void toggleCollapsed();
325 
326  void splitterChanged( int pos, int index );
327  void linkClicked( const QUrl &url );
328  void algExecuted( bool successful, const QVariantMap &results );
329  void taskTriggered( QgsTask *task );
330  void closeClicked();
331 
332  private:
333 
334  QPushButton *mButtonRun = nullptr;
335  QPushButton *mButtonClose = nullptr;
336  QByteArray mSplitterState;
337  QToolButton *mButtonCollapse = nullptr;
338  QgsMessageBar *mMessageBar = nullptr;
339 
340  bool mExecuted = false;
341  QVariantMap mResults;
342  QWidget *mMainWidget = nullptr;
343  std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
344  QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
345 
346  bool mHelpCollapsed = false;
347 
348  QString formatHelp( QgsProcessingAlgorithm *algorithm );
349  void scrollToBottomOfLog();
350  void processEvents();
351 
352 };
353 
354 #ifndef SIP_RUN
355 
362 class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
363 {
364  Q_OBJECT
365 
366  public:
367 
371  QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
372 
376  QProgressBar *progressBar();
377 
381  QPushButton *cancelButton();
382 
386  QTextEdit *logTextEdit();
387 
388  public slots:
389 
390  void reject() override;
391 
392 };
393 
394 #endif
395 
397 
398 #endif // QGSPROCESSINGALGORITHMDIALOGBASE_H
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
Base class for providing feedback from a processing algorithm.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
Abstract base class for processing algorithms.
virtual void setProgressText(const QString &text)
Sets a progress report text string.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
Abstract base class for long running background tasks.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
#define SIP_FACTORY
Definition: qgis_sip.h:69
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
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
QgsTask task which runs a QgsProcessingAlgorithm in a background task.
Contains information about the context in which a processing algorithm is executed.