Skip to content

Commit

Permalink
Dox++, constify
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 28, 2019
1 parent a079b66 commit a1c08b4
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 76 deletions.
88 changes: 70 additions & 18 deletions src/python/qgspythonutils.h
Expand Up @@ -47,11 +47,15 @@ class PYTHON_EXPORT QgsPythonUtils

virtual ~QgsPythonUtils() = default;

//! returns TRUE if Python support is ready to use (must be inited first)
/**
* Returns TRUE if Python support is ready to use.
*
* Python support must be initialized first, via a call to initPython().
*/
virtual bool isEnabled() = 0;

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

#ifdef HAVE_SERVER_PYTHON_PLUGINS
//! initialize Python and import server bindings

/**
* Initializes Python and imports server bindings.
*/
virtual void initServerPython( QgsServerInterface *iface ) = 0;

//! start server plugin: call plugin's classServerFactory(serverInterface) add to active plugins
/**
* Starts a server plugin.
*
* Calls the plugin's classServerFactory(serverInterface) and adds the matching plugin to the
* active plugins list.
*/
virtual bool startServerPlugin( QString packageName ) = 0;
#endif

//! close Python interpreter
/**
* Gracefully closes the Python interpreter and cleans up Python library handles.
*/
virtual void exitPython() = 0;

/* console */

/**
* run a statement, show an error message on error
* Runs a Python \a command, showing an error message if one occurred.
* \returns TRUE if no error occurred
*/
virtual bool runString( const QString &command, QString msgOnError = QString(), bool single = true ) = 0;

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

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

/**
Expand All @@ -95,31 +110,68 @@ class PYTHON_EXPORT QgsPythonUtils

/* plugins */

//! Returns a list of all available Python plugins
/**
* Returns a list of all available Python plugins.
*
* \see listActivePlugins()
*/
virtual QStringList pluginList() = 0;

//! Returns whether the plugin is loaded (active)
/**
* Returns TRUE if the plugin with matching name is loaded (active).
*
* \see listActivePlugins()
* \see loadPlugin()
*/
virtual bool isPluginLoaded( const QString &packageName ) = 0;

//! Returns a list of active plugins
/**
* Returns a list of active (loaded) plugins.
*
* \see isPluginLoaded()
* \see loadPlugin()
*/
virtual QStringList listActivePlugins() = 0;

//! load Python plugin (import)
/**
* Loads a Python plugin (via import) and returns TRUE if the plugin was successfully loaded.
*
* \see isPluginLoaded()
* \see startPlugin()
*/
virtual bool loadPlugin( const QString &packageName ) = 0;

//! start plugin: add to active plugins and call initGui()
/**
* Starts the plugin with matching \a packageName. The plugin must have already been loaded
* via a call to loadPlugin().
*
* Calling this adds the plugin to the active plugins list and calls its initGui() implementation.
*
* Returns TRUE if the plugin was successfully started.
*
* \see loadPlugin()
*/
virtual bool startPlugin( const QString &packageName ) = 0;

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

//! confirm that the plugin can be uninstalled
/**
* Confirms that the plugin can be uninstalled.
*/
virtual bool canUninstallPlugin( const QString &packageName ) = 0;

//! unload plugin
/**
* Unloads a plugin.
*
* Triggers the plugin's unload() implementation and removes it from the list of loaded plugins.
*
* Returns TRUE if the plugin was successfully unloaded.
*/
virtual bool unloadPlugin( const QString &packageName ) = 0;
};

Expand Down
10 changes: 5 additions & 5 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -541,20 +541,20 @@ bool QgsPythonUtilsImpl::evalString( const QString &command, QString &result )
return success;
}

QString QgsPythonUtilsImpl::pythonPath()
QString QgsPythonUtilsImpl::pythonPath() const
{
if ( QgsApplication::isRunningFromBuildDir() )
return QgsApplication::buildOutputPath() + "/python";
else
return QgsApplication::pkgDataPath() + "/python";
}

QString QgsPythonUtilsImpl::pluginsPath()
QString QgsPythonUtilsImpl::pluginsPath() const
{
return pythonPath() + "/plugins";
}

QString QgsPythonUtilsImpl::homePythonPath()
QString QgsPythonUtilsImpl::homePythonPath() const
{
QString settingsDir = QgsApplication::qgisSettingsDirPath();
if ( QDir::cleanPath( settingsDir ) == QDir::homePath() + QStringLiteral( "/.qgis3" ) )
Expand All @@ -567,12 +567,12 @@ QString QgsPythonUtilsImpl::homePythonPath()
}
}

QString QgsPythonUtilsImpl::homePluginsPath()
QString QgsPythonUtilsImpl::homePluginsPath() const
{
return homePythonPath() + " + \"/plugins\"";
}

QStringList QgsPythonUtilsImpl::extraPluginsPaths()
QStringList QgsPythonUtilsImpl::extraPluginsPaths() const
{
const char *cpaths = getenv( "QGIS_PLUGINPATH" );
if ( !cpaths )
Expand Down
76 changes: 23 additions & 53 deletions src/python/qgspythonutilsimpl.h
Expand Up @@ -37,86 +37,56 @@ class QgsPythonUtilsImpl : public QgsPythonUtils
/* general purpose functions */

void initPython( QgisInterface *interface, bool installErrorHook ) override;

#ifdef HAVE_SERVER_PYTHON_PLUGINS
//! initialize Python for server and import bindings
void initServerPython( QgsServerInterface *interface ) override;
bool startServerPlugin( QString packageName ) override;
#endif

//! close Python interpreter
void exitPython() override;

//! returns TRUE if Python support is ready to use (must be inited first)
bool isEnabled() override;

//! returns path where QGIS Python stuff is located
QString pythonPath();

/**
* run a statement (wrapper for PyRun_String)
* this command is more advanced as enables error checking etc.
* when an exception is raised, it shows dialog with exception details
* \returns TRUE if no error occurred
*/
bool runString( const QString &command, QString msgOnError = QString(), bool single = true ) override;

/**
* run a statement, error reporting is not done
* \returns TRUE if no error occurred
*/
bool runStringUnsafe( const QString &command, bool single = true ) override;

bool evalString( const QString &command, QString &result ) override;
bool getError( QString &errorClassName, QString &errorText ) override;

//! \returns object's type name as a string
QString getTypeAsString( PyObject *obj );
/**
* Returns the path where QGIS Python related files are located.
*/
QString pythonPath() const;

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

/* plugins related functions */

//! Returns the current path for Python plugins
QString pluginsPath();
/**
* Returns the current path for Python plugins
*/
QString pluginsPath() const;

//! Returns the current path for Python in home directory
QString homePythonPath();
/**
* Returns the current path for Python in home directory.
*/
QString homePythonPath() const;

//! Returns the current path for home directory Python plugins
QString homePluginsPath();
/**
* Returns the current path for home directory Python plugins.
*/
QString homePluginsPath() const;

//! Returns a list of extra plugins paths passed with QGIS_PLUGINPATH environment variable
QStringList extraPluginsPaths();
/**
* Returns a list of extra plugins paths passed with QGIS_PLUGINPATH environment variable.
*/
QStringList extraPluginsPaths() const;

//! Returns a list of all available Python plugins
QStringList pluginList() override;

//! Returns whether the plugin is loaded (active)
bool isPluginLoaded( const QString &packageName ) override;

//! Returns a list of active plugins
QStringList listActivePlugins() override;

//! load Python plugin (import)
bool loadPlugin( const QString &packageName ) override;

//! start plugin: add to active plugins and call initGui()
bool startPlugin( const QString &packageName ) override;

/**
* helper function to get some information about plugin
* \param function one of these strings: name, tpye, version, description
*/
QString getPluginMetadata( const QString &pluginName, const QString &function ) override;

//! confirm it is safe to uninstall the plugin
bool canUninstallPlugin( const QString &packageName ) override;

//! unload plugin
bool unloadPlugin( const QString &packageName ) override;

protected:
Expand Down

0 comments on commit a1c08b4

Please sign in to comment.