Skip to content

Commit a1c08b4

Browse files
committedFeb 28, 2019
Dox++, constify
1 parent a079b66 commit a1c08b4

File tree

3 files changed

+98
-76
lines changed

3 files changed

+98
-76
lines changed
 

‎src/python/qgspythonutils.h

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ class PYTHON_EXPORT QgsPythonUtils
4747

4848
virtual ~QgsPythonUtils() = default;
4949

50-
//! returns TRUE if Python support is ready to use (must be inited first)
50+
/**
51+
* Returns TRUE if Python support is ready to use.
52+
*
53+
* Python support must be initialized first, via a call to initPython().
54+
*/
5155
virtual bool isEnabled() = 0;
5256

5357
/**
54-
* Initialize Python and import bindings.
58+
* Initializes Python and imports the PyQGIS bindings.
5559
*
5660
* The \a iface argument should be set to an instance of the QGIS interface, or
5761
* NULLPTR if no interface is available.
@@ -61,30 +65,41 @@ class PYTHON_EXPORT QgsPythonUtils
6165
virtual void initPython( QgisInterface *iface, bool installErrorHook ) = 0;
6266

6367
#ifdef HAVE_SERVER_PYTHON_PLUGINS
64-
//! initialize Python and import server bindings
68+
69+
/**
70+
* Initializes Python and imports server bindings.
71+
*/
6572
virtual void initServerPython( QgsServerInterface *iface ) = 0;
6673

67-
//! start server plugin: call plugin's classServerFactory(serverInterface) add to active plugins
74+
/**
75+
* Starts a server plugin.
76+
*
77+
* Calls the plugin's classServerFactory(serverInterface) and adds the matching plugin to the
78+
* active plugins list.
79+
*/
6880
virtual bool startServerPlugin( QString packageName ) = 0;
6981
#endif
7082

71-
//! close Python interpreter
83+
/**
84+
* Gracefully closes the Python interpreter and cleans up Python library handles.
85+
*/
7286
virtual void exitPython() = 0;
7387

74-
/* console */
75-
7688
/**
77-
* run a statement, show an error message on error
89+
* Runs a Python \a command, showing an error message if one occurred.
7890
* \returns TRUE if no error occurred
7991
*/
8092
virtual bool runString( const QString &command, QString msgOnError = QString(), bool single = true ) = 0;
8193

8294
/**
83-
* run a statement, error reporting is not done
95+
* Runs a Python \a command. No error reporting is not performed.
8496
* \returns TRUE if no error occurred
8597
*/
8698
virtual bool runStringUnsafe( const QString &command, bool single = true ) = 0;
8799

100+
/**
101+
* Evaluates a Python \a command and stores the result in a the \a result string.
102+
*/
88103
virtual bool evalString( const QString &command, QString &result ) = 0;
89104

90105
/**
@@ -95,31 +110,68 @@ class PYTHON_EXPORT QgsPythonUtils
95110

96111
/* plugins */
97112

98-
//! Returns a list of all available Python plugins
113+
/**
114+
* Returns a list of all available Python plugins.
115+
*
116+
* \see listActivePlugins()
117+
*/
99118
virtual QStringList pluginList() = 0;
100119

101-
//! Returns whether the plugin is loaded (active)
120+
/**
121+
* Returns TRUE if the plugin with matching name is loaded (active).
122+
*
123+
* \see listActivePlugins()
124+
* \see loadPlugin()
125+
*/
102126
virtual bool isPluginLoaded( const QString &packageName ) = 0;
103127

104-
//! Returns a list of active plugins
128+
/**
129+
* Returns a list of active (loaded) plugins.
130+
*
131+
* \see isPluginLoaded()
132+
* \see loadPlugin()
133+
*/
105134
virtual QStringList listActivePlugins() = 0;
106135

107-
//! load Python plugin (import)
136+
/**
137+
* Loads a Python plugin (via import) and returns TRUE if the plugin was successfully loaded.
138+
*
139+
* \see isPluginLoaded()
140+
* \see startPlugin()
141+
*/
108142
virtual bool loadPlugin( const QString &packageName ) = 0;
109143

110-
//! start plugin: add to active plugins and call initGui()
144+
/**
145+
* Starts the plugin with matching \a packageName. The plugin must have already been loaded
146+
* via a call to loadPlugin().
147+
*
148+
* Calling this adds the plugin to the active plugins list and calls its initGui() implementation.
149+
*
150+
* Returns TRUE if the plugin was successfully started.
151+
*
152+
* \see loadPlugin()
153+
*/
111154
virtual bool startPlugin( const QString &packageName ) = 0;
112155

113156
/**
114-
* helper function to get some information about plugin
115-
* \param function one of these strings: name, tpye, version, description
157+
* Helper function to return some information about a plugin.
158+
*
159+
* \param function metadata component to return. Must match one of the strings: name, type, version, or description.
116160
*/
117161
virtual QString getPluginMetadata( const QString &pluginName, const QString &function ) = 0;
118162

119-
//! confirm that the plugin can be uninstalled
163+
/**
164+
* Confirms that the plugin can be uninstalled.
165+
*/
120166
virtual bool canUninstallPlugin( const QString &packageName ) = 0;
121167

122-
//! unload plugin
168+
/**
169+
* Unloads a plugin.
170+
*
171+
* Triggers the plugin's unload() implementation and removes it from the list of loaded plugins.
172+
*
173+
* Returns TRUE if the plugin was successfully unloaded.
174+
*/
123175
virtual bool unloadPlugin( const QString &packageName ) = 0;
124176
};
125177

‎src/python/qgspythonutilsimpl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,20 +541,20 @@ bool QgsPythonUtilsImpl::evalString( const QString &command, QString &result )
541541
return success;
542542
}
543543

544-
QString QgsPythonUtilsImpl::pythonPath()
544+
QString QgsPythonUtilsImpl::pythonPath() const
545545
{
546546
if ( QgsApplication::isRunningFromBuildDir() )
547547
return QgsApplication::buildOutputPath() + "/python";
548548
else
549549
return QgsApplication::pkgDataPath() + "/python";
550550
}
551551

552-
QString QgsPythonUtilsImpl::pluginsPath()
552+
QString QgsPythonUtilsImpl::pluginsPath() const
553553
{
554554
return pythonPath() + "/plugins";
555555
}
556556

557-
QString QgsPythonUtilsImpl::homePythonPath()
557+
QString QgsPythonUtilsImpl::homePythonPath() const
558558
{
559559
QString settingsDir = QgsApplication::qgisSettingsDirPath();
560560
if ( QDir::cleanPath( settingsDir ) == QDir::homePath() + QStringLiteral( "/.qgis3" ) )
@@ -567,12 +567,12 @@ QString QgsPythonUtilsImpl::homePythonPath()
567567
}
568568
}
569569

570-
QString QgsPythonUtilsImpl::homePluginsPath()
570+
QString QgsPythonUtilsImpl::homePluginsPath() const
571571
{
572572
return homePythonPath() + " + \"/plugins\"";
573573
}
574574

575-
QStringList QgsPythonUtilsImpl::extraPluginsPaths()
575+
QStringList QgsPythonUtilsImpl::extraPluginsPaths() const
576576
{
577577
const char *cpaths = getenv( "QGIS_PLUGINPATH" );
578578
if ( !cpaths )

‎src/python/qgspythonutilsimpl.h

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,86 +37,56 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
3737
/* general purpose functions */
3838

3939
void initPython( QgisInterface *interface, bool installErrorHook ) override;
40-
4140
#ifdef HAVE_SERVER_PYTHON_PLUGINS
42-
//! initialize Python for server and import bindings
4341
void initServerPython( QgsServerInterface *interface ) override;
4442
bool startServerPlugin( QString packageName ) override;
4543
#endif
46-
47-
//! close Python interpreter
4844
void exitPython() override;
49-
50-
//! returns TRUE if Python support is ready to use (must be inited first)
5145
bool isEnabled() override;
52-
53-
//! returns path where QGIS Python stuff is located
54-
QString pythonPath();
55-
56-
/**
57-
* run a statement (wrapper for PyRun_String)
58-
* this command is more advanced as enables error checking etc.
59-
* when an exception is raised, it shows dialog with exception details
60-
* \returns TRUE if no error occurred
61-
*/
6246
bool runString( const QString &command, QString msgOnError = QString(), bool single = true ) override;
63-
64-
/**
65-
* run a statement, error reporting is not done
66-
* \returns TRUE if no error occurred
67-
*/
6847
bool runStringUnsafe( const QString &command, bool single = true ) override;
69-
7048
bool evalString( const QString &command, QString &result ) override;
49+
bool getError( QString &errorClassName, QString &errorText ) override;
7150

72-
//! \returns object's type name as a string
73-
QString getTypeAsString( PyObject *obj );
51+
/**
52+
* Returns the path where QGIS Python related files are located.
53+
*/
54+
QString pythonPath() const;
7455

7556
/**
76-
* Gets information about error to the supplied arguments
77-
* \returns FALSE if there was no Python error
57+
* Returns an object's type name as a string
7858
*/
79-
bool getError( QString &errorClassName, QString &errorText ) override;
59+
QString getTypeAsString( PyObject *obj );
8060

8161
/* plugins related functions */
8262

83-
//! Returns the current path for Python plugins
84-
QString pluginsPath();
63+
/**
64+
* Returns the current path for Python plugins
65+
*/
66+
QString pluginsPath() const;
8567

86-
//! Returns the current path for Python in home directory
87-
QString homePythonPath();
68+
/**
69+
* Returns the current path for Python in home directory.
70+
*/
71+
QString homePythonPath() const;
8872

89-
//! Returns the current path for home directory Python plugins
90-
QString homePluginsPath();
73+
/**
74+
* Returns the current path for home directory Python plugins.
75+
*/
76+
QString homePluginsPath() const;
9177

92-
//! Returns a list of extra plugins paths passed with QGIS_PLUGINPATH environment variable
93-
QStringList extraPluginsPaths();
78+
/**
79+
* Returns a list of extra plugins paths passed with QGIS_PLUGINPATH environment variable.
80+
*/
81+
QStringList extraPluginsPaths() const;
9482

95-
//! Returns a list of all available Python plugins
9683
QStringList pluginList() override;
97-
98-
//! Returns whether the plugin is loaded (active)
9984
bool isPluginLoaded( const QString &packageName ) override;
100-
101-
//! Returns a list of active plugins
10285
QStringList listActivePlugins() override;
103-
104-
//! load Python plugin (import)
10586
bool loadPlugin( const QString &packageName ) override;
106-
107-
//! start plugin: add to active plugins and call initGui()
10887
bool startPlugin( const QString &packageName ) override;
109-
110-
/**
111-
* helper function to get some information about plugin
112-
* \param function one of these strings: name, tpye, version, description
113-
*/
11488
QString getPluginMetadata( const QString &pluginName, const QString &function ) override;
115-
116-
//! confirm it is safe to uninstall the plugin
11789
bool canUninstallPlugin( const QString &packageName ) override;
118-
119-
//! unload plugin
12090
bool unloadPlugin( const QString &packageName ) override;
12191

12292
protected:

0 commit comments

Comments
 (0)
Please sign in to comment.