QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
47class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
48{
49 Q_OBJECT
50
51 public:
52
56 QgsProcessingAlgorithmDialogFeedback();
57
58 signals:
59
60 void progressTextChanged( const QString &text );
61 void errorReported( const QString &text, bool fatalError );
62 void warningPushed( const QString &text );
63 void infoPushed( const QString &text );
64 void commandInfoPushed( const QString &text );
65 void debugInfoPushed( const QString &text );
66 void consoleInfoPushed( const QString &text );
67 void formattedMessagePushed( const QString &html );
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 void pushFormattedMessage( const QString &html, const QString &text ) override;
79
80};
81#endif
82
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 Qgis::ProcessingLogLevel logLevel() const;
189
196 void setLogLevel( Qgis::ProcessingLogLevel 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
231 void pushFormattedMessage( const QString &html );
232
236 void pushDebugInfo( const QString &message );
237
241 void pushCommandInfo( const QString &info );
242
246 void setPercentage( double percent );
247
251 void setProgressText( const QString &text );
252
256 void pushConsoleInfo( const QString &info );
257
262 QDialog *createProgressDialog();
263
268 void clearLog();
269
275 void saveLog();
276
281 void copyLogToClipboard();
282
286 void showParameters();
287
288 void reject() override;
289
290 protected:
291
292 void closeEvent( QCloseEvent *e ) override;
293
297 QPushButton *runButton();
298
302 QPushButton *cancelButton();
303
307 QPushButton *changeParametersButton();
308
312 QDialogButtonBox *buttonBox();
313
317 QTabWidget *tabWidget();
318
322 void clearProgress();
323
329 void setExecuted( bool executed );
330
334 void setExecutedAnyResult( bool executedAnyResult );
335
341 void setResults( const QVariantMap &results );
342
346 void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
347
351 void resetGui();
352
357 virtual void resetAdditionalGui();
358
362 void updateRunButtonVisibility();
363
368 void blockControlsWhileRunning();
369
374 virtual void blockAdditionalControlsWhileRunning();
375
379 QgsMessageBar *messageBar();
380
384 void hideShortHelp();
385
390 void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
391
396 static QString formatStringForLog( const QString &string );
397
403 virtual bool isFinalized();
404
412 void applyContextOverrides( QgsProcessingContext *context );
413
414 signals:
415
421 void algorithmFinished( bool successful, const QVariantMap &result );
422
423 protected slots:
424
428 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
429
433 virtual void runAlgorithm();
434
440 virtual void algExecuted( bool successful, const QVariantMap &results );
441
442 private slots:
443
444 void openHelp();
445 void toggleCollapsed();
446
447 void splitterChanged( int pos, int index );
448 void mTabWidget_currentChanged( int index );
449 void linkClicked( const QUrl &url );
450 void taskTriggered( QgsTask *task );
451 void closeClicked();
452 void urlClicked( const QUrl &url );
453
454 private:
455
456 DialogMode mMode = DialogMode::Single;
457
458 QPushButton *mButtonRun = nullptr;
459 QPushButton *mButtonClose = nullptr;
460 QPushButton *mButtonChangeParameters = nullptr;
461 QByteArray mSplitterState;
462 QToolButton *mButtonCollapse = nullptr;
463 QgsMessageBar *mMessageBar = nullptr;
464 QPushButton *mAdvancedButton = nullptr;
465 QMenu *mAdvancedMenu = nullptr;
466 QAction *mCopyAsQgisProcessCommand = nullptr;
467 QAction *mPasteJsonAction = nullptr;
468 QAction *mContextSettingsAction = nullptr;
469
470 bool mExecuted = false;
471 bool mExecutedAnyResult = false;
472 QVariantMap mResults;
473 QgsPanelWidget *mMainWidget = nullptr;
474 std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
475 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
476
477 bool mHelpCollapsed = false;
478
479 int mMessageLoggedCount = 0;
480
481 Qgis::ProcessingLogLevel mLogLevel = Qgis::ProcessingLogLevel::DefaultLevel;
482
483 QPointer< QgsProcessingContextOptionsWidget > mContextOptionsWidget;
484 bool mOverrideDefaultContextSettings = false;
485 Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
486 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
487 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
488 QString mTemporaryFolderOverride;
489 int mMaximumThreads = QThread::idealThreadCount();
490
491 QString formatHelp( QgsProcessingAlgorithm *algorithm );
492 void scrollToBottomOfLog();
493 void processEvents();
494
495};
496
497#ifndef SIP_RUN
498
504class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
505{
506 Q_OBJECT
507
508 public:
509
513 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
514
518 QProgressBar *progressBar();
519
523 QPushButton *cancelButton();
524
528 QTextEdit *logTextEdit();
529
530 public slots:
531
532 void reject() override;
533
534};
535
542class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, private Ui::QgsProcessingContextOptionsBase
543{
544 Q_OBJECT
545
546 public:
547
551 QgsProcessingContextOptionsWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
552
556 void setFromContext( const QgsProcessingContext *context );
557
561 Qgis::InvalidGeometryCheck invalidGeometryCheck() const;
562
566 Qgis::DistanceUnit distanceUnit() const;
567
571 Qgis::AreaUnit areaUnit() const;
572
576 QString temporaryFolder();
577
581 int maximumThreads() const;
582
588 void setLogLevel( Qgis::ProcessingLogLevel level );
589
595 Qgis::ProcessingLogLevel logLevel() const;
596};
597
598#endif
599
601
602#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:4124
AreaUnit
Units of area.
Definition: qgis.h:4162
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition: qgis.h:1778
ProcessingLogLevel
Logging level for algorithms to use when pushing feedback messages.
Definition: qgis.h:2960
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 pushFormattedMessage(const QString &html, const QString &text)
Pushes a pre-formatted message 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:73
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