1 /***************************************************************************
2                           qgsprocess.h
3                           -------------------
4     begin                : February 2019
5     copyright            : (C) 2019 Nyall Dawson
6     email                : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 #ifndef QGSPROCESS_H
18 #define QGSPROCESS_H
19 
20 #ifdef WITH_BINDINGS
21 #include "qgspythonrunner.h"
22 #include "qgspythonutils.h"
23 #endif
24 
25 #include "qgsprocessingfeedback.h"
26 #include "qgsunittypes.h"
27 #include "qgsprocessingcontext.h"
28 #include <QElapsedTimer>
29 
30 class QgsApplication;
31 
32 class QgsProcessingAlgorithm;
33 
34 class ConsoleFeedback : public QgsProcessingFeedback
35 {
36     Q_OBJECT
37 
38   public:
39 
40     /**
41      * Constructor for QgsProcessingAlgorithmDialogFeedback.
42      */
43     ConsoleFeedback( bool useJson );
44 
45   public slots:
46 
47     void setProgressText( const QString &text ) override;
48     void reportError( const QString &error, bool fatalError ) override;
49     void pushWarning( const QString &warning ) override;
50     void pushInfo( const QString &info ) override;
51     void pushCommandInfo( const QString &info ) override;
52     void pushDebugInfo( const QString &info ) override;
53     void pushConsoleInfo( const QString &info ) override;
54     QVariantMap jsonLog() const;
55 
56   private slots:
57     void showTerminalProgress( double progress );
58 
59   private:
60     QElapsedTimer mTimer;
61     int mLastTick = -1;
62     bool mUseJson = false;
63     QVariantMap mJsonLog;
64 };
65 
66 
67 class QgsProcessingExec
68 {
69 
70   public:
71 
72     QgsProcessingExec();
73     int run( const QStringList &args );
74 
75   private:
76 
77     void showUsage( const QString &appName );
78     void loadPlugins();
79     void listAlgorithms( bool useJson );
80     void listPlugins( bool useJson, bool showLoaded );
81     int enablePlugin( const QString &name, bool enabled );
82     int showAlgorithmHelp( const QString &id, bool useJson );
83     int execute( const QString &algId,
84                  const QVariantMap &parameters,
85                  const QString &ellipsoid,
86                  QgsUnitTypes::DistanceUnit distanceUnit,
87                  QgsUnitTypes::AreaUnit areaUnit,
88                  QgsProcessingContext::LogLevel logLevel,
89                  bool useJson,
90                  const QString &projectPath = QString() );
91 
92     void addVersionInformation( QVariantMap &json );
93     void addAlgorithmInformation( QVariantMap &json, const QgsProcessingAlgorithm *algorithm );
94     void addProviderInformation( QVariantMap &json, QgsProcessingProvider *provider );
95 
96 
97 #ifdef WITH_BINDINGS
98     std::unique_ptr< QgsPythonUtils > mPythonUtils;
99     std::unique_ptr<QgsPythonUtils> loadPythonSupport();
100 #endif
101 };
102 
103 #endif // QGSPROCESS_H
104 
105