QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
47class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
48{
49 Q_OBJECT
50
51 public:
55 QgsProcessingAlgorithmDialogFeedback();
56
57 signals:
58
59 void progressTextChanged( const QString &text );
60 void errorReported( const QString &text, bool fatalError );
61 void warningPushed( const QString &text );
62 void infoPushed( const QString &text );
63 void commandInfoPushed( const QString &text );
64 void debugInfoPushed( const QString &text );
65 void consoleInfoPushed( const QString &text );
66 void formattedMessagePushed( const QString &html );
67
68 public slots:
69
70 void setProgressText( const QString &text ) override;
71 void reportError( const QString &error, bool fatalError ) override;
72 void pushWarning( const QString &info ) override;
73 void pushInfo( const QString &info ) override;
74 void pushCommandInfo( const QString &info ) override;
75 void pushDebugInfo( const QString &info ) override;
76 void pushConsoleInfo( const QString &info ) override;
77 void pushFormattedMessage( const QString &html, const QString &text ) override;
78};
79#endif
80
86class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsProcessingParametersGenerator, public QgsProcessingContextGenerator, private Ui::QgsProcessingDialogBase
87{
88 Q_OBJECT
89
90 public:
95 enum LogFormat
96 {
97 FormatPlainText,
98 FormatHtml,
99 };
100
106 enum class DialogMode : int
107 {
108 Single,
109 Batch,
110 };
111 Q_ENUM( QgsProcessingAlgorithmDialogBase::DialogMode )
112
113
116 QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), QgsProcessingAlgorithmDialogBase::DialogMode mode = QgsProcessingAlgorithmDialogBase::DialogMode::Single );
117 ~QgsProcessingAlgorithmDialogBase() override;
118
126 void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
127
133
138 void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
139
144 QgsPanelWidget *mainWidget();
145
149 void showLog();
150
156 bool wasExecuted() const { return mExecuted; }
157
163 QVariantMap results() const { return mResults; }
164
169 QgsProcessingFeedback *createFeedback() SIP_FACTORY;
170
177 void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
178
185 Qgis::ProcessingLogLevel logLevel() const;
186
193 void setLogLevel( Qgis::ProcessingLogLevel level );
194
200 virtual void setParameters( const QVariantMap &values );
201
202 public slots:
203
209 void reportError( const QString &error, bool fatalError );
210
214 void pushWarning( const QString &warning );
215
219 void pushInfo( const QString &info );
220
228 void pushFormattedMessage( const QString &html );
229
233 void pushDebugInfo( const QString &message );
234
238 void pushCommandInfo( const QString &info );
239
243 void setPercentage( double percent );
244
248 void setProgressText( const QString &text );
249
253 void pushConsoleInfo( const QString &info );
254
259 QDialog *createProgressDialog();
260
265 void clearLog();
266
272 void saveLog();
273
278 void copyLogToClipboard();
279
283 void showParameters();
284
285 void reject() override;
286
287 protected:
288 void closeEvent( QCloseEvent *e ) override;
289
293 QPushButton *runButton();
294
298 QPushButton *cancelButton();
299
303 QPushButton *changeParametersButton();
304
308 QDialogButtonBox *buttonBox();
309
313 QTabWidget *tabWidget();
314
318 void clearProgress();
319
325 void setExecuted( bool executed );
326
330 void setExecutedAnyResult( bool executedAnyResult );
331
337 void setResults( const QVariantMap &results );
338
342 void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
343
347 void resetGui();
348
353 virtual void resetAdditionalGui();
354
358 void updateRunButtonVisibility();
359
364 void blockControlsWhileRunning();
365
370 virtual void blockAdditionalControlsWhileRunning();
371
375 QgsMessageBar *messageBar();
376
380 void hideShortHelp();
381
386 void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
387
392 static QString formatStringForLog( const QString &string );
393
399 virtual bool isFinalized();
400
408 void applyContextOverrides( QgsProcessingContext *context );
409
410 signals:
411
419 void algorithmAboutToRun( QgsProcessingContext *context );
420
426 void algorithmFinished( bool successful, const QVariantMap &result );
427
428 protected slots:
429
433 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
434
438 virtual void runAlgorithm();
439
445 virtual void algExecuted( bool successful, const QVariantMap &results );
446
447 private slots:
448
449 void openHelp();
450 void toggleCollapsed();
451
452 void splitterChanged( int pos, int index );
453 void mTabWidget_currentChanged( int index );
454 void linkClicked( const QUrl &url );
455 void taskTriggered( QgsTask *task );
456 void closeClicked();
457 void urlClicked( const QUrl &url );
458
459 private:
460 DialogMode mMode = DialogMode::Single;
461
462 QPushButton *mButtonRun = nullptr;
463 QPushButton *mButtonClose = nullptr;
464 QPushButton *mButtonChangeParameters = nullptr;
465 QByteArray mSplitterState;
466 QToolButton *mButtonCollapse = nullptr;
467 QgsMessageBar *mMessageBar = nullptr;
468 QPushButton *mAdvancedButton = nullptr;
469 QMenu *mAdvancedMenu = nullptr;
470 QAction *mCopyAsQgisProcessCommand = nullptr;
471 QAction *mPasteJsonAction = nullptr;
472 QAction *mContextSettingsAction = nullptr;
473
474 bool mExecuted = false;
475 bool mExecutedAnyResult = false;
476 QVariantMap mResults;
477 QgsPanelWidget *mMainWidget = nullptr;
478 std::unique_ptr<QgsProcessingAlgorithm> mAlgorithm;
479 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
480
481 bool mHelpCollapsed = false;
482
483 int mMessageLoggedCount = 0;
484
485 Qgis::ProcessingLogLevel mLogLevel = Qgis::ProcessingLogLevel::DefaultLevel;
486
487 QPointer<QgsProcessingContextOptionsWidget> mContextOptionsWidget;
488 bool mOverrideDefaultContextSettings = false;
489 Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
490 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
491 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
492 QString mTemporaryFolderOverride;
493 int mMaximumThreads = QThread::idealThreadCount();
494
495 QString formatHelp( QgsProcessingAlgorithm *algorithm );
496 void scrollToBottomOfLog();
497 void processEvents();
498};
499
500#ifndef SIP_RUN
501
507class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
508{
509 Q_OBJECT
510
511 public:
515 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
516
520 QProgressBar *progressBar();
521
525 QPushButton *cancelButton();
526
530 QTextEdit *logTextEdit();
531
532 public slots:
533
534 void reject() override;
535};
536
543class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, private Ui::QgsProcessingContextOptionsBase
544{
545 Q_OBJECT
546
547 public:
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:4722
AreaUnit
Units of area.
Definition qgis.h:4799
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2117
ProcessingLogLevel
Logging level for algorithms to use when pushing feedback messages.
Definition qgis.h:3438
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.
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.
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