QGIS API Documentation 4.1.0-Master (d6fb7a379fb)
Loading...
Searching...
No Matches
qgsprocessingalgorithmwidgetbase.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingalgorithmwidgetbase.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 QGSPROCESSINGALGORITHMWIDGETBASE_H
17#define QGSPROCESSINGALGORITHMWIDGETBASE_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 QgsProcessingContextOptionsWidget;
36class QgsMessageBar;
38class QgsTask;
39class QgsDockableWidgetHelper;
40class QMainWindow;
41
48class GUI_EXPORT QgsProcessingFeedbackGenerator
49{
50 public:
51 virtual ~QgsProcessingFeedbackGenerator();
52
56 virtual QgsProcessingFeedback *createFeedback() = 0 SIP_FACTORY;
57};
58
59
65class GUI_EXPORT QgsProcessingAlgorithmWidgetBase : public QWidget, public QgsProcessingParametersGenerator, public QgsProcessingContextGenerator, private Ui::QgsProcessingDialogBase
66{
67 Q_OBJECT
68
69 public:
74 enum class LogFormat : int
75 {
76 FormatPlainText,
77 FormatHtml,
78 };
79 Q_ENUM( QgsProcessingAlgorithmWidgetBase::LogFormat )
80
81
86 enum class WidgetMode : int
87 {
88 Single,
89 Batch,
90 };
91 Q_ENUM( QgsProcessingAlgorithmWidgetBase::WidgetMode )
92
93
98 enum class WidgetFlag : int SIP_ENUM_BASETYPE( IntFlag )
99 {
100 NoDocking = 1 << 0
101 };
102 Q_ENUM( WidgetFlag )
103
104
109 Q_DECLARE_FLAGS( WidgetFlags, WidgetFlag )
110 Q_FLAG( WidgetFlags )
111
112
115 QgsProcessingAlgorithmWidgetBase(
116 QMainWindow *parentWindow SIP_TRANSFERTHIS,
117 QgsProcessingAlgorithmWidgetBase::WidgetMode mode = QgsProcessingAlgorithmWidgetBase::WidgetMode::Single,
118 QgsProcessingAlgorithmWidgetBase::WidgetFlags flags = QgsProcessingAlgorithmWidgetBase::WidgetFlags(),
120 );
121 ~QgsProcessingAlgorithmWidgetBase() override;
122
130 void setAlgorithm( QgsProcessingAlgorithm *algorithm SIP_TRANSFER );
131
136 QgsProcessingAlgorithm *algorithm();
137
142 void setMainWidget( QgsPanelWidget *widget SIP_TRANSFER );
143
148 QgsPanelWidget *mainWidget();
149
155 void showWidget();
156
160 void showLog();
161
167 bool wasExecuted() const { return mExecuted; }
168
174 QVariantMap results() const { return mResults; }
175
189 void registerProcessingFeedbackGenerator( QgsProcessingFeedbackGenerator *generator );
190
197 QgsProcessingFeedback *createFeedback() SIP_FACTORY;
198
205 void saveLogToFile( const QString &path, QgsProcessingAlgorithmWidgetBase::LogFormat format = QgsProcessingAlgorithmWidgetBase::LogFormat::FormatPlainText );
206
213 Qgis::ProcessingLogLevel logLevel() const;
214
221 void setLogLevel( Qgis::ProcessingLogLevel level );
222
228 virtual void setParameters( const QVariantMap &values );
229
235 void setTitle( const QString &title );
236
237 public slots:
238
246 void exec();
247
253 void reportError( const QString &error, bool fatalError );
254
258 void pushWarning( const QString &warning );
259
263 void pushInfo( const QString &info );
264
272 void pushFormattedMessage( const QString &html );
273
277 void pushDebugInfo( const QString &message );
278
282 void pushCommandInfo( const QString &info );
283
287 void setPercentage( double percent );
288
292 void setProgressText( const QString &text );
293
297 void pushConsoleInfo( const QString &info );
298
303 QDialog *createProgressDialog();
304
309 void clearLog();
310
316 void saveLog();
317
322 void copyLogToClipboard();
323
327 void showParameters();
328
342 virtual bool isRunning();
343
353 void cancel();
354
360 void forceClose();
361
362 void reject();
363
367 void hideShortHelp();
368
372 QgsMessageBar *messageBar();
373
374 protected:
375 void closeEvent( QCloseEvent *e ) override;
376
380 QPushButton *runButton();
381
385 QPushButton *cancelButton();
386
390 QPushButton *changeParametersButton();
391
395 QDialogButtonBox *buttonBox();
396
400 QTabWidget *tabWidget();
401
405 void clearProgress();
406
412 void setExecuted( bool executed );
413
417 void setExecutedAnyResult( bool executedAnyResult );
418
424 void setResults( const QVariantMap &results );
425
429 void setInfo( const QString &message, bool isError = false, bool escapeHtml = true, bool isWarning = false );
430
434 void resetGui();
435
440 virtual void resetAdditionalGui();
441
445 void updateRunButtonVisibility();
446
451 void blockControlsWhileRunning();
452
457 virtual void blockAdditionalControlsWhileRunning();
458
463 void setCurrentTask( QgsProcessingAlgRunnerTask *task SIP_TRANSFER );
464
469 static QString formatStringForLog( const QString &string );
470
476 virtual bool isFinalized();
477
485 void applyContextOverrides( QgsProcessingContext *context );
486
487 signals:
488
496 void algorithmAboutToRun( QgsProcessingContext *context );
497
503 void algorithmFinished( bool successful, const QVariantMap &result );
504
511 SIP_SKIP void cancelRequested();
512
513 protected slots:
514
518 virtual void finished( bool successful, const QVariantMap &result, QgsProcessingContext &context, QgsProcessingFeedback *feedback );
519
523 virtual void runAlgorithm();
524
530 virtual void algExecuted( bool successful, const QVariantMap &results );
531
532 private slots:
533
534 void openHelp();
535 void toggleCollapsed();
536
537 void splitterChanged( int pos, int index );
538 void mTabWidget_currentChanged( int index );
539 void linkClicked( const QUrl &url );
540 void taskTriggered( QgsTask *task );
541 void closeClicked();
542 void urlClicked( const QUrl &url );
543
544 private:
551 void disconnectCurrentTask();
552
553 QgsDockableWidgetHelper *mDockableWidgetHelper = nullptr;
554
555 WidgetMode mMode = WidgetMode::Single;
556
557 QPushButton *mButtonRun = nullptr;
558 QPushButton *mButtonClose = nullptr;
559 QPushButton *mButtonChangeParameters = nullptr;
560 QByteArray mSplitterState;
561 QToolButton *mButtonCollapse = nullptr;
562 QgsMessageBar *mMessageBar = nullptr;
563 QPushButton *mAdvancedButton = nullptr;
564 QMenu *mAdvancedMenu = nullptr;
565 QAction *mCopyAsQgisProcessCommand = nullptr;
566 QAction *mPasteJsonAction = nullptr;
567 QAction *mContextSettingsAction = nullptr;
568
569 bool mExecuted = false;
570 bool mExecutedAnyResult = false;
571 QVariantMap mResults;
572 QgsPanelWidget *mMainWidget = nullptr;
573 QgsProcessingFeedbackGenerator *mFeedbackFactory = nullptr;
574 std::unique_ptr<QgsProcessingAlgorithm> mAlgorithm;
575 QgsProcessingAlgRunnerTask *mAlgorithmTask = nullptr;
576
577 bool mHelpCollapsed = false;
578
579 int mMessageLoggedCount = 0;
580
581 Qgis::ProcessingLogLevel mLogLevel = Qgis::ProcessingLogLevel::DefaultLevel;
582
583 QPointer<QgsProcessingContextOptionsWidget> mContextOptionsWidget;
584 bool mOverrideDefaultContextSettings = false;
585 Qgis::InvalidGeometryCheck mGeometryCheck = Qgis::InvalidGeometryCheck::AbortOnInvalid;
586 Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
587 Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
588 QString mTemporaryFolderOverride;
589 int mMaximumThreads = QThread::idealThreadCount();
590
591 QString formatHelp( QgsProcessingAlgorithm *algorithm );
592 void scrollToBottomOfLog();
593 void processEvents();
594};
595
596#ifndef SIP_RUN
597
603class QgsProcessingAlgorithmProgressDialog : public QDialog, private Ui::QgsProcessingProgressDialogBase
604{
605 Q_OBJECT
606
607 public:
611 QgsProcessingAlgorithmProgressDialog( QWidget *parent = nullptr );
612
616 QProgressBar *progressBar();
617
621 QPushButton *cancelButton();
622
626 QTextEdit *logTextEdit();
627
628 public slots:
629
630 void reject() override;
631};
632
639class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, private Ui::QgsProcessingContextOptionsBase
640{
641 Q_OBJECT
642
643 public:
647 QgsProcessingContextOptionsWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
648
652 void setFromContext( const QgsProcessingContext *context );
653
657 Qgis::InvalidGeometryCheck invalidGeometryCheck() const;
658
662 Qgis::DistanceUnit distanceUnit() const;
663
667 Qgis::AreaUnit areaUnit() const;
668
672 QString temporaryFolder();
673
677 int maximumThreads() const;
678
684 void setLogLevel( Qgis::ProcessingLogLevel level );
685
691 Qgis::ProcessingLogLevel logLevel() const;
692};
693
694Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProcessingAlgorithmWidgetBase::WidgetFlags )
695
696#endif
697
699
700#endif // QGSPROCESSINGALGORITHMWIDGETBASE_H
DistanceUnit
Units of distance.
Definition qgis.h:5382
AreaUnit
Units of area.
Definition qgis.h:5459
InvalidGeometryCheck
Methods for handling of features with invalid geometries.
Definition qgis.h:2372
DockableWidgetInitialState
Dockable widget initial states.
Definition qgis.h:6776
@ RestorePreviousState
Restore the previous state of this dock.
Definition qgis.h:6777
ProcessingLogLevel
Logging level for algorithms to use when pushing feedback messages.
Definition qgis.h:3838
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.
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_ENUM_BASETYPE(type)
Definition qgis_sip.h:274
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)