QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "ui_qgsprocessingalgorithmdialogbase.h"
20#include "ui_qgsprocessingalgorithmprogressdialogbase.h"
21#include "ui_qgsprocessingcontextoptionsbase.h"
22
23#include "qgis.h"
24#include "qgis_gui.h"
28
29#include <QThread>
30
32
34class QToolButton;
35class QgsProcessingAlgorithmDialogBase;
36class QgsProcessingContextOptionsWidget;
37class QgsMessageBar;
39class QgsTask;
40
41#ifndef SIP_RUN
42
48class QgsProcessingAlgorithmDialogFeedback : public QgsProcessingFeedback
49{
50 Q_OBJECT
51
52 public:
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#endif
81
87class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsProcessingParametersGenerator, public QgsProcessingContextGenerator, private Ui::QgsProcessingDialogBase
88{
89 Q_OBJECT
90
91 public:
96 enum LogFormat
97 {
98 FormatPlainText,
99 FormatHtml,
100 };
101
107 enum class DialogMode : int
108 {
109 Single,
110 Batch,
111 };
112 Q_ENUM( QgsProcessingAlgorithmDialogBase::DialogMode )
113
114
117 QgsProcessingAlgorithmDialogBase( QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), QgsProcessingAlgorithmDialogBase::DialogMode mode = QgsProcessingAlgorithmDialogBase::DialogMode::Single );
118 ~QgsProcessingAlgorithmDialogBase() override;
119
127 void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
128
133 QgsProcessingAlgorithm *algorithm();
134
139 void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
140
145 QgsPanelWidget *mainWidget();
146
150 void showLog();
151
157 bool wasExecuted() const { return mExecuted; }
158
164 QVariantMap results() const { return mResults; }
165
170 QgsProcessingFeedback *createFeedback() SIP_FACTORY;
171
178 void saveLogToFile( const QString &path, LogFormat format = FormatPlainText );
179
186 Qgis::ProcessingLogLevel logLevel() const;
187
194 void setLogLevel( Qgis::ProcessingLogLevel level );
195
201 virtual void setParameters( const QVariantMap &values );
202
203 public slots:
204
210 void reportError( const QString &error, bool fatalError );
211
215 void pushWarning( const QString &warning );
216
220 void pushInfo( const QString &info );
221
229 void pushFormattedMessage( const QString &html );
230
234 void pushDebugInfo( const QString &message );
235
239 void pushCommandInfo( const QString &info );
240
244 void setPercentage( double percent );
245
249 void setProgressText( const QString &text );
250
254 void pushConsoleInfo( const QString &info );
255
260 QDialog *createProgressDialog();
261
266 void clearLog();
267
273 void saveLog();
274
279 void copyLogToClipboard();
280
284 void showParameters();
285
286 void reject() override;
287
288 protected:
289 void closeEvent( QCloseEvent *e ) override;
290
294 QPushButton *runButton();
295
299 QPushButton *cancelButton();
300
304 QPushButton *changeParametersButton();
305
309 QDialogButtonBox *buttonBox();
310
314 QTabWidget *tabWidget();
315
319 void clearProgress();
320
326 void setExecuted( bool executed );
327
331 void setExecutedAnyResult( bool executedAnyResult );
332
338 void setResults( const QVariantMap &results );
339
343 void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
344
348 void resetGui();
349
354 virtual void resetAdditionalGui();
355
359 void updateRunButtonVisibility();
360
365 void blockControlsWhileRunning();
366
371 virtual void blockAdditionalControlsWhileRunning();
372
376 QgsMessageBar *messageBar();
377
381 void hideShortHelp();
382
387 void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
388
393 static QString formatStringForLog( const QString &string );
394
400 virtual bool isFinalized();
401
409 void applyContextOverrides( QgsProcessingContext *context );
410
411 signals:
412
420 void algorithmAboutToRun( QgsProcessingContext *context );
421
427 void algorithmFinished( bool successful, const QVariantMap &result );
428
429 protected slots:
430
434 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
435
439 virtual void runAlgorithm();
440
446 virtual void algExecuted( bool successful, const QVariantMap &results );
447
448 private slots:
449
450 void openHelp();
451 void toggleCollapsed();
452
453 void splitterChanged( int pos, int index );
454 void mTabWidget_currentChanged( int index );
455 void linkClicked( const QUrl &url );
456 void taskTriggered( QgsTask *task );
457 void closeClicked();
458 void urlClicked( const QUrl &url );
459
460 private:
461 DialogMode mMode = DialogMode::Single;
462
463 QPushButton *mButtonRun = nullptr;
464 QPushButton *mButtonClose = nullptr;
465 QPushButton *mButtonChangeParameters = nullptr;
466 QByteArray mSplitterState;
467 QToolButton *mButtonCollapse = nullptr;
468 QgsMessageBar *mMessageBar = nullptr;
469 QPushButton *mAdvancedButton = nullptr;
470 QMenu *mAdvancedMenu = nullptr;
471 QAction *mCopyAsQgisProcessCommand = nullptr;
472 QAction *mPasteJsonAction = nullptr;
473 QAction *mContextSettingsAction = nullptr;
474
475 bool mExecuted = false;
476 bool mExecutedAnyResult = false;
477 QVariantMap mResults;
478 QgsPanelWidget *mMainWidget = nullptr;
479 std::unique_ptr<QgsProcessingAlgorithm> mAlgorithm;
480 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
481
482 bool mHelpCollapsed = false;
483
484 int mMessageLoggedCount = 0;
485
486 Qgis::ProcessingLogLevel mLogLevel = Qgis::ProcessingLogLevel::DefaultLevel;
487
488 QPointer<QgsProcessingContextOptionsWidget> mContextOptionsWidget;
489 bool mOverrideDefaultContextSettings = false;
490 Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
491 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
492 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
493 QString mTemporaryFolderOverride;
494 int mMaximumThreads = QThread::idealThreadCount();
495
496 QString formatHelp( QgsProcessingAlgorithm *algorithm );
497 void scrollToBottomOfLog();
498 void processEvents();
499};
500
501#ifndef SIP_RUN
502
508class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
509{
510 Q_OBJECT
511
512 public:
516 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
517
521 QProgressBar *progressBar();
522
526 QPushButton *cancelButton();
527
531 QTextEdit *logTextEdit();
532
533 public slots:
534
535 void reject() override;
536};
537
544class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, private Ui::QgsProcessingContextOptionsBase
545{
546 Q_OBJECT
547
548 public:
552 QgsProcessingContextOptionsWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
553
557 void setFromContext( const QgsProcessingContext *context );
558
562 Qgis::InvalidGeometryCheck invalidGeometryCheck() const;
563
567 Qgis::DistanceUnit distanceUnit() const;
568
572 Qgis::AreaUnit areaUnit() const;
573
577 QString temporaryFolder();
578
582 int maximumThreads() const;
583
589 void setLogLevel( Qgis::ProcessingLogLevel level );
590
596 Qgis::ProcessingLogLevel logLevel() const;
597};
598
599#endif
600
602
603#endif // QGSPROCESSINGALGORITHMDIALOGBASE_H
DistanceUnit
Units of distance.
Definition qgis.h:5013
AreaUnit
Units of area.
Definition qgis.h:5090
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2238
ProcessingLogLevel
Logging level for algorithms to use when pushing feedback messages.
Definition qgis.h:3656
A bar for displaying non-blocking messages to the user.
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.
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:84