QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 infoPushed( const QString &text );
60  void commandInfoPushed( const QString &text );
61  void debugInfoPushed( const QString &text );
62  void consoleInfoPushed( const QString &text );
63 
64  public slots:
65 
66  void setProgressText( const QString &text ) override;
67  void reportError( const QString &error, bool fatalError ) override;
68  void pushInfo( const QString &info ) override;
69  void pushCommandInfo( const QString &info ) override;
70  void pushDebugInfo( const QString &info ) override;
71  void pushConsoleInfo( const QString &info ) override;
72 
73 };
74 #endif
75 
82 class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsProcessingParametersGenerator, 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 = Qt::WindowFlags() );
102  ~QgsProcessingAlgorithmDialogBase() override;
103 
111  void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
112 
118 
123  void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
124 
129  QgsPanelWidget *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 
162  void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
163 
164  public slots:
165 
171  void reportError( const QString &error, bool fatalError );
172 
176  void pushInfo( const QString &info );
177 
181  void pushDebugInfo( const QString &message );
182 
186  void pushCommandInfo( const QString &info );
187 
191  void setPercentage( double percent );
192 
196  void setProgressText( const QString &text );
197 
201  void pushConsoleInfo( const QString &info );
202 
207  QDialog *createProgressDialog();
208 
213  void clearLog();
214 
220  void saveLog();
221 
226  void copyLogToClipboard();
227 
231  void showParameters();
232 
233  void reject() override;
234 
235  protected:
236 
237  void closeEvent( QCloseEvent *e ) override;
238 
242  QPushButton *runButton();
243 
247  QPushButton *cancelButton();
248 
252  QPushButton *changeParametersButton();
253 
257  QDialogButtonBox *buttonBox();
258 
262  QTabWidget *tabWidget();
263 
267  void clearProgress();
268 
274  void setExecuted( bool executed );
275 
279  void setExecutedAnyResult( bool executedAnyResult );
280 
286  void setResults( const QVariantMap &results );
287 
291  void setInfo( const QString &message, bool isError = false, bool escapeHtml = true );
292 
296  void resetGui();
297 
302  virtual void resetAdditionalGui();
303 
307  void updateRunButtonVisibility();
308 
313  void blockControlsWhileRunning();
314 
319  virtual void blockAdditionalControlsWhileRunning();
320 
324  QgsMessageBar *messageBar();
325 
329  void hideShortHelp();
330 
335  void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
336 
342  static QString formatStringForLog( const QString &string );
343 
344  signals:
345 
351  void algorithmFinished( bool successful, const QVariantMap &result );
352 
353  protected slots:
354 
358  virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
359 
363  virtual void runAlgorithm();
364 
365  private slots:
366 
367  void openHelp();
368  void toggleCollapsed();
369 
370  void splitterChanged( int pos, int index );
371  void mTabWidget_currentChanged( int index );
372  void linkClicked( const QUrl &url );
373  void algExecuted( bool successful, const QVariantMap &results );
374  void taskTriggered( QgsTask *task );
375  void closeClicked();
376 
377  private:
378 
379  QPushButton *mButtonRun = nullptr;
380  QPushButton *mButtonClose = nullptr;
381  QPushButton *mButtonChangeParameters = nullptr;
382  QByteArray mSplitterState;
383  QToolButton *mButtonCollapse = nullptr;
384  QgsMessageBar *mMessageBar = nullptr;
385 
386  bool mExecuted = false;
387  bool mExecutedAnyResult = false;
388  QVariantMap mResults;
389  QgsPanelWidget *mMainWidget = nullptr;
390  std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
391  QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
392 
393  bool mHelpCollapsed = false;
394 
395  QString formatHelp( QgsProcessingAlgorithm *algorithm );
396  void scrollToBottomOfLog();
397  void processEvents();
398 
399 };
400 
401 #ifndef SIP_RUN
402 
409 class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
410 {
411  Q_OBJECT
412 
413  public:
414 
418  QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
419 
423  QProgressBar *progressBar();
424 
428  QPushButton *cancelButton();
429 
433  QTextEdit *logTextEdit();
434 
435  public slots:
436 
437  void reject() override;
438 
439 };
440 
441 #endif
442 
444 
445 #endif // QGSPROCESSINGALGORITHMDIALOGBASE_H
QgsProcessingAlgRunnerTask
Definition: qgsprocessingalgrunnertask.h:35
QgsProcessingFeedback::setProgressText
virtual void setProgressText(const QString &text)
Sets a progress report text string.
Definition: qgsprocessingfeedback.cpp:35
QgsProcessingFeedback::pushCommandInfo
virtual void pushCommandInfo(const QString &info)
Pushes an informational message containing a command from the algorithm.
Definition: qgsprocessingfeedback.cpp:57
QgsProcessingFeedback
Definition: qgsprocessingfeedback.h:37
algorithm
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
QgsProcessingFeedback::pushInfo
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
Definition: qgsprocessingfeedback.cpp:48
QgsProcessingFeedback::reportError
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Definition: qgsprocessingfeedback.cpp:39
qgis.h
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsProcessingFeedback::pushConsoleInfo
virtual void pushConsoleInfo(const QString &info)
Pushes a console feedback message from the algorithm.
Definition: qgsprocessingfeedback.cpp:75
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsPanelWidget
Base class for any widget that can be shown as a inline panel.
Definition: qgspanelwidget.h:29
QgsProcessingContext
Definition: qgsprocessingcontext.h:43
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
qgsprocessingwidgetwrapper.h
QgsMessageBar
Definition: qgsmessagebar.h:60
qgsprocessingfeedback.h
QgsProcessingParametersGenerator
Definition: qgsprocessingwidgetwrapper.h:76
QgsProcessingFeedback::pushDebugInfo
virtual void pushDebugInfo(const QString &info)
Pushes an informational message containing debugging helpers from the algorithm.
Definition: qgsprocessingfeedback.cpp:66
QgsProcessingAlgorithm
Definition: qgsprocessingalgorithm.h:51
qgsprocessingcontext.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsTask
Abstract base class for long running background tasks. Tasks can be controlled directly,...
Definition: qgstaskmanager.h:52