QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsapplication.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsapplication.cpp - Accessors for application-wide data
3  --------------------------------------
4  Date : 02-Jan-2006
5  Copyright : (C) 2006 by Tom Elwertowski
6  Email : telwertowski at users dot sourceforge dot net
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 
16 #include "qgsapplication.h"
17 #include "qgsauthmanager.h"
18 #include "qgscrscache.h"
20 #include "qgsexception.h"
21 #include "qgsgeometry.h"
22 #include "qgslogger.h"
23 #include "qgsmaplayerregistry.h"
25 #include "qgsproviderregistry.h"
26 #include "qgsexpression.h"
27 
28 #include <QDir>
29 #include <QFile>
30 #include <QFileInfo>
31 #include <QFileOpenEvent>
32 #include <QMessageBox>
33 #include <QPalette>
34 #include <QProcess>
35 #include <QSettings>
36 #include <QIcon>
37 #include <QPixmap>
38 #include <QThreadPool>
39 
40 #ifndef Q_OS_WIN
41 #include <netinet/in.h>
42 #include <pwd.h>
43 #else
44 #include <winsock.h>
45 #include <windows.h>
46 #include <Lmcons.h>
47 #define SECURITY_WIN32
48 #include <Security.h>
49 #pragma comment( lib, "Secur32.lib" )
50 #endif
51 
52 #include "qgsconfig.h"
53 
54 #include <gdal.h>
55 #include <ogr_api.h>
56 #include <cpl_conv.h> // for setting gdal options
57 #include <sqlite3.h>
58 
59 QObject * ABISYM( QgsApplication::mFileOpenEventReceiver );
60 QStringList ABISYM( QgsApplication::mFileOpenEventList );
61 QString ABISYM( QgsApplication::mPrefixPath );
62 QString ABISYM( QgsApplication::mPluginPath );
63 QString ABISYM( QgsApplication::mPkgDataPath );
64 QString ABISYM( QgsApplication::mLibraryPath );
65 QString ABISYM( QgsApplication::mLibexecPath );
66 QString ABISYM( QgsApplication::mThemeName );
67 QString ABISYM( QgsApplication::mUIThemeName );
68 QStringList ABISYM( QgsApplication::mDefaultSvgPaths );
69 QMap<QString, QString> ABISYM( QgsApplication::mSystemEnvVars );
70 QString ABISYM( QgsApplication::mConfigPath );
71 bool ABISYM( QgsApplication::mRunningFromBuildDir ) = false;
72 QString ABISYM( QgsApplication::mBuildSourcePath );
73 #ifdef _MSC_VER
74 QString ABISYM( QgsApplication::mCfgIntDir );
75 #endif
76 QString ABISYM( QgsApplication::mBuildOutputPath );
77 QStringList ABISYM( QgsApplication::mGdalSkipList );
78 int ABISYM( QgsApplication::mMaxThreads );
79 QString ABISYM( QgsApplication::mAuthDbDirPath );
80 
81 QString QgsApplication::sUserName;
82 QString QgsApplication::sUserFullName;
83 QString QgsApplication::sPlatformName = "desktop";
84 
85 const char* QgsApplication::QGIS_ORGANIZATION_NAME = "QGIS";
86 const char* QgsApplication::QGIS_ORGANIZATION_DOMAIN = "qgis.org";
87 const char* QgsApplication::QGIS_APPLICATION_NAME = "QGIS2";
88 
102 QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled, const QString& customConfigPath, const QString& platformName )
103  : QApplication( argc, argv, GUIenabled )
104 {
105  sPlatformName = platformName;
106 
107  init( customConfigPath ); // init can also be called directly by e.g. unit tests that don't inherit QApplication.
108 }
109 
110 void QgsApplication::init( QString customConfigPath )
111 {
112  if ( customConfigPath.isEmpty() )
113  {
114  if ( getenv( "QGIS_CUSTOM_CONFIG_PATH" ) )
115  {
116  customConfigPath = getenv( "QGIS_CUSTOM_CONFIG_PATH" );
117  }
118  else
119  {
120  customConfigPath = QString( "%1/.qgis%2/" ).arg( QDir::homePath() ).arg( QGis::QGIS_VERSION_INT / 10000 );
121  }
122  }
123 
124  qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
125 
126  QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
127  // QgsDebugMsg( QString( "prefixPath(): %1" ).arg( prefixPath ) );
128 
129  // check if QGIS is run from build directory (not the install directory)
130  QFile f;
131  // "/../../.." is for Mac bundled app in build directory
132  Q_FOREACH ( const QString& path, QStringList() << "" << "/.." << "/bin" << "/../../.." )
133  {
134  f.setFileName( prefixPath + path + "/qgisbuildpath.txt" );
135  if ( f.exists() )
136  break;
137  }
138  if ( f.exists() && f.open( QIODevice::ReadOnly ) )
139  {
140  ABISYM( mRunningFromBuildDir ) = true;
141  ABISYM( mBuildSourcePath ) = f.readLine().trimmed();
142  ABISYM( mBuildOutputPath ) = f.readLine().trimmed();
143  qDebug( "Running from build directory!" );
144  qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toUtf8().data() );
145  qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toUtf8().data() );
146 #ifdef _MSC_VER
147  ABISYM( mCfgIntDir ) = prefixPath.split( '/', QString::SkipEmptyParts ).last();
148  qDebug( "- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() );
149 #endif
150  }
151 
152  if ( ABISYM( mRunningFromBuildDir ) )
153  {
154  // we run from source directory - not installed to destination (specified prefix)
155  ABISYM( mPrefixPath ) = QString(); // set invalid path
156 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
157  setPluginPath( ABISYM( mBuildOutputPath ) + '/' + QString( QGIS_PLUGIN_SUBDIR ) + '/' + ABISYM( mCfgIntDir ) );
158 #else
159  setPluginPath( ABISYM( mBuildOutputPath ) + '/' + QString( QGIS_PLUGIN_SUBDIR ) );
160 #endif
161  setPkgDataPath( ABISYM( mBuildSourcePath ) ); // directly source path - used for: doc, resources, svg
162  ABISYM( mLibraryPath ) = ABISYM( mBuildOutputPath ) + '/' + QGIS_LIB_SUBDIR + '/';
163 #if defined(_MSC_VER) && !defined(USING_NMAKE) && !defined(USING_NINJA)
164  ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) + '/' + QGIS_LIBEXEC_SUBDIR + '/' + ABISYM( mCfgIntDir ) + '/';
165 #else
166  ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) + '/' + QGIS_LIBEXEC_SUBDIR + '/';
167 #endif
168  }
169  else
170  {
171  char *prefixPath = getenv( "QGIS_PREFIX_PATH" );
172  if ( !prefixPath )
173  {
174 #if defined(Q_OS_MACX) || defined(Q_OS_WIN)
176 #elif defined(ANDROID)
177  // this is "/data/data/org.qgis.qgis" in android
178  QDir myDir( QDir::homePath() );
179  myDir.cdUp();
180  QString myPrefix = myDir.absolutePath();
181  setPrefixPath( myPrefix, true );
182 #else
183  QDir myDir( applicationDirPath() );
184  myDir.cdUp();
185  QString myPrefix = myDir.absolutePath();
186  setPrefixPath( myPrefix, true );
187 #endif
188  }
189  else
190  {
191  setPrefixPath( prefixPath, true );
192  }
193  }
194 
195  if ( !customConfigPath.isEmpty() )
196  {
197  ABISYM( mConfigPath ) = customConfigPath + '/'; // make sure trailing slash is included
198  }
199 
200  ABISYM( mDefaultSvgPaths ) << qgisSettingsDirPath() + QLatin1String( "svg/" );
201 
202  ABISYM( mAuthDbDirPath ) = qgisSettingsDirPath();
203  if ( getenv( "QGIS_AUTH_DB_DIR_PATH" ) )
204  {
205  setAuthDbDirPath( getenv( "QGIS_AUTH_DB_DIR_PATH" ) );
206  }
207 
208 
209  // store system environment variables passed to application, before they are adjusted
210  QMap<QString, QString> systemEnvVarMap;
211  QString passfile( "QGIS_AUTH_PASSWORD_FILE" ); // QString, for comparison
212  Q_FOREACH ( const QString &varStr, QProcess::systemEnvironment() )
213  {
214  int pos = varStr.indexOf( QLatin1Char( '=' ) );
215  if ( pos == -1 )
216  continue;
217  QString varStrName = varStr.left( pos );
218  QString varStrValue = varStr.mid( pos + 1 );
219  if ( varStrName != passfile )
220  {
221  systemEnvVarMap.insert( varStrName, varStrValue );
222  }
223  }
224  ABISYM( mSystemEnvVars ) = systemEnvVarMap;
225 
226  // allow Qt to search for Qt plugins (e.g. sqldrivers) in our plugin directory
228 
229  // set max. thread count to -1
230  // this should be read from QSettings but we don't know where they are at this point
231  // so we read actual value in main.cpp
232  ABISYM( mMaxThreads ) = -1;
233 }
234 
236 {
237 }
238 
240 {
241  bool done = false;
242  if ( event->type() == QEvent::FileOpen )
243  {
244  // handle FileOpen event (double clicking a file icon in Mac OS X Finder)
245  if ( ABISYM( mFileOpenEventReceiver ) )
246  {
247  // Forward event to main window.
248  done = notify( ABISYM( mFileOpenEventReceiver ), event );
249  }
250  else
251  {
252  // Store filename because receiver has not registered yet.
253  // If QGIS has been launched by double clicking a file icon, FileOpen will be
254  // the first event; the main window is not yet ready to handle the event.
255  ABISYM( mFileOpenEventList ).append( static_cast<QFileOpenEvent *>( event )->file() );
256  done = true;
257  }
258  }
259  else
260  {
261  // pass other events to base class
262  done = QApplication::event( event );
263  }
264  return done;
265 }
266 
268 {
269  bool done = false;
270  // Crashes in customization (especially on Mac), if we're not in the main/UI thread, see #5597
271  if ( thread() == receiver->thread() )
272  emit preNotify( receiver, event, &done );
273 
274  if ( done )
275  return true;
276 
277  // Send event to receiver and catch unhandled exceptions
278  done = true;
279  try
280  {
281  done = QApplication::notify( receiver, event );
282  }
283  catch ( QgsException & e )
284  {
285  QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
286  if ( qApp->thread() == QThread::currentThread() )
287  QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
288  }
289  catch ( std::exception & e )
290  {
291  QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
292  if ( qApp->thread() == QThread::currentThread() )
293  QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() );
294  }
295  catch ( ... )
296  {
297  QgsDebugMsg( "Caught unhandled unknown exception" );
298  if ( qApp->thread() == QThread::currentThread() )
299  QMessageBox::critical( activeWindow(), tr( "Exception" ), tr( "unknown exception" ) );
300  }
301 
302  return done;
303 }
304 
306 {
307  // Set receiver for FileOpen events
308  ABISYM( mFileOpenEventReceiver ) = receiver;
309  // Propagate any events collected before the receiver has registered.
310  if ( ABISYM( mFileOpenEventList ).count() > 0 )
311  {
312  QStringListIterator i( ABISYM( mFileOpenEventList ) );
313  while ( i.hasNext() )
314  {
315  QFileOpenEvent foe( i.next() );
316  QgsApplication::sendEvent( ABISYM( mFileOpenEventReceiver ), &foe );
317  }
318  ABISYM( mFileOpenEventList ).clear();
319  }
320 }
321 
322 void QgsApplication::setPrefixPath( const QString &thePrefixPath, bool useDefaultPaths )
323 {
324  ABISYM( mPrefixPath ) = thePrefixPath;
325 #if defined(_MSC_VER)
326  if ( ABISYM( mPrefixPath ).endsWith( "/bin" ) )
327  {
328  ABISYM( mPrefixPath ).chop( 4 );
329  }
330 #endif
331  if ( useDefaultPaths && !ABISYM( mRunningFromBuildDir ) )
332  {
333  setPluginPath( ABISYM( mPrefixPath ) + '/' + QString( QGIS_PLUGIN_SUBDIR ) );
334  setPkgDataPath( ABISYM( mPrefixPath ) + '/' + QString( QGIS_DATA_SUBDIR ) );
335  }
336  ABISYM( mLibraryPath ) = ABISYM( mPrefixPath ) + '/' + QGIS_LIB_SUBDIR + '/';
337  ABISYM( mLibexecPath ) = ABISYM( mPrefixPath ) + '/' + QGIS_LIBEXEC_SUBDIR + '/';
338 }
339 
340 void QgsApplication::setPluginPath( const QString &thePluginPath )
341 {
342  ABISYM( mPluginPath ) = thePluginPath;
343 }
344 
345 void QgsApplication::setPkgDataPath( const QString &thePkgDataPath )
346 {
347  ABISYM( mPkgDataPath ) = thePkgDataPath;
348  QString mySvgPath = thePkgDataPath + ( ABISYM( mRunningFromBuildDir ) ? "/images/svg/" : "/svg/" );
349  // avoid duplicate entries
350  if ( !ABISYM( mDefaultSvgPaths ).contains( mySvgPath ) )
351  ABISYM( mDefaultSvgPaths ) << mySvgPath;
352 }
353 
355 {
356  ABISYM( mDefaultSvgPaths ) = pathList;
357 }
358 
359 void QgsApplication::setAuthDbDirPath( const QString& theAuthDbDirPath )
360 {
361  QFileInfo fi( theAuthDbDirPath );
362  if ( fi.exists() && fi.isDir() && fi.isWritable() )
363  {
364  ABISYM( mAuthDbDirPath ) = fi.canonicalFilePath() + QDir::separator();
365  }
366 }
367 
369 {
370  if ( ABISYM( mRunningFromBuildDir ) )
371  {
372  static bool once = true;
373  if ( once )
374  qWarning( "!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" );
375  once = false;
376  }
377 
378  return ABISYM( mPrefixPath );
379 }
381 {
382  return ABISYM( mPluginPath );
383 }
385 {
386  return ABISYM( mPkgDataPath );
387 }
389 {
390  return ":/images/themes/default/";
391 }
393 {
394  return userThemesFolder() + QDir::separator() + themeName() + QDir::separator() + "icons/";
395 }
396 
398 {
399  return iconsPath() + "qgis-icon-60x60.png";
400 }
401 
403 {
404  // try active theme
405  QString path = activeThemePath();
406  if ( QFile::exists( path + iconFile ) )
407  return path + iconFile;
408 
409  // use default theme
410  return defaultThemePath() + iconFile;
411 }
412 
414 {
415  QgsApplication* app = qobject_cast<QgsApplication*>( instance() );
416  if ( app && app->mIconCache.contains( theName ) )
417  return app->mIconCache.value( theName );
418 
419  QIcon icon;
420 
421  QString myPreferredPath = activeThemePath() + QDir::separator() + theName;
422  QString myDefaultPath = defaultThemePath() + QDir::separator() + theName;
423  if ( QFile::exists( myPreferredPath ) )
424  {
425  icon = QIcon( myPreferredPath );
426  }
427  else if ( QFile::exists( myDefaultPath ) )
428  {
429  //could still return an empty icon if it
430  //doesnt exist in the default theme either!
431  icon = QIcon( myDefaultPath );
432  }
433  else
434  {
435  icon = QIcon();
436  }
437 
438  if ( app )
439  app->mIconCache.insert( theName, icon );
440  return icon;
441 }
442 
443 // TODO: add some caching mechanism ?
445 {
446  QString myPreferredPath = activeThemePath() + QDir::separator() + theName;
447  QString myDefaultPath = defaultThemePath() + QDir::separator() + theName;
448  if ( QFile::exists( myPreferredPath ) )
449  {
450  return QPixmap( myPreferredPath );
451  }
452  else
453  {
454  //could still return an empty icon if it
455  //doesnt exist in the default theme either!
456  return QPixmap( myDefaultPath );
457  }
458 }
459 
463 void QgsApplication::setThemeName( const QString &theThemeName )
464 {
465  ABISYM( mThemeName ) = theThemeName;
466 }
471 {
472  return ABISYM( mThemeName );
473 }
474 
476 {
477  // Loop all style sheets, find matching name, load it.
479  QString themename = themeName;
480  if ( !themes.contains( themename ) )
481  themename = "default";
482 
483  QString path = themes[themename];
484  QString stylesheetname = path + "/style.qss";
485  QString autostylesheet = stylesheetname + ".auto";
486 
487  QFile file( stylesheetname );
488  QFile variablesfile( path + "/variables.qss" );
489  QFile fileout( autostylesheet );
490 
491  QFileInfo variableInfo( variablesfile );
492 
493  if ( variableInfo.exists() && variablesfile.open( QIODevice::ReadOnly ) )
494  {
495  if ( !file.open( QIODevice::ReadOnly ) || !fileout.open( QIODevice::WriteOnly | QIODevice::Text ) )
496  {
497  return;
498  }
499 
500  QHash<QString, QString> variables;
501  QString styledata = file.readAll();
502  QTextStream in( &variablesfile );
503  while ( !in.atEnd() )
504  {
505  QString line = in.readLine();
506  // This is is a variable
507  if ( line.startsWith( '@' ) )
508  {
509  int index = line.indexOf( ':' );
510  QString name = line.mid( 0, index );
511  QString value = line.mid( index + 1, line.length() );
512  styledata.replace( name, value );
513  }
514  }
515  variablesfile.close();
516  QTextStream out( &fileout );
517  out << styledata;
518  fileout.close();
519  file.close();
520  stylesheetname = autostylesheet;
521  }
522 
523  QString styleSheet = QLatin1String( "file:///" );
524  styleSheet.append( stylesheetname );
525  qApp->setStyleSheet( styleSheet );
526  setThemeName( themename );
527 }
528 
530 {
532  QHash<QString, QString> mapping;
533  mapping.insert( "default", "" );
534  Q_FOREACH ( const QString& path, paths )
535  {
536  QDir folder( path );
537  QFileInfoList styleFiles = folder.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot );
538  Q_FOREACH ( const QFileInfo& info, styleFiles )
539  {
540  QFileInfo styleFile( info.absoluteFilePath() + "/style.qss" );
541  if ( !styleFile.exists() )
542  continue;
543 
544  QString name = info.baseName();
545  QString path = info.absoluteFilePath();
546  mapping.insert( name, path );
547  }
548  }
549  return mapping;
550 }
551 
556 {
557  return ABISYM( mPkgDataPath ) + QLatin1String( "/doc/AUTHORS" );
558 }
563 {
564  return ABISYM( mPkgDataPath ) + QLatin1String( "/doc/CONTRIBUTORS" );
565 }
567 {
568  return ABISYM( mPkgDataPath ) + QLatin1String( "/doc/developersmap.html" );
569 }
570 
575 {
576  return ABISYM( mPkgDataPath ) + QLatin1String( "/doc/SPONSORS" );
577 }
578 
583 {
584  return ABISYM( mPkgDataPath ) + QLatin1String( "/doc/DONORS" );
585 }
586 
589 {
590  return ABISYM( mPkgDataPath ) + QLatin1String( "/doc/TRANSLATORS" );
591 }
592 
595 {
596  return ABISYM( mPkgDataPath ) + QLatin1String( "/doc/LICENSE" );
597 }
598 
603 {
605 #ifdef Q_OS_MACX
606  helpAppPath = applicationDirPath() + "/bin/qgis_help.app/Contents/MacOS";
607 #else
608  helpAppPath = libexecPath();
609 #endif
610  helpAppPath += "/qgis_help";
611 #ifdef Q_OS_WIN
612  helpAppPath += ".exe";
613 #endif
614  return helpAppPath;
615 }
620 {
621  if ( ABISYM( mRunningFromBuildDir ) )
622  return ABISYM( mBuildOutputPath ) + QLatin1String( "/i18n" );
623  else
624  return ABISYM( mPkgDataPath ) + QLatin1String( "/i18n/" );
625 }
626 
631 {
632  return ABISYM( mPkgDataPath ) + QLatin1String( "/resources/qgis.db" );
633 }
634 
639 {
640  return ABISYM( mConfigPath );
641 }
642 
647 {
648  return qgisSettingsDirPath() + QLatin1String( "qgis.db" );
649 }
650 
655 {
656  return ABISYM( mAuthDbDirPath ) + QLatin1String( "qgis-auth.db" );
657 }
658 
663 {
664  return QString( ":/images/splash/" );
665 }
666 
671 {
672  return ABISYM( mPkgDataPath ) + QLatin1String( "/images/icons/" );
673 }
678 {
679  if ( ABISYM( mRunningFromBuildDir ) )
680  {
681  QString tempCopy = QDir::tempPath() + "/srs.db";
682 
683  if ( !QFile( tempCopy ).exists() )
684  {
685  QFile f( ABISYM( mPkgDataPath ) + "/resources/srs.db" );
686  if ( !f.copy( tempCopy ) )
687  {
688  qFatal( "Could not create temporary copy" );
689  }
690  }
691 
692  return tempCopy;
693  }
694  else
695  {
696  return ABISYM( mPkgDataPath ) + QLatin1String( "/resources/srs.db" );
697  }
698 }
699 
704 {
705  //local directories to search when looking for an SVG with a given basename
706  //defined by user in options dialog
707  QSettings settings;
708  QStringList myPathList;
709  QString myPaths = settings.value( "svg/searchPathsForSVG", QString() ).toString();
710  if ( !myPaths.isEmpty() )
711  {
712  myPathList = myPaths.split( '|' );
713  }
714 
715  // maintain user set order while stripping duplicates
716  QStringList paths;
717  Q_FOREACH ( const QString& path, myPathList )
718  {
719  if ( !paths.contains( path ) )
720  paths.append( path );
721  }
722  Q_FOREACH ( const QString& path, ABISYM( mDefaultSvgPaths ) )
723  {
724  if ( !paths.contains( path ) )
725  paths.append( path );
726  }
727 
728  return paths;
729 }
730 
735 {
736  //local directories to search when looking for an SVG with a given basename
737  //defined by user in options dialog
738  QSettings settings;
739  QStringList myPathList;
740  QString myPaths = settings.value( "composer/searchPathsForTemplates", QString() ).toString();
741  if ( !myPaths.isEmpty() )
742  {
743  myPathList = myPaths.split( '|' );
744  }
745 
746  return myPathList;
747 }
748 
750 {
751  return qgisSettingsDirPath() + QLatin1String( "symbology-ng-style.db" );
752 }
753 
755 {
756  return QRegExp( "^[A-Za-z_][A-Za-z0-9\\._-]*" );
757 }
758 
760 {
761  if ( !sUserName.isEmpty() )
762  return sUserName;
763 
764 #ifdef Q_OS_WIN
765  TCHAR name [ UNLEN + 1 ];
766  DWORD size = UNLEN + 1;
767 
768  if ( GetUserName(( TCHAR* )name, &size ) )
769  {
770  sUserName = QString( name );
771  }
772 
773 #else
774  QProcess process;
775 
776  process.start( "whoami" );
777  process.waitForFinished();
778  sUserName = process.readAllStandardOutput().trimmed();
779 #endif
780 
781  if ( !sUserName.isEmpty() )
782  return sUserName;
783 
784  //backup plan - use environment variables
785  sUserName = qgetenv( "USER" );
786  if ( !sUserName.isEmpty() )
787  return sUserName;
788 
789  //last resort
790  sUserName = qgetenv( "USERNAME" );
791  return sUserName;
792 }
793 
795 {
796  if ( !sUserFullName.isEmpty() )
797  return sUserFullName;
798 
799 #ifdef Q_OS_WIN
800  TCHAR name [ UNLEN + 1 ];
801  DWORD size = UNLEN + 1;
802 
803  //note - this only works for accounts connected to domain
804  if ( GetUserNameEx( NameDisplay, ( TCHAR* )name, &size ) )
805  {
806  sUserFullName = QString( name );
807  }
808 
809  //fall back to login name
810  if ( sUserFullName.isEmpty() )
811  sUserFullName = userLoginName();
812 #elif defined(Q_OS_ANDROID)
813  sUserFullName = "Not available";
814 #else
815  struct passwd *p = getpwuid( getuid() );
816 
817  if ( p )
818  {
819  QString gecosName = QString( p->pw_gecos );
820  sUserFullName = gecosName.left( gecosName.indexOf( ',', 0 ) );
821  }
822 
823 #endif
824 
825  return sUserFullName;
826 }
827 
829 {
830 #if defined(Q_OS_ANDROID)
831  return QLatin1String( "android" );
832 #elif defined(Q_OS_MAC)
833  return QLatin1String( "osx" );
834 #elif defined(Q_OS_WIN)
835  return QLatin1String( "windows" );
836 #elif defined(Q_OS_LINUX)
837  return QLatin1String( "linux" );
838 #else
839  return QLatin1String( "unknown" );
840 #endif
841 }
842 
844 {
845  return sPlatformName;
846 }
847 
849 {
850  return qgisSettingsDirPath() + QLatin1String( "/themes" );
851 }
852 
854 {
855  return ABISYM( mPkgDataPath ) + QLatin1String( "/resources/symbology-ng-style.db" );
856 }
857 
859 {
860  return ABISYM( mPkgDataPath ) + QLatin1String( "/resources/themes" );
861 }
862 
864 {
865  return ABISYM( mLibraryPath );
866 }
867 
869 {
870  return ABISYM( mLibexecPath );
871 }
872 
874 {
875  return ( htonl( 1 ) == 1 ) ? XDR : NDR;
876 }
877 
879 {
880  // set the provider plugin path (this creates provider registry)
882 
883  // create map layer registry if doesn't exist
885 
886  // initialize authentication manager and connect to database
888 }
889 
891 {
892  delete QgsAuthManager::instance();
893 
894  //Ensure that all remaining deleteLater QObjects are actually deleted before we exit.
895  //This isn't strictly necessary (since we're exiting anyway) but doing so prevents a lot of
896  //LeakSanitiser noise which hides real issues
897  QgsApplication::sendPostedEvents( nullptr, QEvent::DeferredDelete );
898 
900 
901  //delete all registered functions from expression engine (see above comment)
903 
904  // tear-down GDAL/OGR
905  OGRCleanupAll();
906  GDALDestroyDriverManager();
907 }
908 
910 {
911  QString myEnvironmentVar( getenv( "QGIS_PREFIX_PATH" ) );
912  QString myState = tr( "Application state:\n"
913  "QGIS_PREFIX_PATH env var:\t\t%1\n"
914  "Prefix:\t\t%2\n"
915  "Plugin Path:\t\t%3\n"
916  "Package Data Path:\t%4\n"
917  "Active Theme Name:\t%5\n"
918  "Active Theme Path:\t%6\n"
919  "Default Theme Path:\t%7\n"
920  "SVG Search Paths:\t%8\n"
921  "User DB Path:\t%9\n"
922  "Auth DB Path:\t%10\n" )
923  .arg( myEnvironmentVar,
924  prefixPath(),
925  pluginPath(),
926  pkgDataPath(),
927  themeName(),
928  activeThemePath(),
930  svgPaths().join( tr( "\n\t\t", "match indentation of application state" ) ),
932  .arg( qgisAuthDbFilePath() );
933  return myState;
934 }
935 
937 {
938  //
939  // Make the style sheet desktop preferences aware by using qappliation
940  // palette as a basis for colors where appropriate
941  //
942 // QColor myColor1 = palette().highlight().color();
943  QColor myColor1( Qt::lightGray );
944  QColor myColor2 = myColor1;
945  myColor2 = myColor2.lighter( 110 ); //10% lighter
946  QString myStyle;
947  myStyle = "p.glossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, "
948  " stop: 0 " + myColor1.name() + ","
949  " stop: 0.1 " + myColor2.name() + ","
950  " stop: 0.5 " + myColor1.name() + ","
951  " stop: 0.9 " + myColor2.name() + ","
952  " stop: 1 " + myColor1.name() + ");"
953  " color: black;"
954  " padding-left: 4px;"
955  " padding-top: 20px;"
956  " padding-bottom: 8px;"
957  " border: 1px solid #6c6c6c;"
958  "}"
959  "p.subheaderglossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, "
960  " stop: 0 " + myColor1.name() + ","
961  " stop: 0.1 " + myColor2.name() + ","
962  " stop: 0.5 " + myColor1.name() + ","
963  " stop: 0.9 " + myColor2.name() + ","
964  " stop: 1 " + myColor1.name() + ");"
965  " font-weight: bold;"
966  " font-size: medium;"
967  " line-height: 1.1em;"
968  " width: 100%;"
969  " color: black;"
970  " padding-left: 4px;"
971  " padding-right: 4px;"
972  " padding-top: 20px;"
973  " padding-bottom: 8px;"
974  " border: 1px solid #6c6c6c;"
975  "}"
976  "th.glossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, "
977  " stop: 0 " + myColor1.name() + ","
978  " stop: 0.1 " + myColor2.name() + ","
979  " stop: 0.5 " + myColor1.name() + ","
980  " stop: 0.9 " + myColor2.name() + ","
981  " stop: 1 " + myColor1.name() + ");"
982  " color: black;"
983  " border: 1px solid #6c6c6c;"
984  "}"
985  ".overview{ font: 1.82em; font-weight: bold;}"
986  "body{ background: white;"
987  " color: black;"
988  " font-family: arial,sans-serif;"
989  "}"
990  "h1{ background-color: #F6F6F6;"
991  " color: #8FB171; "
992  " font-size: x-large; "
993  " font-weight: normal;"
994  " font-family: luxi serif, georgia, times new roman, times, serif;"
995  " background: none;"
996  " padding: 0.75em 0 0;"
997  " margin: 0;"
998  " line-height: 3em;"
999  "}"
1000  "h2{ background-color: #F6F6F6;"
1001  " color: #8FB171; "
1002  " font-size: medium; "
1003  " font-weight: normal;"
1004  " font-family: luxi serif, georgia, times new roman, times, serif;"
1005  " background: none;"
1006  " padding: 0.75em 0 0;"
1007  " margin: 0;"
1008  " line-height: 1.1em;"
1009  "}"
1010  "h3{ background-color: #F6F6F6;"
1011  " color: #729FCF;"
1012  " font-family: luxi serif, georgia, times new roman, times, serif;"
1013  " font-weight: bold;"
1014  " font-size: large;"
1015  " text-align: right;"
1016  " border-bottom: 5px solid #DCEB5C;"
1017  "}"
1018  "h4{ background-color: #F6F6F6;"
1019  " color: #729FCF;"
1020  " font-family: luxi serif, georgia, times new roman, times, serif;"
1021  " font-weight: bold;"
1022  " font-size: medium;"
1023  " text-align: right;"
1024  "}"
1025  "h5{ background-color: #F6F6F6;"
1026  " color: #729FCF;"
1027  " font-family: luxi serif, georgia, times new roman, times, serif;"
1028  " font-weight: bold;"
1029  " font-size: small;"
1030  " text-align: right;"
1031  "}"
1032  "a{ color: #729FCF;"
1033  " font-family: arial,sans-serif;"
1034  " font-size: small;"
1035  "}"
1036  "label{ background-color: #FFFFCC;"
1037  " border: 1px solid black;"
1038  " margin: 1px;"
1039  " padding: 0px 3px; "
1040  " font-size: small;"
1041  "}";
1042  return myStyle;
1043 }
1044 
1046 {
1047  if ( 0 >= OGRGetDriverCount() )
1048  {
1049  OGRRegisterAll();
1050  }
1051 }
1052 
1054 {
1055  QString aPathUrl = aPath;
1056  QString tPathUrl = targetPath;
1057 #if defined( Q_OS_WIN )
1058  const Qt::CaseSensitivity cs = Qt::CaseInsensitive;
1059 
1060  aPathUrl.replace( '\\', '/' );
1061  if ( aPathUrl.startsWith( "//" ) )
1062  {
1063  // keep UNC prefix
1064  aPathUrl = "\\\\" + aPathUrl.mid( 2 );
1065  }
1066 
1067  tPathUrl.replace( '\\', '/' );
1068  if ( tPathUrl.startsWith( "//" ) )
1069  {
1070  // keep UNC prefix
1071  tPathUrl = "\\\\" + tPathUrl.mid( 2 );
1072  }
1073 #else
1074  const Qt::CaseSensitivity cs = Qt::CaseSensitive;
1075 #endif
1076 
1077  QStringList targetElems = tPathUrl.split( '/', QString::SkipEmptyParts );
1078  QStringList aPathElems = aPathUrl.split( '/', QString::SkipEmptyParts );
1079 
1080  targetElems.removeAll( "." );
1081  aPathElems.removeAll( "." );
1082 
1083  // remove common part
1084  int n = 0;
1085  while ( !aPathElems.isEmpty() &&
1086  !targetElems.isEmpty() &&
1087  aPathElems[0].compare( targetElems[0], cs ) == 0 )
1088  {
1089  aPathElems.removeFirst();
1090  targetElems.removeFirst();
1091  n++;
1092  }
1093 
1094  if ( n == 0 )
1095  {
1096  // no common parts; might not even be a file
1097  return aPathUrl;
1098  }
1099 
1100  if ( !targetElems.isEmpty() )
1101  {
1102  // go up to the common directory
1103  for ( int i = 0; i < targetElems.size(); i++ )
1104  {
1105  aPathElems.insert( 0, ".." );
1106  }
1107  }
1108  else
1109  {
1110  // let it start with . nevertheless,
1111  // so relative path always start with either ./ or ../
1112  aPathElems.insert( 0, "." );
1113  }
1114 
1115  return aPathElems.join( "/" );
1116 }
1117 
1119 {
1120  // relative path should always start with ./ or ../
1121  if ( !rpath.startsWith( "./" ) && !rpath.startsWith( "../" ) )
1122  {
1123  return rpath;
1124  }
1125 
1126  QString rPathUrl = rpath;
1127  QString targetPathUrl = targetPath;
1128 
1129 #if defined(Q_OS_WIN)
1130  rPathUrl.replace( '\\', '/' );
1131  targetPathUrl.replace( '\\', '/' );
1132 
1133  bool uncPath = targetPathUrl.startsWith( "//" );
1134 #endif
1135 
1136  QStringList srcElems = rPathUrl.split( '/', QString::SkipEmptyParts );
1137  QStringList targetElems = targetPathUrl.split( '/', QString::SkipEmptyParts );
1138 
1139 #if defined(Q_OS_WIN)
1140  if ( uncPath )
1141  {
1142  targetElems.insert( 0, "" );
1143  targetElems.insert( 0, "" );
1144  }
1145 #endif
1146 
1147  // append source path elements
1148  targetElems << srcElems;
1149  targetElems.removeAll( "." );
1150 
1151  // resolve ..
1152  int pos;
1153  while (( pos = targetElems.indexOf( ".." ) ) > 0 )
1154  {
1155  // remove preceding element and ..
1156  targetElems.removeAt( pos - 1 );
1157  targetElems.removeAt( pos - 1 );
1158  }
1159 
1160 #if !defined(Q_OS_WIN)
1161  // make path absolute
1162  targetElems.prepend( "" );
1163 #endif
1164 
1165  return targetElems.join( "/" );
1166 }
1167 
1168 void QgsApplication::skipGdalDriver( const QString& theDriver )
1169 {
1170  if ( ABISYM( mGdalSkipList ).contains( theDriver ) || theDriver.isEmpty() )
1171  {
1172  return;
1173  }
1174  ABISYM( mGdalSkipList ) << theDriver;
1176 }
1177 
1179 {
1180  if ( !ABISYM( mGdalSkipList ).contains( theDriver ) )
1181  {
1182  return;
1183  }
1184  int myPos = ABISYM( mGdalSkipList ).indexOf( theDriver );
1185  if ( myPos >= 0 )
1186  {
1187  ABISYM( mGdalSkipList ).removeAt( myPos );
1188  }
1190 }
1191 
1193 {
1194  ABISYM( mGdalSkipList ).removeDuplicates();
1195  QString myDriverList = ABISYM( mGdalSkipList ).join( " " );
1196  QgsDebugMsg( "Gdal Skipped driver list set to:" );
1197  QgsDebugMsg( myDriverList );
1198  CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() );
1199  GDALAllRegister(); //to update driver list and skip missing ones
1200 }
1201 
1203 {
1204  QString folder = userThemesFolder();
1205  QDir myDir( folder );
1206  if ( !myDir.exists() )
1207  {
1208  myDir.mkpath( folder );
1209  }
1210 
1211  copyPath( defaultThemesFolder(), userThemesFolder() );
1212  return true;
1213 }
1214 
1215 void QgsApplication::copyPath( const QString& src, const QString& dst )
1216 {
1217  QDir dir( src );
1218  if ( ! dir.exists() )
1219  return;
1220 
1221  Q_FOREACH ( const QString& d, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
1222  {
1223  QString dst_path = dst + QDir::separator() + d;
1224  dir.mkpath( dst_path );
1225  copyPath( src + QDir::separator() + d, dst_path );
1226  }
1227 
1228  Q_FOREACH ( const QString& f, dir.entryList( QDir::Files ) )
1229  {
1230  QFile::copy( src + QDir::separator() + f, dst + QDir::separator() + f );
1231  }
1232 }
1233 
1234 bool QgsApplication::createDB( QString *errorMessage )
1235 {
1236  // set a working directory up for gdal to write .aux.xml files into
1237  // for cases where the raster dir is read only to the user
1238  // if the env var is already set it will be used preferentially
1239  QString myPamPath = qgisSettingsDirPath() + QLatin1String( "gdal_pam/" );
1240  QDir myDir( myPamPath );
1241  if ( !myDir.exists() )
1242  {
1243  myDir.mkpath( myPamPath ); //fail silently
1244  }
1245 
1246 #if defined(Q_OS_WIN)
1247  CPLSetConfigOption( "GDAL_PAM_PROXY_DIR", myPamPath.toUtf8() );
1248 #else
1249  //under other OS's we use an environment var so the user can
1250  //override the path if he likes
1251  int myChangeFlag = 0; //whether we want to force the env var to change
1252  setenv( "GDAL_PAM_PROXY_DIR", myPamPath.toUtf8(), myChangeFlag );
1253 #endif
1254 
1255  // Check qgis.db and make private copy if necessary
1256  QFile qgisPrivateDbFile( QgsApplication::qgisUserDbFilePath() );
1257 
1258  // first we look for ~/.qgis/qgis.db
1259  if ( !qgisPrivateDbFile.exists() )
1260  {
1261  // if it doesnt exist we copy it in from the global resources dir
1262  QString qgisMasterDbFileName = QgsApplication::qgisMasterDbFilePath();
1263  QFile masterFile( qgisMasterDbFileName );
1264 
1265  // Must be sure there is destination directory ~/.qgis
1267 
1268  //now copy the master file into the users .qgis dir
1269  bool isDbFileCopied = masterFile.copy( qgisPrivateDbFile.fileName() );
1270 
1271  if ( !isDbFileCopied )
1272  {
1273  if ( errorMessage )
1274  {
1275  *errorMessage = tr( "[ERROR] Can not make qgis.db private copy" );
1276  }
1277  return false;
1278  }
1279  }
1280  else
1281  {
1282  // migrate if necessary
1283  sqlite3 *db;
1284  if ( sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().constData(), &db ) != SQLITE_OK )
1285  {
1286  if ( errorMessage )
1287  {
1288  *errorMessage = tr( "Could not open qgis.db" );
1289  }
1290  return false;
1291  }
1292 
1293  char *errmsg;
1294  int res = sqlite3_exec( db, "SELECT epsg FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
1295  if ( res == SQLITE_OK )
1296  {
1297  // epsg column exists => need migration
1298  if ( sqlite3_exec( db,
1299  "ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
1300  "CREATE TABLE tbl_srs ("
1301  "srs_id INTEGER PRIMARY KEY,"
1302  "description text NOT NULL,"
1303  "projection_acronym text NOT NULL,"
1304  "ellipsoid_acronym NOT NULL,"
1305  "parameters text NOT NULL,"
1306  "srid integer,"
1307  "auth_name varchar,"
1308  "auth_id varchar,"
1309  "is_geo integer NOT NULL,"
1310  "deprecated boolean);"
1311  "CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
1312  "INSERT INTO tbl_srs(srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) SELECT srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,'','',is_geo,0 FROM tbl_srs_bak;"
1313  "DROP TABLE tbl_srs_bak", nullptr, nullptr, &errmsg ) != SQLITE_OK
1314  )
1315  {
1316  if ( errorMessage )
1317  {
1318  *errorMessage = tr( "Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
1319  }
1320  sqlite3_free( errmsg );
1321  sqlite3_close( db );
1322  return false;
1323  }
1324  }
1325  else
1326  {
1327  sqlite3_free( errmsg );
1328  }
1329 
1330  if ( sqlite3_exec( db, "DROP VIEW vw_srs", nullptr, nullptr, &errmsg ) != SQLITE_OK )
1331  {
1332  QgsDebugMsg( QString( "vw_srs didn't exists in private qgis.db: %1" ).arg( errmsg ) );
1333  }
1334 
1335  if ( sqlite3_exec( db,
1336  "CREATE VIEW vw_srs AS"
1337  " SELECT"
1338  " a.description AS description"
1339  ",a.srs_id AS srs_id"
1340  ",a.is_geo AS is_geo"
1341  ",coalesce(b.name,a.projection_acronym) AS name"
1342  ",a.parameters AS parameters"
1343  ",a.auth_name AS auth_name"
1344  ",a.auth_id AS auth_id"
1345  ",a.deprecated AS deprecated"
1346  " FROM tbl_srs a"
1347  " LEFT OUTER JOIN tbl_projection b ON a.projection_acronym=b.acronym"
1348  " ORDER BY coalesce(b.name,a.projection_acronym),a.description", nullptr, nullptr, &errmsg ) != SQLITE_OK
1349  )
1350  {
1351  if ( errorMessage )
1352  {
1353  *errorMessage = tr( "Update of view in private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
1354  }
1355  sqlite3_free( errmsg );
1356  sqlite3_close( db );
1357  return false;
1358  }
1359 
1360  sqlite3_close( db );
1361  }
1362  return true;
1363 }
1364 
1366 {
1367  QgsDebugMsg( QString( "maxThreads: %1" ).arg( maxThreads ) );
1368 
1369  // make sure value is between 1 and #cores, if not set to -1 (use #cores)
1370  // 0 could be used to disable any parallel processing
1371  if ( maxThreads < 1 || maxThreads > QThread::idealThreadCount() )
1372  maxThreads = -1;
1373 
1374  // save value
1375  ABISYM( mMaxThreads ) = maxThreads;
1376 
1377  // if -1 use #cores
1378  if ( maxThreads == -1 )
1379  maxThreads = QThread::idealThreadCount();
1380 
1381  // set max thread count in QThreadPool
1383  QgsDebugMsg( QString( "set QThreadPool max thread count to %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) );
1384 }
1385 
1387 {
1388  emit settingsChanged();
1389 }
1390 
static bool createDB(QString *errorMessage=nullptr)
initialise qgis.db
static void init(QString customConfigPath=QString())
This method initialises paths etc for QGIS.
QString fromAscii(const char *str, int size)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
static unsigned index
static QgsProviderRegistry * instance(const QString &pluginPath=QString::null)
Means of accessing canonical single instance.
QString & append(QChar ch)
Type type() const
iterator insert(const Key &key, const T &value)
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
static void skipGdalDriver(const QString &theDriver)
Sets the GDAL_SKIP environment variable to include the specified driver and then calls GDALDriverMana...
bool contains(const Key &key) const
static QgsAuthManager * instance()
Enforce singleton pattern.
QStringList systemEnvironment()
static QString authorsFilePath()
Returns the path to the authors file.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user&#39;s home dir.
static QString qgisUserDbFilePath()
Returns the path to the user qgis.db file.
static QString libraryPath()
Returns the path containing qgis_core, qgis_gui, qgispython (and other) libraries.
static QString defaultThemePath()
Returns the path to the default theme directory.
QString readLine(qint64 maxlen)
QByteArray trimmed() const
virtual bool event(QEvent *event) override
Watch for QFileOpenEvent.
QString name() const
static QString qgisAuthDbFilePath()
Returns the path to the user authentication database file: qgis-auth.db.
static QString donorsFilePath()
Returns the path to the donors file.
static QString relativePathToAbsolutePath(const QString &rpath, const QString &targetPath)
Converts path relative to target to an absolute path.
static void setPrefixPath(const QString &thePrefixPath, bool useDefaultPaths=false)
Alters prefix path - used by 3rd party apps.
QgsApplication(int &argc, char **argv, bool GUIenabled, const QString &customConfigPath=QString(), const QString &platformName="desktop")
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
int removeDuplicates()
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
static QString themeName()
Set the active theme to the specified theme.
static QString defaultThemesFolder()
Returns the path to default themes folder from install (works as a starting point).
void removeFirst()
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
QThreadPool * globalInstance()
void removeAt(int i)
bool contains(const QString &str, Qt::CaseSensitivity cs) const
void setFileName(const QString &name)
static void registerOgrDrivers()
Register OGR drivers ensuring this only happens once.
QString join(const QString &separator) const
bool exists() const
QThread * thread() const
static void setFileOpenEventReceiver(QObject *receiver)
Set the FileOpen event receiver.
static QString reportStyleSheet()
get a standard css style sheet for reports.
static int maxThreads()
Get maximum concurrent thread count.
static endian_t endian()
Returns whether this machine uses big or little endian.
QString homePath()
QChar separator()
QString tr(const char *sourceText, const char *disambiguation, int n)
static QPixmap getThemePixmap(const QString &theName)
Helper to get a theme icon as a pixmap.
bool copy(const QString &newName)
static QString userFullName()
Returns the user&#39;s operating system login account full display name.
static QString developersMapFilePath()
Returns the path to the developers map file.
void addLibraryPath(const QString &path)
int size() const
static QString absolutePathToRelativePath(const QString &apath, const QString &targetPath)
Converts absolute path to path relative to target.
QString what() const
Definition: qgsexception.h:36
void emitSettingsChanged()
Causes the application instance to emit the settingsChanged() signal.
static void applyGdalSkippedDrivers()
Apply the skipped drivers list to gdal.
const char * name() const
QString canonicalFilePath() const
QWidget * activeWindow()
endian_t
Constants for endian-ness.
bool exists() const
void append(const T &value)
QString fromUtf8(const char *str, int size)
bool atEnd() const
void setMaxThreadCount(int maxThreadCount)
QString tempPath()
static QString pluginPath()
Returns the path to the application plugin directory.
bool isDir() const
static void setThemeName(const QString &theThemeName)
Set the active theme to the specified theme.
bool init(const QString &pluginPath=QString::null)
Initialize QCA, prioritize qca-ossl plugin and optionally set up the authentication database...
static QString helpAppPath()
Returns the path to the help application.
static bool createThemeFolder()
Create the users theme folder.
static void cleanRegisteredFunctions()
Deletes all registered functions whose ownership have been transferred to the expression engine...
bool isEmpty() const
QFileInfoList entryInfoList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QString absoluteFilePath() const
virtual ~QgsApplication()
bool isEmpty() const
int removeAll(const T &value)
static QString i18nPath()
Returns the path to the translation directory.
bool sendEvent(QObject *receiver, QEvent *event)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QByteArray readAll()
static void setPkgDataPath(const QString &thePkgDataPath)
Alters pkg data path - used by 3rd party apps.
static QString splashPath()
Returns the path to the splash screen image directory.
QCoreApplication * instance()
QStringList ABISYM(QgsApplication::mFileOpenEventList)
static const char * QGIS_ORGANIZATION_NAME
static QString qgisMasterDbFilePath()
Returns the path to the master qgis.db file.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
static void setPluginPath(const QString &thePluginPath)
Alters plugin path - used by 3rd party apps.
bool cdUp()
static void restoreGdalDriver(const QString &theDriver)
Sets the GDAL_SKIP environment variable to exclude the specified driver and then calls GDALDriverMana...
static QString userLoginName()
Returns the user&#39;s operating system login account name.
bool exists() const
static QString pkgDataPath()
Returns the common root path of all application data directories.
struct sqlite3 sqlite3
static QString osName()
Returns a string name of the operating system QGIS is running on.
static void initQgis()
loads providers
static void setDefaultSvgPaths(const QStringList &pathList)
Alters default svg paths - used by 3rd party apps.
QColor lighter(int factor) const
virtual void close()
static void setAuthDbDirPath(const QString &theAuthDbDirPath)
Alters authentication data base directory path - used by 3rd party apps.
static QString defaultStyleV2Path()
Returns the path to default style (works as a starting point).
static QRegExp shortNameRegExp()
Returns the short name regular expression for line edit validator.
static QString userStyleV2Path()
Returns the path to user&#39;s style.
QString & replace(int position, int n, QChar after)
static QString showSettings()
Convenience function to get a summary of the paths used in this application instance useful for debug...
QVariant value(const QString &key, const QVariant &defaultValue) const
static QString appIconPath()
get application icon
static const char * QGIS_ORGANIZATION_DOMAIN
int idealThreadCount()
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QString mid(int position, int n) const
virtual bool notify(QObject *receiver, QEvent *event) override
Catch exceptions when sending event to receiver.
static QString contributorsFilePath()
Returns the path to the contributors file.
static QString activeThemePath()
Returns the path to the currently active theme directory.
virtual bool event(QEvent *e)
QString absolutePath() const
void insert(int i, const T &value)
void sendPostedEvents()
QThread * currentThread()
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
StandardButton critical(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
QString styleSheet() const
bool isWritable() const
int length() const
static QString platform()
Returns the QGIS platform name, eg "desktop" or "server".
QString left(int n) const
static void exitQgis()
deletes provider registry and map layer registry
static QStringList svgPaths()
Returns the pathes to svg directories.
static QString sponsorsFilePath()
Returns the path to the sponsors file.
int indexOf(const QRegExp &rx, int from) const
void prepend(const T &value)
iterator insert(const Key &key, const T &value)
bool contains(const Key &key) const
static QStringList composerTemplatePaths()
Returns the pathes to composer template directories.
static QString srsDbFilePath()
Returns the path to the srs.db file.
static QHash< QString, QString > uiThemes()
All themes found in ~/.qgis2/themes folder.
static QString libexecPath()
Returns the path with utility executables (help viewer, crssync, ...)
static QString prefixPath()
Returns the path to the application prefix directory.
static QString iconsPath()
Returns the path to the icons image directory.
static QString translatorsFilePath()
Returns the path to the sponsors file.
static const char * QGIS_APPLICATION_NAME
QString applicationDirPath()
virtual bool notify(QObject *receiver, QEvent *e)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
static const int QGIS_VERSION_INT
Definition: qgis.h:48
Defines a qgis exception class.
Definition: qgsexception.h:25
QByteArray readAllStandardOutput()
QString baseName() const
void settingsChanged()
Emitted whenever any global, application-wide settings are changed.
void start(const QString &program, const QStringList &arguments, QFlags< QIODevice::OpenModeFlag > mode)
static void setMaxThreads(int maxThreads)
Set maximum concurrent thread count.
bool mkpath(const QString &dirPath) const
static void setUITheme(const QString &themeName)
Set the current UI theme used to style the interface.
static QString licenceFilePath()
Returns the path to the licence file.
qint64 readLine(char *data, qint64 maxSize)
static QString userThemesFolder()
Returns the path to user&#39;s themes folder.
void preNotify(QObject *receiver, QEvent *event, bool *done)
const T value(const Key &key) const
bool waitForFinished(int msecs)
QByteArray toUtf8() const