QgsApplication Class Reference
[QGIS core library]

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

#include <qgsapplication.h>

List of all members.

Public Types

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

Public Member Functions

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

Static Public Member Functions

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 developerPath ()
 Returns the path to the developer image directory.
static const QString helpAppPath ()
 Returns the path to the help application.
static const QString msexportAppPath ()
 Returns the path to the mapserver export 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 qgisSpatialiteDbTemplatePath ()
 Returns the path to the spatialite template 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 QString svgPath ()
 Returns the paths to svg applications svg directory.
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 const QString userStyleV2Path ()
 Returns the path to user's style. Added in QGIS 1.4.
static const QString defaultStyleV2Path ()
 Returns the path to default style (works as a starting point). Added in QGIS 1.4.
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. Added in QGIS 1.5.
static void initQgis ()
 loads providers
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 Private Attributes

static QString mPrefixPath
static QString mPluginPath
static QString mPkgDataPath
static QString mThemeName
static QStringList mDefaultSvgPaths
static QString mConfigPath = QDir::homePath() + QString( "/.qgis/" )


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.

Definition at line 25 of file qgsapplication.h.


Member Typedef Documentation

constants for endian-ness


Member Enumeration Documentation

constants for endian-ness

Enumerator:
XDR 
NDR 

Definition at line 165 of file qgsapplication.h.


Constructor & Destructor Documentation

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

Note:
customConfigDir parameter added in v1.6

Definition at line 57 of file qgsapplication.cpp.

References mConfigPath, mDefaultSvgPaths, mPkgDataPath, qgisSettingsDirPath(), and setPrefixPath().

QgsApplication::~QgsApplication (  )  [virtual]

Definition at line 78 of file qgsapplication.cpp.


Member Function Documentation

bool QgsApplication::notify ( QObject *  receiver,
QEvent *  event 
) [virtual]

Catch exceptions when sending event to receiver.

Definition at line 82 of file qgsapplication.cpp.

References QgsException::what().

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.

Definition at line 173 of file qgsapplication.cpp.

References mThemeName.

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

Definition at line 189 of file qgsapplication.cpp.

References mThemeName.

Referenced by showSettings().

const QString QgsApplication::authorsFilePath (  )  [static]

Returns the path to the authors file.

Returns the path to the authors file.

Definition at line 196 of file qgsapplication.cpp.

References mPkgDataPath.

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.

Note:
this function was added in version 1.3
Returns the path to the contributors file.

Definition at line 203 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::sponsorsFilePath (  )  [static]

Returns the path to the sponsors file.

Note:
this function was added in version 1.2
Returns the path to the sponsors file.

Definition at line 210 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::donorsFilePath (  )  [static]

Returns the path to the donors file.

Note:
this function was added in version 1.2
Returns the path to the donors file.

Definition at line 218 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::translatorsFilePath (  )  [static]

Returns the path to the sponsors file.

Note:
This was added in QGIS 1.1
Returns the path to the sponsors file.
Note:
Added in QGIS 1.1

Definition at line 227 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::developerPath (  )  [static]

Returns the path to the developer image directory.

Returns the path to the developer image directory.

Definition at line 234 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::helpAppPath (  )  [static]

Returns the path to the help application.

Returns the path to the help application.

Definition at line 242 of file qgsapplication.cpp.

Referenced by QgsContextHelp::start().

const QString QgsApplication::msexportAppPath (  )  [static]

Returns the path to the mapserver export application.

Returns the path to the mapserverexport application.

Definition at line 254 of file qgsapplication.cpp.

const QString QgsApplication::i18nPath (  )  [static]

Returns the path to the translation directory.

Returns the path to the translation directory.

Definition at line 267 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::qgisMasterDbFilePath (  )  [static]

Returns the path to the master qgis.db file.

Returns the path to the master qgis.db file.

Definition at line 275 of file qgsapplication.cpp.

References mPkgDataPath.

Referenced by showSettings().

const QString QgsApplication::qgisSpatialiteDbTemplatePath (  )  [static]

Returns the path to the spatialite template db file.

Note:
added in 1.5
Returns the path to the spatialite template db file.

Definition at line 283 of file qgsapplication.cpp.

References mPkgDataPath.

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

Definition at line 291 of file qgsapplication.cpp.

References mConfigPath.

Referenced by QgsMapLayer::loadNamedStyle(), qgisUserDbFilePath(), QgsApplication(), QgsMapLayer::saveNamedStyle(), and userStyleV2Path().

const QString QgsApplication::qgisUserDbFilePath (  )  [static]

const QString QgsApplication::splashPath (  )  [static]

Returns the path to the splash screen image directory.

Returns the path to the splash screen image directory.

Definition at line 307 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::iconsPath (  )  [static]

Returns the path to the icons image directory.

Returns the path to the icons image directory.

Definition at line 315 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::srsDbFilePath (  )  [static]

const QStringList QgsApplication::svgPaths (  )  [static]

const QString QgsApplication::svgPath (  )  [static]

Returns the paths to svg applications svg directory.

Note:
deprecated since 1.4
Returns the path to the applications svg directories.

Definition at line 349 of file qgsapplication.cpp.

References mPkgDataPath.

const QString QgsApplication::prefixPath (  )  [static]

Returns the path to the application prefix directory.

Definition at line 137 of file qgsapplication.cpp.

References mPrefixPath.

const QString QgsApplication::pluginPath (  )  [static]

Returns the path to the application plugin directory.

Definition at line 141 of file qgsapplication.cpp.

References mPluginPath.

Referenced by initQgis().

const QString QgsApplication::pkgDataPath (  )  [static]

Returns the common root path of all application data directories.

Definition at line 145 of file qgsapplication.cpp.

References mPkgDataPath.

Referenced by QgsMapLayer::loadNamedStyle().

const QString QgsApplication::activeThemePath (  )  [static]

const QString QgsApplication::defaultThemePath (  )  [static]

Returns the path to the default theme directory.

Definition at line 149 of file qgsapplication.cpp.

Referenced by QgsComposerItem::drawSelectionBoxes(), iconPath(), and showSettings().

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

Note:
Added in 1.5

Definition at line 159 of file qgsapplication.cpp.

References activeThemePath(), and defaultThemePath().

const QString QgsApplication::userStyleV2Path (  )  [static]

Returns the path to user's style. Added in QGIS 1.4.

Definition at line 354 of file qgsapplication.cpp.

References qgisSettingsDirPath().

Referenced by QgsStyleV2::defaultStyle().

const QString QgsApplication::defaultStyleV2Path (  )  [static]

Returns the path to default style (works as a starting point). Added in QGIS 1.4.

Definition at line 359 of file qgsapplication.cpp.

References mPkgDataPath.

Referenced by QgsStyleV2::defaultStyle().

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

Alters prefix path - used by 3rd party apps.

Definition at line 105 of file qgsapplication.cpp.

References mPrefixPath, setPkgDataPath(), and setPluginPath().

Referenced by QgsApplication().

void QgsApplication::setPluginPath ( const QString  thePluginPath  )  [static]

Alters plugin path - used by 3rd party apps.

Definition at line 121 of file qgsapplication.cpp.

References mPluginPath.

Referenced by setPrefixPath().

void QgsApplication::setPkgDataPath ( const QString  thePkgDataPath  )  [static]

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

Definition at line 126 of file qgsapplication.cpp.

References mDefaultSvgPaths, and mPkgDataPath.

Referenced by setPrefixPath().

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

Alters default svg paths - used by 3rd party apps. Added in QGIS 1.5.

Definition at line 132 of file qgsapplication.cpp.

References mDefaultSvgPaths.

void QgsApplication::initQgis (  )  [static]

loads providers

Definition at line 369 of file qgsapplication.cpp.

References QgsMapLayerRegistry::instance(), QgsProviderRegistry::instance(), and pluginPath().

void QgsApplication::exitQgis (  )  [static]

deletes provider registry and map layer registry

Definition at line 378 of file qgsapplication.cpp.

References QgsProviderRegistry::instance(), and QgsMapLayerRegistry::instance().

QgsApplication::endian_t QgsApplication::endian (  )  [static]

Returns whether this machine uses big or little endian.

Definition at line 364 of file qgsapplication.cpp.

References NDR, and XDR.

Referenced by QgsGeometry::convertToMultiType(), and QgsGeometry::exportGeosToWkb().

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.

Definition at line 406 of file qgsapplication.cpp.

QString QgsApplication::showSettings (  )  [static]

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

Definition at line 384 of file qgsapplication.cpp.

References activeThemePath(), defaultThemePath(), mPkgDataPath, mPluginPath, mPrefixPath, qgisMasterDbFilePath(), svgPaths(), and themeName().

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.

Definition at line 478 of file qgsapplication.cpp.

Referenced by QgsVectorFileWriter::ogrDriverList(), QgsVectorFileWriter::QgsVectorFileWriter(), and QgsVectorFileWriter::supportedFiltersAndFormats().

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

Converts absolute path to path relative to target.

Note:
: this method was added in version 1.6

Definition at line 486 of file qgsapplication.cpp.

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

Converts path relative to target to an absolute path.

Note:
: this method was added in version 1.6

Definition at line 549 of file qgsapplication.cpp.


Member Data Documentation

QString QgsApplication::mPrefixPath [static, private]

Definition at line 203 of file qgsapplication.h.

Referenced by prefixPath(), setPrefixPath(), and showSettings().

QString QgsApplication::mPluginPath [static, private]

Definition at line 204 of file qgsapplication.h.

Referenced by pluginPath(), setPluginPath(), and showSettings().

QString QgsApplication::mPkgDataPath [static, private]

QString QgsApplication::mThemeName [static, private]

Definition at line 206 of file qgsapplication.h.

Referenced by activeThemePath(), setThemeName(), and themeName().

QStringList QgsApplication::mDefaultSvgPaths [static, private]

Definition at line 207 of file qgsapplication.h.

Referenced by QgsApplication(), setDefaultSvgPaths(), setPkgDataPath(), and svgPaths().

QString QgsApplication::mConfigPath = QDir::homePath() + QString( "/.qgis/" ) [static, private]

Definition at line 209 of file qgsapplication.h.

Referenced by qgisSettingsDirPath(), and QgsApplication().


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

Generated on Sat Feb 4 19:17:23 2012 for Quantum GIS API Documentation by  doxygen 1.5.6