QGIS API Documentation  3.2.0-Bonn (bc43194)
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();
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 = nullptr, Qt::WindowFlags flags = nullptr );
102 
107  void setAlgorithm( QgsProcessingAlgorithm *algorithm );
108 
114 
119  void setMainWidget( QWidget *widget SIP_TRANSFER );
120 
125  QWidget *mainWidget();
126 
130  void showLog();
131 
137  bool wasExecuted() const { return mExecuted; }
138 
144  QVariantMap results() const { return mResults; }
145 
150  QgsProcessingFeedback *createFeedback() SIP_FACTORY;
151 
155  virtual QVariantMap getParameterValues() const;
156 
163  void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
164 
165  public slots:
166 
167  void accept() override;
168 
174  void reportError( const QString &error, bool fatalError );
175 
179  void pushInfo( const QString &info );
180 
184  void pushDebugInfo( const QString &message );
185 
189  void pushCommandInfo( const QString &info );
190 
194  void setPercentage( double percent );
195 
199  void setProgressText( const QString &text );
200 
204  void pushConsoleInfo( const QString &info );
205 
210  QDialog *createProgressDialog();
211 
216  void clearLog();
217 
223  void saveLog();
224 
229  void copyLogToClipboard();
230 
231  protected:
232 
233  void closeEvent( QCloseEvent *e ) override;
234 
238  QPushButton *runButton();
239 
243  QPushButton *cancelButton();
244 
248  QDialogButtonBox *buttonBox();
249 
253  QTabWidget *tabWidget();
254 
258  void clearProgress();
259 
265  void setExecuted( bool executed );
266 
272  void setResults( const QVariantMap &results );
273 
277  void setInfo( const QString &message, bool isError = false, bool escapeHtml = true );
278 
282  void resetGui();
283 
287  QgsMessageBar *messageBar();
288 
292  void hideShortHelp();
293 
298  void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
299 
305  static QString formatStringForLog( const QString &string );
306 
307  protected slots:
308 
312  virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
313 
314  private slots:
315 
316  void openHelp();
317  void toggleCollapsed();
318 
319  void splitterChanged( int pos, int index );
320  void linkClicked( const QUrl &url );
321  void algExecuted( bool successful, const QVariantMap &results );
322  void taskTriggered( QgsTask *task );
323  void closeClicked();
324 
325  private:
326 
327  QPushButton *mButtonRun = nullptr;
328  QPushButton *mButtonClose = nullptr;
329  QByteArray mSplitterState;
330  QToolButton *mButtonCollapse = nullptr;
331  QgsMessageBar *mMessageBar = nullptr;
332 
333  bool mExecuted = false;
334  QVariantMap mResults;
335  QWidget *mMainWidget = nullptr;
336  QgsProcessingAlgorithm *mAlgorithm = nullptr;
337  QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
338 
339  bool mHelpCollapsed = false;
340 
341  QString formatHelp( QgsProcessingAlgorithm *algorithm );
342  void scrollToBottomOfLog();
343  void processEvents();
344 
345 };
346 
347 #ifndef SIP_RUN
348 
355 class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
356 {
357  Q_OBJECT
358 
359  public:
360 
364  QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
365 
369  QProgressBar *progressBar();
370 
374  QPushButton *cancelButton();
375 
379  QTextEdit *logTextEdit();
380 
381  public slots:
382 
383  void reject() override;
384 
385 };
386 
387 #endif
388 
390 
391 #endif // QGSPROCESSINGALGORITHMDIALOGBASE_H
Base class for providing feedback from a processing algorithm.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:45
virtual void setProgressText(const QString &text)
Sets a progress report text string.
Abstract base class for processing algorithms.
Abstract base class for long running background tasks.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#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 pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
QgsTask task which runs a QgsProcessingAlgorithm in a background task.
Contains information about the context in which a processing algorithm is executed.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.