QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
qgspythonrunner.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgspythonrunner.cpp
3
---------------------
4
begin : May 2011
5
copyright : (C) 2011 by Martin Dobias
6
email : wonder dot sk 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
#include "
qgspythonrunner.h
"
16
17
#include "
qgslogger.h
"
18
19
#include <QString>
20
21
using namespace
Qt::StringLiterals;
22
23
QgsPythonRunner
*
QgsPythonRunner::sInstance
=
nullptr
;
24
26
// static methods
27
28
bool
QgsPythonRunner::isValid
()
29
{
30
return
nullptr
!=
sInstance
;
31
}
32
33
bool
QgsPythonRunner::run
(
const
QString &command,
const
QString &messageOnError )
34
{
35
if
(
sInstance
)
36
{
37
QgsDebugMsgLevel
(
"Running "
+ command, 3 );
38
return
sInstance
->runCommand( command, messageOnError );
39
}
40
else
41
{
42
QgsDebugError
( u
"Unable to run Python command: runner not available!"
_s );
43
return
false
;
44
}
45
}
46
47
bool
QgsPythonRunner::runFile
(
const
QString &filename,
const
QString &messageOnError )
48
{
49
if
(
sInstance
)
50
{
51
QgsDebugMsgLevel
(
"Running "
+ filename, 3 );
52
return
sInstance
->runFileCommand( filename, messageOnError );
53
}
54
else
55
{
56
QgsDebugError
( u
"Unable to run Python command: runner not available!"
_s );
57
return
false
;
58
}
59
}
60
61
bool
QgsPythonRunner::eval
(
const
QString &command, QString &result )
62
{
63
if
(
sInstance
)
64
{
65
return
sInstance
->evalCommand( command, result );
66
}
67
else
68
{
69
QgsDebugError
( u
"Unable to run Python command: runner not available!"
_s );
70
return
false
;
71
}
72
}
73
74
bool
QgsPythonRunner::setArgv
(
const
QStringList &arguments,
const
QString &messageOnError )
75
{
76
if
(
sInstance
)
77
{
78
return
sInstance
->setArgvCommand( arguments, messageOnError );
79
}
80
else
81
{
82
QgsDebugError
( u
"Unable to run Python command: runner not available!"
_s );
83
return
false
;
84
}
85
}
86
87
void
QgsPythonRunner::setInstance
(
QgsPythonRunner
*runner )
88
{
89
delete
sInstance
;
90
sInstance
= runner;
91
}
QgsPythonRunner
Utility class for running Python commands from various parts of QGIS.
Definition
qgspythonrunner.h:33
QgsPythonRunner::setArgv
static bool setArgv(const QStringList &arguments, const QString &messageOnError=QString())
Set sys.argv.
Definition
qgspythonrunner.cpp:74
QgsPythonRunner::run
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a Python statement.
Definition
qgspythonrunner.cpp:33
QgsPythonRunner::setInstance
static void setInstance(QgsPythonRunner *runner)
Assign an instance of Python runner so that run() can be used.
Definition
qgspythonrunner.cpp:87
QgsPythonRunner::eval
static bool eval(const QString &command, QString &result)
Eval a Python statement.
Definition
qgspythonrunner.cpp:61
QgsPythonRunner::sInstance
static QgsPythonRunner * sInstance
Definition
qgspythonrunner.h:80
QgsPythonRunner::runFile
static bool runFile(const QString &filename, const QString &messageOnError=QString())
Execute a Python filename, showing an error message if one occurred.
Definition
qgspythonrunner.cpp:47
QgsPythonRunner::isValid
static bool isValid()
Returns true if the runner has an instance (and thus is able to run commands).
Definition
qgspythonrunner.cpp:28
QgsPythonRunner::QgsPythonRunner
QgsPythonRunner()=default
Protected constructor: can be instantiated only from children.
qgslogger.h
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition
qgslogger.h:80
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
qgspythonrunner.h
Generated on
for QGIS API Documentation by
1.17.0