QGIS API Documentation  3.0.2-Girona (307d082)
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 
91  QgsProcessingAlgorithmDialogBase( QWidget *parent = nullptr, Qt::WindowFlags flags = nullptr );
92 
97  void setAlgorithm( QgsProcessingAlgorithm *algorithm );
98 
103  QgsProcessingAlgorithm *algorithm();
104 
109  void setMainWidget( QWidget *widget SIP_TRANSFER );
110 
115  QWidget *mainWidget();
116 
120  void showLog();
121 
127  bool wasExecuted() const { return mExecuted; }
128 
134  QVariantMap results() const { return mResults; }
135 
140  QgsProcessingFeedback *createFeedback() SIP_FACTORY;
141 
145  virtual QVariantMap getParameterValues() const;
146 
147  public slots:
148 
149  void accept() override;
150 
156  void reportError( const QString &error, bool fatalError );
157 
161  void pushInfo( const QString &info );
162 
166  void pushDebugInfo( const QString &message );
167 
171  void pushCommandInfo( const QString &info );
172 
176  void setPercentage( double percent );
177 
181  void setProgressText( const QString &text );
182 
186  void pushConsoleInfo( const QString &info );
187 
192  QDialog *createProgressDialog();
193 
194  protected:
195 
196  void closeEvent( QCloseEvent *e ) override;
197 
201  QPushButton *runButton();
202 
206  QPushButton *cancelButton();
207 
211  QDialogButtonBox *buttonBox();
212 
216  QTabWidget *tabWidget();
217 
221  void clearProgress();
222 
228  void setExecuted( bool executed );
229 
235  void setResults( const QVariantMap &results );
236 
240  void setInfo( const QString &message, bool isError = false, bool escapeHtml = true );
241 
245  void resetGui();
246 
250  QgsMessageBar *messageBar();
251 
255  void hideShortHelp();
256 
261  void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
262 
268  static QString formatStringForLog( const QString &string );
269 
270  protected slots:
271 
275  virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
276 
277  private slots:
278 
279  void openHelp();
280  void toggleCollapsed();
281 
282  void splitterChanged( int pos, int index );
283  void linkClicked( const QUrl &url );
284  void algExecuted( bool successful, const QVariantMap &results );
285  void taskTriggered( QgsTask *task );
286  void closeClicked();
287 
288  private:
289 
290  QPushButton *mButtonRun = nullptr;
291  QPushButton *mButtonClose = nullptr;
292  QByteArray mSplitterState;
293  QToolButton *mButtonCollapse = nullptr;
294  QgsMessageBar *mMessageBar = nullptr;
295 
296  bool mExecuted = false;
297  QVariantMap mResults;
298  QWidget *mMainWidget = nullptr;
299  QgsProcessingAlgorithm *mAlgorithm = nullptr;
300  QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
301 
302  bool mHelpCollapsed = false;
303 
304  QString formatHelp( QgsProcessingAlgorithm *algorithm );
305  void scrollToBottomOfLog();
306  void processEvents();
307 
308 };
309 
310 #ifndef SIP_RUN
311 
318 class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
319 {
320  Q_OBJECT
321 
322  public:
323 
327  QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
328 
332  QProgressBar *progressBar();
333 
337  QPushButton *cancelButton();
338 
342  QTextEdit *logTextEdit();
343 
344  public slots:
345 
346  void reject() override;
347 
348 };
349 
350 #endif
351 
353 
354 #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
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.