QGIS API Documentation 3.41.0-Master (25ec5511245)
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:
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
423 void algorithmAboutToRun( QgsProcessingContext *context );
424
430 void algorithmFinished( bool successful, const QVariantMap &result );
431
432 protected slots:
433
437 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
438
442 virtual void runAlgorithm();
443
449 virtual void algExecuted( bool successful, const QVariantMap &results );
450
451 private slots:
452
453 void openHelp();
454 void toggleCollapsed();
455
456 void splitterChanged( int pos, int index );
457 void mTabWidget_currentChanged( int index );
458 void linkClicked( const QUrl &url );
459 void taskTriggered( QgsTask *task );
460 void closeClicked();
461 void urlClicked( const QUrl &url );
462
463 private:
464
465 DialogMode mMode = DialogMode::Single;
466
467 QPushButton *mButtonRun = nullptr;
468 QPushButton *mButtonClose = nullptr;
469 QPushButton *mButtonChangeParameters = nullptr;
470 QByteArray mSplitterState;
471 QToolButton *mButtonCollapse = nullptr;
472 QgsMessageBar *mMessageBar = nullptr;
473 QPushButton *mAdvancedButton = nullptr;
474 QMenu *mAdvancedMenu = nullptr;
475 QAction *mCopyAsQgisProcessCommand = nullptr;
476 QAction *mPasteJsonAction = nullptr;
477 QAction *mContextSettingsAction = nullptr;
478
479 bool mExecuted = false;
480 bool mExecutedAnyResult = false;
481 QVariantMap mResults;
482 QgsPanelWidget *mMainWidget = nullptr;
483 std::unique_ptr< QgsProcessingAlgorithm > mAlgorithm;
484 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
485
486 bool mHelpCollapsed = false;
487
488 int mMessageLoggedCount = 0;
489
490 Qgis::ProcessingLogLevel mLogLevel = Qgis::ProcessingLogLevel::DefaultLevel;
491
492 QPointer< QgsProcessingContextOptionsWidget > mContextOptionsWidget;
493 bool mOverrideDefaultContextSettings = false;
494 Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
495 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
496 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
497 QString mTemporaryFolderOverride;
498 int mMaximumThreads = QThread::idealThreadCount();
499
500 QString formatHelp( QgsProcessingAlgorithm *algorithm );
501 void scrollToBottomOfLog();
502 void processEvents();
503
504};
505
506#ifndef SIP_RUN
507
513class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
514{
515 Q_OBJECT
516
517 public:
518
522 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
523
527 QProgressBar *progressBar();
528
532 QPushButton *cancelButton();
533
537 QTextEdit *logTextEdit();
538
539 public slots:
540
541 void reject() override;
542
543};
544
551class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, private Ui::QgsProcessingContextOptionsBase
552{
553 Q_OBJECT
554
555 public:
556
560 QgsProcessingContextOptionsWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
561
565 void setFromContext( const QgsProcessingContext *context );
566
570 Qgis::InvalidGeometryCheck invalidGeometryCheck() const;
571
575 Qgis::DistanceUnit distanceUnit() const;
576
580 Qgis::AreaUnit areaUnit() const;
581
585 QString temporaryFolder();
586
590 int maximumThreads() const;
591
597 void setLogLevel( Qgis::ProcessingLogLevel level );
598
604 Qgis::ProcessingLogLevel logLevel() const;
605};
606
607#endif
608
610
611#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:4669
AreaUnit
Units of area.
Definition qgis.h:4746
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2072
ProcessingLogLevel
Logging level for algorithms to use when pushing feedback messages.
Definition qgis.h:3385
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