QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
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"
23#include "ui_qgsprocessingcontextoptionsbase.h"
27
28#include <QThread>
29
31
33class QToolButton;
34class QgsProcessingAlgorithmDialogBase;
35class QgsProcessingContextOptionsWidget;
36class QgsMessageBar;
38class QgsTask;
39
40#ifndef SIP_RUN
41
48class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
49{
50 Q_OBJECT
51
52 public:
53
57 QgsProcessingAlgorithmDialogFeedback();
58
59 signals:
60
61 void progressTextChanged( const QString &text );
62 void errorReported( const QString &text, bool fatalError );
63 void warningPushed( const QString &text );
64 void infoPushed( const QString &text );
65 void commandInfoPushed( const QString &text );
66 void debugInfoPushed( const QString &text );
67 void consoleInfoPushed( const QString &text );
68
69 public slots:
70
71 void setProgressText( const QString &text ) override;
72 void reportError( const QString &error, bool fatalError ) override;
73 void pushWarning( const QString &info ) override;
74 void pushInfo( const QString &info ) override;
75 void pushCommandInfo( const QString &info ) override;
76 void pushDebugInfo( const QString &info ) override;
77 void pushConsoleInfo( const QString &info ) override;
78
79};
80#endif
81
88class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsProcessingParametersGenerator, public QgsProcessingContextGenerator, private Ui::QgsProcessingDialogBase
89{
90 Q_OBJECT
91
92 public:
93
98 enum LogFormat
99 {
100 FormatPlainText,
101 FormatHtml,
102 };
103
109 enum class DialogMode : int
110 {
111 Single,
112 Batch,
113 };
114 Q_ENUM( QgsProcessingAlgorithmDialogBase::DialogMode )
115
116
119 QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), QgsProcessingAlgorithmDialogBase::DialogMode mode = QgsProcessingAlgorithmDialogBase::DialogMode::Single );
120 ~QgsProcessingAlgorithmDialogBase() override;
121
129 void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
130
136
141 void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
142
147 QgsPanelWidget *mainWidget();
148
152 void showLog();
153
159 bool wasExecuted() const { return mExecuted; }
160
166 QVariantMap results() const { return mResults; }
167
172 QgsProcessingFeedback *createFeedback() SIP_FACTORY;
173
180 void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
181
188 QgsProcessingContext::LogLevel logLevel() const;
189
196 void setLogLevel( QgsProcessingContext::LogLevel level );
197
203 virtual void setParameters( const QVariantMap &values );
204
205 public slots:
206
212 void reportError( const QString &error, bool fatalError );
213
217 void pushWarning( const QString &warning );
218
222 void pushInfo( const QString &info );
223
227 void pushDebugInfo( const QString &message );
228
232 void pushCommandInfo( const QString &info );
233
237 void setPercentage( double percent );
238
242 void setProgressText( const QString &text );
243
247 void pushConsoleInfo( const QString &info );
248
253 QDialog *createProgressDialog();
254
259 void clearLog();
260
266 void saveLog();
267
272 void copyLogToClipboard();
273
277 void showParameters();
278
279 void reject() override;
280
281 protected:
282
283 void closeEvent( QCloseEvent *e ) override;
284
288 QPushButton *runButton();
289
293 QPushButton *cancelButton();
294
298 QPushButton *changeParametersButton();
299
303 QDialogButtonBox *buttonBox();
304
308 QTabWidget *tabWidget();
309
313 void clearProgress();
314
320 void setExecuted( bool executed );
321
325 void setExecutedAnyResult( bool executedAnyResult );
326
332 void setResults( const QVariantMap &results );
333
337 void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
338
342 void resetGui();
343
348 virtual void resetAdditionalGui();
349
353 void updateRunButtonVisibility();
354
359 void blockControlsWhileRunning();
360
365 virtual void blockAdditionalControlsWhileRunning();
366
370 QgsMessageBar *messageBar();
371
375 void hideShortHelp();
376
381 void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
382
388 static QString formatStringForLog( const QString &string );
389
395 virtual bool isFinalized();
396
404 void applyContextOverrides( QgsProcessingContext *context );
405
406 signals:
407
413 void algorithmFinished( bool successful, const QVariantMap &result );
414
415 protected slots:
416
420 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
421
425 virtual void runAlgorithm();
426
432 virtual void algExecuted( bool successful, const QVariantMap &results );
433
434 private slots:
435
436 void openHelp();
437 void toggleCollapsed();
438
439 void splitterChanged( int pos, int index );
440 void mTabWidget_currentChanged( int index );
441 void linkClicked( const QUrl &url );
442 void taskTriggered( QgsTask *task );
443 void closeClicked();
444
445 private:
446
447 DialogMode mMode = DialogMode::Single;
448
449 QPushButton *mButtonRun = nullptr;
450 QPushButton *mButtonClose = nullptr;
451 QPushButton *mButtonChangeParameters = nullptr;
452 QByteArray mSplitterState;
453 QToolButton *mButtonCollapse = nullptr;
454 QgsMessageBar *mMessageBar = nullptr;
455 QPushButton *mAdvancedButton = nullptr;
456 QMenu *mAdvancedMenu = nullptr;
457 QAction *mCopyAsQgisProcessCommand = nullptr;
458 QAction *mPasteJsonAction = nullptr;
459 QAction *mContextSettingsAction = nullptr;
460
461 bool mExecuted = false;
462 bool mExecutedAnyResult = false;
463 QVariantMap mResults;
464 QgsPanelWidget *mMainWidget = nullptr;
465 std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
466 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
467
468 bool mHelpCollapsed = false;
469
470 int mMessageLoggedCount = 0;
471
472 QgsProcessingContext::LogLevel mLogLevel = QgsProcessingContext::DefaultLevel;
473
474 QPointer< QgsProcessingContextOptionsWidget > mContextOptionsWidget;
475 bool mOverrideDefaultContextSettings = false;
476 QgsFeatureRequest::InvalidGeometryCheck mGeometryCheck = QgsFeatureRequest::InvalidGeometryCheck::GeometryAbortOnInvalid;
477 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
478 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
479 QString mTemporaryFolderOverride;
480 int mMaximumThreads = QThread::idealThreadCount();
481
482 QString formatHelp( QgsProcessingAlgorithm *algorithm );
483 void scrollToBottomOfLog();
484 void processEvents();
485
486};
487
488#ifndef SIP_RUN
489
496class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
497{
498 Q_OBJECT
499
500 public:
501
505 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
506
510 QProgressBar *progressBar();
511
515 QPushButton *cancelButton();
516
520 QTextEdit *logTextEdit();
521
522 public slots:
523
524 void reject() override;
525
526};
527
534class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, private Ui::QgsProcessingContextOptionsBase
535{
536 Q_OBJECT
537
538 public:
539
543 QgsProcessingContextOptionsWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
544
548 void setFromContext( const QgsProcessingContext *context );
549
553 QgsFeatureRequest::InvalidGeometryCheck invalidGeometryCheck() const;
554
558 Qgis::DistanceUnit distanceUnit() const;
559
563 Qgis::AreaUnit areaUnit() const;
564
568 QString temporaryFolder();
569
573 int maximumThreads() const;
574
580 void setLogLevel( QgsProcessingContext::LogLevel level );
581
587 QgsProcessingContext::LogLevel logLevel() const;
588};
589
590#endif
591
593
594#endif // QGSPROCESSINGALGORITHMDIALOGBASE_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
DistanceUnit
Units of distance.
Definition qgis.h:3496
AreaUnit
Units of area.
Definition qgis.h:3534
This class wraps a request for features to a vector layer (or directly its vector data provider).
InvalidGeometryCheck
Handling of features with invalid geometries.
A bar for displaying non-blocking messages to the user.
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.
LogLevel
Logging level for algorithms to use when pushing feedback messages.
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.
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