QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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(
118 QWidget *parent SIP_TRANSFERTHIS = nullptr, Qt::WindowFlags flags = Qt::WindowFlags(), QgsProcessingAlgorithmDialogBase::DialogMode mode = QgsProcessingAlgorithmDialogBase::DialogMode::Single
119 );
120 ~QgsProcessingAlgorithmDialogBase() override;
121
129 void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
130
135 QgsProcessingAlgorithm *algorithm();
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 void closeEvent( QCloseEvent *e ) override;
292
296 QPushButton *runButton();
297
301 QPushButton *cancelButton();
302
306 QPushButton *changeParametersButton();
307
311 QDialogButtonBox *buttonBox();
312
316 QTabWidget *tabWidget();
317
321 void clearProgress();
322
328 void setExecuted( bool executed );
329
333 void setExecutedAnyResult( bool executedAnyResult );
334
340 void setResults( const QVariantMap &results );
341
345 void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
346
350 void resetGui();
351
356 virtual void resetAdditionalGui();
357
361 void updateRunButtonVisibility();
362
367 void blockControlsWhileRunning();
368
373 virtual void blockAdditionalControlsWhileRunning();
374
378 QgsMessageBar *messageBar();
379
383 void hideShortHelp();
384
389 void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
390
395 static QString formatStringForLog( const QString &string );
396
402 virtual bool isFinalized();
403
411 void applyContextOverrides( QgsProcessingContext *context );
412
413 signals:
414
422 void algorithmAboutToRun( QgsProcessingContext *context );
423
429 void algorithmFinished( bool successful, const QVariantMap &result );
430
431 protected slots:
432
436 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
437
441 virtual void runAlgorithm();
442
448 virtual void algExecuted( bool successful, const QVariantMap &results );
449
450 private slots:
451
452 void openHelp();
453 void toggleCollapsed();
454
455 void splitterChanged( int pos, int index );
456 void mTabWidget_currentChanged( int index );
457 void linkClicked( const QUrl &url );
458 void taskTriggered( QgsTask *task );
459 void closeClicked();
460 void urlClicked( const QUrl &url );
461
462 private:
463 DialogMode mMode = DialogMode::Single;
464
465 QPushButton *mButtonRun = nullptr;
466 QPushButton *mButtonClose = nullptr;
467 QPushButton *mButtonChangeParameters = nullptr;
468 QByteArray mSplitterState;
469 QToolButton *mButtonCollapse = nullptr;
470 QgsMessageBar *mMessageBar = nullptr;
471 QPushButton *mAdvancedButton = nullptr;
472 QMenu *mAdvancedMenu = nullptr;
473 QAction *mCopyAsQgisProcessCommand = nullptr;
474 QAction *mPasteJsonAction = nullptr;
475 QAction *mContextSettingsAction = nullptr;
476
477 bool mExecuted = false;
478 bool mExecutedAnyResult = false;
479 QVariantMap mResults;
480 QgsPanelWidget *mMainWidget = nullptr;
481 std::unique_ptr<QgsProcessingAlgorithm> mAlgorithm;
482 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
483
484 bool mHelpCollapsed = false;
485
486 int mMessageLoggedCount = 0;
487
488 Qgis::ProcessingLogLevel mLogLevel = Qgis::ProcessingLogLevel::DefaultLevel;
489
490 QPointer<QgsProcessingContextOptionsWidget> mContextOptionsWidget;
491 bool mOverrideDefaultContextSettings = false;
492 Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
493 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
494 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
495 QString mTemporaryFolderOverride;
496 int mMaximumThreads = QThread::idealThreadCount();
497
498 QString formatHelp( QgsProcessingAlgorithm *algorithm );
499 void scrollToBottomOfLog();
500 void processEvents();
501};
502
503#ifndef SIP_RUN
504
510class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
511{
512 Q_OBJECT
513
514 public:
518 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
519
523 QProgressBar *progressBar();
524
528 QPushButton *cancelButton();
529
533 QTextEdit *logTextEdit();
534
535 public slots:
536
537 void reject() override;
538};
539
546class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, private Ui::QgsProcessingContextOptionsBase
547{
548 Q_OBJECT
549
550 public:
554 QgsProcessingContextOptionsWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
555
559 void setFromContext( const QgsProcessingContext *context );
560
564 Qgis::InvalidGeometryCheck invalidGeometryCheck() const;
565
569 Qgis::DistanceUnit distanceUnit() const;
570
574 Qgis::AreaUnit areaUnit() const;
575
579 QString temporaryFolder();
580
584 int maximumThreads() const;
585
591 void setLogLevel( Qgis::ProcessingLogLevel level );
592
598 Qgis::ProcessingLogLevel logLevel() const;
599};
600
601#endif
602
604
605#endif // QGSPROCESSINGALGORITHMDIALOGBASE_H
DistanceUnit
Units of distance.
Definition qgis.h:5170
AreaUnit
Units of area.
Definition qgis.h:5247
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2319
ProcessingLogLevel
Logging level for algorithms to use when pushing feedback messages.
Definition qgis.h:3771
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:52
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83