QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
QgsApplication Class Reference

Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc. More...

#include <qgsapplication.h>

Public Types

enum  ENDIAN { XDR = 0, NDR = 1 }
 constants for endian-ness More...
typedef enum QgsApplication::ENDIAN endian_t
 constants for endian-ness

Signals

void preNotify (QObject *receiver, QEvent *event, bool *done)

Public Member Functions

 QgsApplication (int &argc, char **argv, bool GUIenabled, QString customConfigPath=QString())
virtual ~QgsApplication ()
virtual bool event (QEvent *event)
 Watch for QFileOpenEvent.
virtual bool notify (QObject *receiver, QEvent *event)
 Catch exceptions when sending event to receiver.

Static Public Member Functions

static void init (QString customConfigPath=QString())
 This method initialises paths etc for QGIS.
static void setFileOpenEventReceiver (QObject *receiver)
 Set the FileOpen event receiver.
static void setThemeName (const QString &theThemeName)
 Set the active theme to the specified theme.
static const QString themeName ()
 Set the active theme to the specified theme.
static const QString authorsFilePath ()
 Returns the path to the authors file.
static const QString contributorsFilePath ()
 Returns the path to the contributors file.
static const QString sponsorsFilePath ()
 Returns the path to the sponsors file.
static const QString donorsFilePath ()
 Returns the path to the donors file.
static const QString translatorsFilePath ()
 Returns the path to the sponsors file.
static const QString licenceFilePath ()
static const QString helpAppPath ()
 Returns the path to the help application.
static const QString i18nPath ()
 Returns the path to the translation directory.
static const QString qgisMasterDbFilePath ()
 Returns the path to the master qgis.db file.
static const QString qgisSettingsDirPath ()
 Returns the path to the settings directory in user's home dir.
static const QString qgisUserDbFilePath ()
 Returns the path to the user qgis.db file.
static const QString splashPath ()
 Returns the path to the splash screen image directory.
static const QString iconsPath ()
 Returns the path to the icons image directory.
static const QString srsDbFilePath ()
 Returns the path to the srs.db file.
static const QStringList svgPaths ()
 Returns the pathes to svg directories.
static const QMap< QString,
QString > 
systemEnvVars ()
 Returns the system environment variables passed to application.
static const QString prefixPath ()
 Returns the path to the application prefix directory.
static const QString pluginPath ()
 Returns the path to the application plugin directory.
static const QString pkgDataPath ()
 Returns the common root path of all application data directories.
static const QString activeThemePath ()
 Returns the path to the currently active theme directory.
static const QString defaultThemePath ()
 Returns the path to the default theme directory.
static QString iconPath (QString iconFile)
 Returns path to the desired icon file.
static QIcon getThemeIcon (const QString &theName)
 Helper to get a theme icon.
static QPixmap getThemePixmap (const QString &theName)
 Helper to get a theme icon as a pixmap.
static const QString userStyleV2Path ()
 Returns the path to user's style.
static const QString defaultStyleV2Path ()
 Returns the path to default style (works as a starting point).
static const QString libraryPath ()
 Returns the path containing qgis_core, qgis_gui, qgispython (and other) libraries.
static const QString libexecPath ()
 Returns the path with utility executables (help viewer, crssync, ...)
static void setPrefixPath (const QString &thePrefixPath, bool useDefaultPaths=false)
 Alters prefix path - used by 3rd party apps.
static void setPluginPath (const QString &thePluginPath)
 Alters plugin path - used by 3rd party apps.
static void setPkgDataPath (const QString &thePkgDataPath)
 Alters pkg data path - used by 3rd party apps.
static void setDefaultSvgPaths (const QStringList &pathList)
 Alters default svg paths - used by 3rd party apps.
static void initQgis ()
 loads providers
static bool createDB (QString *errorMessage=0)
 initialise qgis.db
static void exitQgis ()
 deletes provider registry and map layer registry
static endian_t endian ()
 Returns whether this machine uses big or little endian.
static QString reportStyleSheet ()
 get a standard css style sheet for reports.
static QString showSettings ()
 Convenience function to get a summary of the paths used in this application instance useful for debugging mainly.
static void registerOgrDrivers ()
 Register OGR drivers ensuring this only happens once.
static QString absolutePathToRelativePath (QString apath, QString targetPath)
 Converts absolute path to path relative to target.
static QString relativePathToAbsolutePath (QString rpath, QString targetPath)
 Converts path relative to target to an absolute path.
static bool isRunningFromBuildDir ()
 Indicates whether running from build directory (not installed)
static QString buildSourcePath ()
 Returns path to the source directory.
static QString buildOutputPath ()
 Returns path to the build output directory.
static void skipGdalDriver (QString theDriver)
 Sets the GDAL_SKIP environment variable to include the specified driver and then calls GDALDriverManager::AutoSkipDrivers() to unregister it.
static void restoreGdalDriver (QString theDriver)
 Sets the GDAL_SKIP environment variable to exclude the specified driver and then calls GDALDriverManager::AutoSkipDrivers() to unregister it.
static QStringList skippedGdalDrivers ()
 Returns the list of gdal drivers that should be skipped (based on GDAL_SKIP environment variable)
static void applyGdalSkippedDrivers ()
 Apply the skipped drivers list to gdal.
static int maxThreads ()
 Get maximum concurrent thread count.
static void setMaxThreads (int maxThreads)
 Set maximum concurrent thread count.

Static Public Attributes

static const char * QGIS_ORGANIZATION_NAME = "QGIS"
static const char * QGIS_ORGANIZATION_DOMAIN = "qgis.org"
static const char * QGIS_APPLICATION_NAME = "QGIS2"

Detailed Description

Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.

The QgsApplication class manages application-wide information.

This is a subclass of QApplication and should be instantiated in place of QApplication. Most methods are static in keeping witn the design of QApplication.

This class hides platform-specific path information and provides a portable way of referencing specific files and directories. Ideally, hard-coded paths should appear only here and not in other modules so that platform-conditional code is minimized and paths are easier to change due to centralization.

Member Typedef Documentation

constants for endian-ness

Member Enumeration Documentation

constants for endian-ness

Enumerator:
XDR 
NDR 

Constructor & Destructor Documentation

QgsApplication::QgsApplication ( int &  argc,
char **  argv,
bool  GUIenabled,
QString  customConfigPath = QString() 
)
QgsApplication::~QgsApplication ( )
virtual

Member Function Documentation

QString QgsApplication::absolutePathToRelativePath ( QString  apath,
QString  targetPath 
)
static

Converts absolute path to path relative to target.

const QString QgsApplication::activeThemePath ( )
static

Returns the path to the currently active theme directory.

void QgsApplication::applyGdalSkippedDrivers ( )
static

Apply the skipped drivers list to gdal.

See Also
skipGdalDriver
restoreGdalDriver
skippedGdalDrivers
const QString QgsApplication::authorsFilePath ( )
static

Returns the path to the authors file.

static QString QgsApplication::buildOutputPath ( )
inlinestatic

Returns path to the build output directory.

Valid only when running from build directory

static QString QgsApplication::buildSourcePath ( )
inlinestatic

Returns path to the source directory.

Valid only when running from build directory

const QString QgsApplication::contributorsFilePath ( )
static

Returns the path to the contributors file.

Contributors are people who have submitted patches but don't have svn write access.

bool QgsApplication::createDB ( QString *  errorMessage = 0)
static

initialise qgis.db

const QString QgsApplication::defaultStyleV2Path ( )
static

Returns the path to default style (works as a starting point).

const QString QgsApplication::defaultThemePath ( )
static

Returns the path to the default theme directory.

const QString QgsApplication::donorsFilePath ( )
static

Returns the path to the donors file.

QgsApplication::endian_t QgsApplication::endian ( )
static

Returns whether this machine uses big or little endian.

bool QgsApplication::event ( QEvent *  event)
virtual

Watch for QFileOpenEvent.

void QgsApplication::exitQgis ( )
static

deletes provider registry and map layer registry

QIcon QgsApplication::getThemeIcon ( const QString &  theName)
static

Helper to get a theme icon.

It will fall back to the default theme if the active theme does not have the required icon.

QPixmap QgsApplication::getThemePixmap ( const QString &  theName)
static

Helper to get a theme icon as a pixmap.

It will fall back to the default theme if the active theme does not have the required icon.

const QString QgsApplication::helpAppPath ( )
static

Returns the path to the help application.

const QString QgsApplication::i18nPath ( )
static

Returns the path to the translation directory.

QString QgsApplication::iconPath ( QString  iconFile)
static

Returns path to the desired icon file.

First it tries to use the active theme path, then default theme path

const QString QgsApplication::iconsPath ( )
static

Returns the path to the icons image directory.

void QgsApplication::init ( QString  customConfigPath = QString())
static

This method initialises paths etc for QGIS.

Called by the ctor or call it manually when your app does not extend the QApplication class.

Note
you will probably want to call initQgis too to load the providers in the above case.
void QgsApplication::initQgis ( )
static

loads providers

static bool QgsApplication::isRunningFromBuildDir ( )
inlinestatic

Indicates whether running from build directory (not installed)

const QString QgsApplication::libexecPath ( )
static

Returns the path with utility executables (help viewer, crssync, ...)

const QString QgsApplication::libraryPath ( )
static

Returns the path containing qgis_core, qgis_gui, qgispython (and other) libraries.

const QString QgsApplication::licenceFilePath ( )
static

Returns the path to the licence file.

static int QgsApplication::maxThreads ( )
inlinestatic

Get maximum concurrent thread count.

Note
added in 2.4
bool QgsApplication::notify ( QObject *  receiver,
QEvent *  event 
)
virtual

Catch exceptions when sending event to receiver.

const QString QgsApplication::pkgDataPath ( )
static

Returns the common root path of all application data directories.

const QString QgsApplication::pluginPath ( )
static

Returns the path to the application plugin directory.

const QString QgsApplication::prefixPath ( )
static

Returns the path to the application prefix directory.

void QgsApplication::preNotify ( QObject *  receiver,
QEvent *  event,
bool *  done 
)
signal
Note
not available in python bindings
const QString QgsApplication::qgisMasterDbFilePath ( )
static

Returns the path to the master qgis.db file.

const QString QgsApplication::qgisSettingsDirPath ( )
static

Returns the path to the settings directory in user's home dir.

Returns the path to the settings directory in user's home dir

const QString QgsApplication::qgisUserDbFilePath ( )
static

Returns the path to the user qgis.db file.

void QgsApplication::registerOgrDrivers ( )
static

Register OGR drivers ensuring this only happens once.

This is a workaround for an issue with older gdal versions that caused duplicate driver name entries to appear in the list of registered drivers when QgsApplication::registerOgrDrivers was called multiple times.

QString QgsApplication::relativePathToAbsolutePath ( QString  rpath,
QString  targetPath 
)
static

Converts path relative to target to an absolute path.

QString QgsApplication::reportStyleSheet ( )
static

get a standard css style sheet for reports.

Typically you will use this method by doing: QString myStyle = QgsApplication::reportStyleSheet(); textBrowserReport->document()->setDefaultStyleSheet(myStyle);

Returns
QString containing the CSS 2.1 compliant stylesheet.
Note
you can use the special Qt extensions too, for example the gradient fills for backgrounds.
void QgsApplication::restoreGdalDriver ( QString  theDriver)
static

Sets the GDAL_SKIP environment variable to exclude the specified driver and then calls GDALDriverManager::AutoSkipDrivers() to unregister it.

The driver name should be the short format of the Gdal driver name e.g. GTIFF.

void QgsApplication::setDefaultSvgPaths ( const QStringList &  pathList)
static

Alters default svg paths - used by 3rd party apps.

void QgsApplication::setFileOpenEventReceiver ( QObject *  receiver)
static

Set the FileOpen event receiver.

void QgsApplication::setMaxThreads ( int  maxThreads)
static

Set maximum concurrent thread count.

Note
must be between 1 and #cores, -1 means use all available cores
added in 2.4
void QgsApplication::setPkgDataPath ( const QString &  thePkgDataPath)
static

Alters pkg data path - used by 3rd party apps.

void QgsApplication::setPluginPath ( const QString &  thePluginPath)
static

Alters plugin path - used by 3rd party apps.

void QgsApplication::setPrefixPath ( const QString &  thePrefixPath,
bool  useDefaultPaths = false 
)
static

Alters prefix path - used by 3rd party apps.

void QgsApplication::setThemeName ( const QString &  theThemeName)
static

Set the active theme to the specified theme.

The theme name should be a single word e.g. 'default','classic'. The theme search path usually will be pkgDataPath + "/themes/" + themName + "/" but plugin writers etc can use themeName() as a basis for searching for resources in their own datastores e.g. a Qt4 resource bundle.

Note
A basic test will be carried out to ensure the theme search path based on the supplied theme name exists. If it does not the theme name will be reverted to 'default'.

Set the theme path to the specified theme.

QString QgsApplication::showSettings ( )
static

Convenience function to get a summary of the paths used in this application instance useful for debugging mainly.

void QgsApplication::skipGdalDriver ( QString  theDriver)
static

Sets the GDAL_SKIP environment variable to include the specified driver and then calls GDALDriverManager::AutoSkipDrivers() to unregister it.

The driver name should be the short format of the Gdal driver name e.g. GTIFF.

static QStringList QgsApplication::skippedGdalDrivers ( )
inlinestatic

Returns the list of gdal drivers that should be skipped (based on GDAL_SKIP environment variable)

const QString QgsApplication::splashPath ( )
static

Returns the path to the splash screen image directory.

const QString QgsApplication::sponsorsFilePath ( )
static

Returns the path to the sponsors file.

const QString QgsApplication::srsDbFilePath ( )
static

Returns the path to the srs.db file.

const QStringList QgsApplication::svgPaths ( )
static

Returns the pathes to svg directories.

Returns the paths to the svg directories.

static const QMap<QString, QString> QgsApplication::systemEnvVars ( )
inlinestatic

Returns the system environment variables passed to application.

const QString QgsApplication::themeName ( )
static

Set the active theme to the specified theme.

The theme name should be a single word e.g. 'default','classic'. The theme search path usually will be pkgDataPath + "/themes/" + themName + "/" but plugin writers etc can use this method as a basis for searching for resources in their own datastores e.g. a Qt4 resource bundle.

Get the active theme name

const QString QgsApplication::translatorsFilePath ( )
static

Returns the path to the sponsors file.

const QString QgsApplication::userStyleV2Path ( )
static

Returns the path to user's style.

Member Data Documentation

const char * QgsApplication::QGIS_APPLICATION_NAME = "QGIS2"
static
const char * QgsApplication::QGIS_ORGANIZATION_DOMAIN = "qgis.org"
static
const char * QgsApplication::QGIS_ORGANIZATION_NAME = "QGIS"
static

The documentation for this class was generated from the following files: