QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
30class QToolButton;
31class QgsProcessingAlgorithmDialogBase;
32class QgsMessageBar;
34class QgsTask;
35
36#ifndef SIP_RUN
37
44class 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
84class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsProcessingParametersGenerator, public QgsProcessingContextGenerator, private Ui::QgsProcessingDialogBase
85{
86 Q_OBJECT
87
88 public:
89
94 enum LogFormat
95 {
96 FormatPlainText,
97 FormatHtml,
98 };
99
105 enum class DialogMode : int
106 {
107 Single,
108 Batch,
109 };
110 Q_ENUM( QgsProcessingAlgorithmDialogBase::DialogMode )
111
112
115 QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), QgsProcessingAlgorithmDialogBase::DialogMode mode = QgsProcessingAlgorithmDialogBase::DialogMode::Single );
116 ~QgsProcessingAlgorithmDialogBase() override;
117
125 void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
126
132
137 void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
138
143 QgsPanelWidget *mainWidget();
144
148 void showLog();
149
155 bool wasExecuted() const { return mExecuted; }
156
162 QVariantMap results() const { return mResults; }
163
168 QgsProcessingFeedback *createFeedback() SIP_FACTORY;
169
176 void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
177
184 QgsProcessingContext::LogLevel logLevel() const;
185
192 void setLogLevel( QgsProcessingContext::LogLevel level );
193
199 virtual void setParameters( const QVariantMap &values );
200
201 public slots:
202
208 void reportError( const QString &error, bool fatalError );
209
213 void pushWarning( const QString &warning );
214
218 void pushInfo( const QString &info );
219
223 void pushDebugInfo( const QString &message );
224
228 void pushCommandInfo( const QString &info );
229
233 void setPercentage( double percent );
234
238 void setProgressText( const QString &text );
239
243 void pushConsoleInfo( const QString &info );
244
249 QDialog *createProgressDialog();
250
255 void clearLog();
256
262 void saveLog();
263
268 void copyLogToClipboard();
269
273 void showParameters();
274
275 void reject() override;
276
277 protected:
278
279 void closeEvent( QCloseEvent *e ) override;
280
284 QPushButton *runButton();
285
289 QPushButton *cancelButton();
290
294 QPushButton *changeParametersButton();
295
299 QDialogButtonBox *buttonBox();
300
304 QTabWidget *tabWidget();
305
309 void clearProgress();
310
316 void setExecuted( bool executed );
317
321 void setExecutedAnyResult( bool executedAnyResult );
322
328 void setResults( const QVariantMap &results );
329
333 void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
334
338 void resetGui();
339
344 virtual void resetAdditionalGui();
345
349 void updateRunButtonVisibility();
350
355 void blockControlsWhileRunning();
356
361 virtual void blockAdditionalControlsWhileRunning();
362
366 QgsMessageBar *messageBar();
367
371 void hideShortHelp();
372
377 void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
378
384 static QString formatStringForLog( const QString &string );
385
391 virtual bool isFinalized();
392
393 signals:
394
400 void algorithmFinished( bool successful, const QVariantMap &result );
401
402 protected slots:
403
407 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
408
412 virtual void runAlgorithm();
413
419 virtual void algExecuted( bool successful, const QVariantMap &results );
420
421 private slots:
422
423 void openHelp();
424 void toggleCollapsed();
425
426 void splitterChanged( int pos, int index );
427 void mTabWidget_currentChanged( int index );
428 void linkClicked( const QUrl &url );
429 void taskTriggered( QgsTask *task );
430 void closeClicked();
431
432 private:
433
434 DialogMode mMode = DialogMode::Single;
435
436 QPushButton *mButtonRun = nullptr;
437 QPushButton *mButtonClose = nullptr;
438 QPushButton *mButtonChangeParameters = nullptr;
439 QByteArray mSplitterState;
440 QToolButton *mButtonCollapse = nullptr;
441 QgsMessageBar *mMessageBar = nullptr;
442 QPushButton *mAdvancedButton = nullptr;
443 QMenu *mAdvancedMenu = nullptr;
444 QAction *mCopyAsQgisProcessCommand = nullptr;
445 QAction *mPasteJsonAction = nullptr;
446
447 bool mExecuted = false;
448 bool mExecutedAnyResult = false;
449 QVariantMap mResults;
450 QgsPanelWidget *mMainWidget = nullptr;
451 std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
452 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
453
454 bool mHelpCollapsed = false;
455
456 int mMessageLoggedCount = 0;
457
458 QgsProcessingContext::LogLevel mLogLevel = QgsProcessingContext::DefaultLevel;
459
460 QString formatHelp( QgsProcessingAlgorithm *algorithm );
461 void scrollToBottomOfLog();
462 void processEvents();
463
464};
465
466#ifndef SIP_RUN
467
474class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
475{
476 Q_OBJECT
477
478 public:
479
483 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
484
488 QProgressBar *progressBar();
489
493 QPushButton *cancelButton();
494
498 QTextEdit *logTextEdit();
499
500 public slots:
501
502 void reject() override;
503
504};
505
506#endif
507
509
510#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.
An interface for objects which can create Processing contexts.
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:74
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