|
QGIS API Documentation
master-6227475
|
00001 /*************************************************************************** 00002 qgsapplication.cpp - Accessors for application-wide data 00003 -------------------------------------- 00004 Date : 02-Jan-2006 00005 Copyright : (C) 2006 by Tom Elwertowski 00006 Email : telwertowski at users dot sourceforge dot net 00007 *************************************************************************** 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 ***************************************************************************/ 00015 00016 #include "qgsapplication.h" 00017 #include "qgslogger.h" 00018 #include "qgsmaplayerregistry.h" 00019 #include "qgsproviderregistry.h" 00020 #include "qgsexception.h" 00021 #include "qgsgeometry.h" 00022 00023 #include <QDir> 00024 #include <QFile> 00025 #include <QFileOpenEvent> 00026 #include <QMessageBox> 00027 #include <QPalette> 00028 #include <QProcess> 00029 #include <QSettings> 00030 #include <QIcon> 00031 #include <QPixmap> 00032 00033 #ifndef Q_WS_WIN 00034 #include <netinet/in.h> 00035 #else 00036 #include <winsock.h> 00037 #endif 00038 00039 #include "qgsconfig.h" 00040 00041 #include <gdal.h> 00042 #include <ogr_api.h> 00043 #include <cpl_conv.h> // for setting gdal options 00044 00045 QObject * ABISYM( QgsApplication::mFileOpenEventReceiver ); 00046 QStringList ABISYM( QgsApplication::mFileOpenEventList ); 00047 QString ABISYM( QgsApplication::mPrefixPath ); 00048 QString ABISYM( QgsApplication::mPluginPath ); 00049 QString ABISYM( QgsApplication::mPkgDataPath ); 00050 QString ABISYM( QgsApplication::mLibraryPath ); 00051 QString ABISYM( QgsApplication::mLibexecPath ); 00052 QString ABISYM( QgsApplication::mThemeName ); 00053 QStringList ABISYM( QgsApplication::mDefaultSvgPaths ); 00054 QMap<QString, QString> ABISYM( QgsApplication::mSystemEnvVars ); 00055 QString ABISYM( QgsApplication::mConfigPath ); 00056 bool ABISYM( QgsApplication::mRunningFromBuildDir ) = false; 00057 QString ABISYM( QgsApplication::mBuildSourcePath ); 00058 #ifdef _MSC_VER 00059 QString ABISYM( QgsApplication::mCfgIntDir ); 00060 #endif 00061 QString ABISYM( QgsApplication::mBuildOutputPath ); 00062 QStringList ABISYM( QgsApplication::mGdalSkipList ); 00063 00077 QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled, QString customConfigPath ) 00078 : QApplication( argc, argv, GUIenabled ) 00079 { 00080 init( customConfigPath ); // init can also be called directly by e.g. unit tests that don't inherit QApplication. 00081 } 00082 00083 void QgsApplication::init( QString customConfigPath ) 00084 { 00085 if ( customConfigPath.isEmpty() ) 00086 { 00087 customConfigPath = QDir::homePath() + QString( "/.qgis%1/" ).arg( 2 /* FIXME QGis::QGIS_VERSION_INT / 10000 */ ); 00088 } 00089 00090 qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" ); 00091 00092 QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() ); 00093 00094 // check if QGIS is run from build directory (not the install directory) 00095 QFile f; 00096 // "/../../.." is for Mac bundled app in build directory 00097 foreach ( QString path, QStringList() << "" << "/.." << "/bin" << "/../../.." ) 00098 { 00099 f.setFileName( prefixPath + path + "/path.txt" ); 00100 if ( f.exists() ) 00101 break; 00102 } 00103 if ( f.exists() && f.open( QIODevice::ReadOnly ) ) 00104 { 00105 ABISYM( mRunningFromBuildDir ) = true; 00106 ABISYM( mBuildSourcePath ) = f.readLine().trimmed(); 00107 ABISYM( mBuildOutputPath ) = f.readLine().trimmed(); 00108 qDebug( "Running from build directory!" ); 00109 qDebug( "- source directory: %s", ABISYM( mBuildSourcePath ).toUtf8().data() ); 00110 qDebug( "- output directory of the build: %s", ABISYM( mBuildOutputPath ).toUtf8().data() ); 00111 #ifdef _MSC_VER 00112 ABISYM( mCfgIntDir ) = prefixPath.split( "/", QString::SkipEmptyParts ).last(); 00113 qDebug( "- cfg: %s", ABISYM( mCfgIntDir ).toUtf8().data() ); 00114 #endif 00115 } 00116 00117 if ( ABISYM( mRunningFromBuildDir ) ) 00118 { 00119 // we run from source directory - not installed to destination (specified prefix) 00120 ABISYM( mPrefixPath ) = QString(); // set invalid path 00121 #if defined(_MSC_VER) && !defined(USING_NMAKE) 00122 setPluginPath( ABISYM( mBuildOutputPath ) + "/" + QString( QGIS_PLUGIN_SUBDIR ) + "/" + ABISYM( mCfgIntDir ) ); 00123 #else 00124 setPluginPath( ABISYM( mBuildOutputPath ) + "/" + QString( QGIS_PLUGIN_SUBDIR ) ); 00125 #endif 00126 setPkgDataPath( ABISYM( mBuildSourcePath ) ); // directly source path - used for: doc, resources, svg 00127 ABISYM( mLibraryPath ) = ABISYM( mBuildOutputPath ) + "/" + QGIS_LIB_SUBDIR + "/"; 00128 #if defined(_MSC_VER) && !defined(USING_NMAKE) 00129 ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) + "/" + QGIS_LIBEXEC_SUBDIR + "/" + ABISYM( mCfgIntDir ) + "/"; 00130 #else 00131 ABISYM( mLibexecPath ) = ABISYM( mBuildOutputPath ) + "/" + QGIS_LIBEXEC_SUBDIR + "/"; 00132 #endif 00133 } 00134 else 00135 { 00136 char *prefixPath = getenv( "QGIS_PREFIX_PATH" ); 00137 if ( !prefixPath ) 00138 { 00139 #if defined(Q_WS_MACX) || defined(Q_WS_WIN32) || defined(WIN32) 00140 setPrefixPath( applicationDirPath(), true ); 00141 #else 00142 QDir myDir( applicationDirPath() ); 00143 myDir.cdUp(); 00144 QString myPrefix = myDir.absolutePath(); 00145 setPrefixPath( myPrefix, true ); 00146 #endif 00147 } 00148 else 00149 { 00150 setPrefixPath( prefixPath, true ); 00151 } 00152 } 00153 00154 if ( !customConfigPath.isEmpty() ) 00155 { 00156 ABISYM( mConfigPath ) = customConfigPath + "/"; // make sure trailing slash is included 00157 } 00158 00159 ABISYM( mDefaultSvgPaths ) << qgisSettingsDirPath() + QString( "svg/" ); 00160 00161 // store system environment variables passed to application, before they are adjusted 00162 QMap<QString, QString> systemEnvVarMap; 00163 foreach ( const QString &varStr, QProcess::systemEnvironment() ) 00164 { 00165 int pos = varStr.indexOf( QLatin1Char( '=' ) ); 00166 if ( pos == -1 ) 00167 continue; 00168 QString varStrName = varStr.left( pos ); 00169 QString varStrValue = varStr.mid( pos + 1 ); 00170 systemEnvVarMap.insert( varStrName, varStrValue ); 00171 } 00172 ABISYM( mSystemEnvVars ) = systemEnvVarMap; 00173 00174 // set a working directory up for gdal to write .aux.xml files into 00175 // for cases where the raster dir is read only to the user 00176 // if the env var is already set it will be used preferentially 00177 QString myPamPath = qgisSettingsDirPath() + QString( "gdal_pam/" ); 00178 QDir myDir( myPamPath ); 00179 if ( !myDir.exists() ) 00180 { 00181 myDir.mkpath( myPamPath ); //fail silently 00182 } 00183 00184 00185 #if defined(Q_WS_WIN32) || defined(WIN32) 00186 CPLSetConfigOption( "GDAL_PAM_PROXY_DIR", myPamPath.toUtf8() ); 00187 #else 00188 //under other OS's we use an environment var so the user can 00189 //override the path if he likes 00190 int myChangeFlag = 0; //whether we want to force the env var to change 00191 setenv( "GDAL_PAM_PROXY_DIR", myPamPath.toUtf8(), myChangeFlag ); 00192 #endif 00193 } 00194 00195 QgsApplication::~QgsApplication() 00196 { 00197 } 00198 00199 bool QgsApplication::event( QEvent * event ) 00200 { 00201 bool done = false; 00202 if ( event->type() == QEvent::FileOpen ) 00203 { 00204 // handle FileOpen event (double clicking a file icon in Mac OS X Finder) 00205 if ( ABISYM( mFileOpenEventReceiver ) ) 00206 { 00207 // Forward event to main window. 00208 done = notify( ABISYM( mFileOpenEventReceiver ), event ); 00209 } 00210 else 00211 { 00212 // Store filename because receiver has not registered yet. 00213 // If QGIS has been launched by double clicking a file icon, FileOpen will be 00214 // the first event; the main window is not yet ready to handle the event. 00215 ABISYM( mFileOpenEventList ).append( static_cast<QFileOpenEvent *>( event )->file() ); 00216 done = true; 00217 } 00218 } 00219 else 00220 { 00221 // pass other events to base class 00222 done = QApplication::event( event ); 00223 } 00224 return done; 00225 } 00226 00227 bool QgsApplication::notify( QObject * receiver, QEvent * event ) 00228 { 00229 bool done = false; 00230 // Crashes in customization (especially on Mac), if we're not in the main/UI thread, see #5597 00231 if ( thread() == receiver->thread() ) 00232 emit preNotify( receiver, event, &done ); 00233 00234 if ( done ) 00235 return true; 00236 00237 // Send event to receiver and catch unhandled exceptions 00238 done = true; 00239 try 00240 { 00241 done = QApplication::notify( receiver, event ); 00242 } 00243 catch ( QgsException & e ) 00244 { 00245 QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() ); 00246 } 00247 catch ( std::exception & e ) 00248 { 00249 QMessageBox::critical( activeWindow(), tr( "Exception" ), e.what() ); 00250 } 00251 catch ( ... ) 00252 { 00253 QMessageBox::critical( activeWindow(), tr( "Exception" ), tr( "unknown exception" ) ); 00254 } 00255 00256 return done; 00257 } 00258 00259 void QgsApplication::setFileOpenEventReceiver( QObject * receiver ) 00260 { 00261 // Set receiver for FileOpen events 00262 ABISYM( mFileOpenEventReceiver ) = receiver; 00263 // Propagate any events collected before the receiver has registered. 00264 if ( ABISYM( mFileOpenEventList ).count() > 0 ) 00265 { 00266 QStringListIterator i( ABISYM( mFileOpenEventList ) ); 00267 while ( i.hasNext() ) 00268 { 00269 QFileOpenEvent foe( i.next() ); 00270 QgsApplication::sendEvent( ABISYM( mFileOpenEventReceiver ), &foe ); 00271 } 00272 ABISYM( mFileOpenEventList ).clear(); 00273 } 00274 } 00275 00276 void QgsApplication::setPrefixPath( const QString thePrefixPath, bool useDefaultPaths ) 00277 { 00278 ABISYM( mPrefixPath ) = thePrefixPath; 00279 #if defined(_MSC_VER) 00280 if ( ABISYM( mPrefixPath ).endsWith( "/bin" ) ) 00281 { 00282 ABISYM( mPrefixPath ).chop( 4 ); 00283 } 00284 #endif 00285 if ( useDefaultPaths ) 00286 { 00287 setPluginPath( ABISYM( mPrefixPath ) + "/" + QString( QGIS_PLUGIN_SUBDIR ) ); 00288 setPkgDataPath( ABISYM( mPrefixPath ) + "/" + QString( QGIS_DATA_SUBDIR ) ); 00289 } 00290 ABISYM( mLibraryPath ) = ABISYM( mPrefixPath ) + "/" + QGIS_LIB_SUBDIR + "/"; 00291 ABISYM( mLibexecPath ) = ABISYM( mPrefixPath ) + "/" + QGIS_LIBEXEC_SUBDIR + "/"; 00292 } 00293 00294 void QgsApplication::setPluginPath( const QString thePluginPath ) 00295 { 00296 ABISYM( mPluginPath ) = thePluginPath; 00297 } 00298 00299 void QgsApplication::setPkgDataPath( const QString thePkgDataPath ) 00300 { 00301 ABISYM( mPkgDataPath ) = thePkgDataPath; 00302 QString mySvgPath = thePkgDataPath + ( ABISYM( mRunningFromBuildDir ) ? "/images/svg/" : "/svg/" ); 00303 // avoid duplicate entries 00304 if ( !ABISYM( mDefaultSvgPaths ).contains( mySvgPath ) ) 00305 ABISYM( mDefaultSvgPaths ) << mySvgPath; 00306 } 00307 00308 void QgsApplication::setDefaultSvgPaths( const QStringList& pathList ) 00309 { 00310 ABISYM( mDefaultSvgPaths ) = pathList; 00311 } 00312 00313 const QString QgsApplication::prefixPath() 00314 { 00315 if ( ABISYM( mRunningFromBuildDir ) ) 00316 { 00317 qWarning( "!!! prefix path was requested, but it is not valid - we do not run from installed path !!!" ); 00318 } 00319 00320 return ABISYM( mPrefixPath ); 00321 } 00322 const QString QgsApplication::pluginPath() 00323 { 00324 return ABISYM( mPluginPath ); 00325 } 00326 const QString QgsApplication::pkgDataPath() 00327 { 00328 return ABISYM( mPkgDataPath ); 00329 } 00330 const QString QgsApplication::defaultThemePath() 00331 { 00332 return ":/images/themes/default/"; 00333 } 00334 const QString QgsApplication::activeThemePath() 00335 { 00336 return ":/images/themes/" + themeName() + "/"; 00337 } 00338 00339 00340 QString QgsApplication::iconPath( QString iconFile ) 00341 { 00342 // try active theme 00343 QString path = activeThemePath(); 00344 if ( QFile::exists( path + iconFile ) ) 00345 return path + iconFile; 00346 00347 // use default theme 00348 return defaultThemePath() + iconFile; 00349 } 00350 00351 QIcon QgsApplication::getThemeIcon( const QString theName ) 00352 { 00353 QString myPreferredPath = activeThemePath() + QDir::separator() + theName; 00354 QString myDefaultPath = defaultThemePath() + QDir::separator() + theName; 00355 if ( QFile::exists( myPreferredPath ) ) 00356 { 00357 return QIcon( myPreferredPath ); 00358 } 00359 else if ( QFile::exists( myDefaultPath ) ) 00360 { 00361 //could still return an empty icon if it 00362 //doesnt exist in the default theme either! 00363 return QIcon( myDefaultPath ); 00364 } 00365 else 00366 { 00367 return QIcon(); 00368 } 00369 } 00370 00371 // TODO: add some caching mechanism ? 00372 QPixmap QgsApplication::getThemePixmap( const QString theName ) 00373 { 00374 QString myPreferredPath = activeThemePath() + QDir::separator() + theName; 00375 QString myDefaultPath = defaultThemePath() + QDir::separator() + theName; 00376 if ( QFile::exists( myPreferredPath ) ) 00377 { 00378 return QPixmap( myPreferredPath ); 00379 } 00380 else 00381 { 00382 //could still return an empty icon if it 00383 //doesnt exist in the default theme either! 00384 return QPixmap( myDefaultPath ); 00385 } 00386 } 00387 00391 void QgsApplication::setThemeName( const QString theThemeName ) 00392 { 00393 QString myPath = ":/images/themes/" + theThemeName + "/"; 00394 //check it exists and if not roll back to default theme 00395 if ( QFile::exists( myPath ) ) 00396 { 00397 ABISYM( mThemeName ) = theThemeName; 00398 } 00399 else 00400 { 00401 ABISYM( mThemeName ) = "default"; 00402 } 00403 } 00407 const QString QgsApplication::themeName() 00408 { 00409 return ABISYM( mThemeName ); 00410 } 00414 const QString QgsApplication::authorsFilePath() 00415 { 00416 return ABISYM( mPkgDataPath ) + QString( "/doc/AUTHORS" ); 00417 } 00421 const QString QgsApplication::contributorsFilePath() 00422 { 00423 return ABISYM( mPkgDataPath ) + QString( "/doc/CONTRIBUTORS" ); 00424 } 00428 const QString QgsApplication::sponsorsFilePath() 00429 { 00430 return ABISYM( mPkgDataPath ) + QString( "/doc/SPONSORS" ); 00431 } 00432 00436 const QString QgsApplication::donorsFilePath() 00437 { 00438 return ABISYM( mPkgDataPath ) + QString( "/doc/DONORS" ); 00439 } 00440 00445 const QString QgsApplication::translatorsFilePath() 00446 { 00447 return ABISYM( mPkgDataPath ) + QString( "/doc/TRANSLATORS" ); 00448 } 00449 00453 const QString QgsApplication::helpAppPath() 00454 { 00455 QString helpAppPath; 00456 #ifdef Q_OS_MACX 00457 helpAppPath = applicationDirPath() + "/bin/qgis_help.app/Contents/MacOS"; 00458 #else 00459 helpAppPath = libexecPath(); 00460 #endif 00461 helpAppPath += "/qgis_help"; 00462 #ifdef Q_OS_WIN 00463 helpAppPath += ".exe"; 00464 #endif 00465 return helpAppPath; 00466 } 00470 const QString QgsApplication::i18nPath() 00471 { 00472 if ( ABISYM( mRunningFromBuildDir ) ) 00473 return ABISYM( mBuildOutputPath ) + QString( "/i18n" ); 00474 else 00475 return ABISYM( mPkgDataPath ) + QString( "/i18n/" ); 00476 } 00477 00481 const QString QgsApplication::qgisMasterDbFilePath() 00482 { 00483 return ABISYM( mPkgDataPath ) + QString( "/resources/qgis.db" ); 00484 } 00485 00489 const QString QgsApplication::qgisSettingsDirPath() 00490 { 00491 return ABISYM( mConfigPath ); 00492 } 00493 00497 const QString QgsApplication::qgisUserDbFilePath() 00498 { 00499 return qgisSettingsDirPath() + QString( "qgis.db" ); 00500 } 00501 00505 const QString QgsApplication::splashPath() 00506 { 00507 return QString( ":/images/splash/" ); 00508 } 00509 00513 const QString QgsApplication::iconsPath() 00514 { 00515 return ABISYM( mPkgDataPath ) + QString( "/images/icons/" ); 00516 } 00520 const QString QgsApplication::srsDbFilePath() 00521 { 00522 if ( ABISYM( mRunningFromBuildDir ) ) 00523 { 00524 QString tempCopy = QDir::tempPath() + "/srs.db"; 00525 00526 if ( !QFile( tempCopy ).exists() ) 00527 { 00528 QFile f( ABISYM( mPkgDataPath ) + "/resources/srs.db" ); 00529 if ( !f.copy( tempCopy ) ) 00530 { 00531 qFatal( "Could not create temporary copy" ); 00532 } 00533 } 00534 00535 return tempCopy; 00536 } 00537 else 00538 { 00539 return ABISYM( mPkgDataPath ) + QString( "/resources/srs.db" ); 00540 } 00541 } 00542 00546 const QStringList QgsApplication::svgPaths() 00547 { 00548 //local directories to search when looking for an SVG with a given basename 00549 //defined by user in options dialog 00550 QSettings settings; 00551 QStringList myPathList; 00552 QString myPaths = settings.value( "svg/searchPathsForSVG", "" ).toString(); 00553 if ( !myPaths.isEmpty() ) 00554 { 00555 myPathList = myPaths.split( "|" ); 00556 } 00557 00558 myPathList << ABISYM( mDefaultSvgPaths ); 00559 return myPathList; 00560 } 00561 00562 const QString QgsApplication::userStyleV2Path() 00563 { 00564 return qgisSettingsDirPath() + QString( "symbology-ng-style.db" ); 00565 } 00566 00567 const QString QgsApplication::defaultStyleV2Path() 00568 { 00569 return ABISYM( mPkgDataPath ) + QString( "/resources/symbology-ng-style.db" ); 00570 } 00571 00572 const QString QgsApplication::libraryPath() 00573 { 00574 return ABISYM( mLibraryPath ); 00575 } 00576 00577 const QString QgsApplication::libexecPath() 00578 { 00579 return ABISYM( mLibexecPath ); 00580 } 00581 00582 QgsApplication::endian_t QgsApplication::endian() 00583 { 00584 return ( htonl( 1 ) == 1 ) ? XDR : NDR ; 00585 } 00586 00587 void QgsApplication::initQgis() 00588 { 00589 // set the provider plugin path (this creates provider registry) 00590 QgsProviderRegistry::instance( pluginPath() ); 00591 00592 // create map layer registry if doesn't exist 00593 QgsMapLayerRegistry::instance(); 00594 } 00595 00596 void QgsApplication::exitQgis() 00597 { 00598 delete QgsMapLayerRegistry::instance(); 00599 delete QgsProviderRegistry::instance(); 00600 } 00601 00602 QString QgsApplication::showSettings() 00603 { 00604 QString myEnvironmentVar( getenv( "QGIS_PREFIX_PATH" ) ); 00605 QString myState = tr( "Application state:\n" 00606 "QGIS_PREFIX_PATH env var:\t\t%1\n" 00607 "Prefix:\t\t%2\n" 00608 "Plugin Path:\t\t%3\n" 00609 "Package Data Path:\t%4\n" 00610 "Active Theme Name:\t%5\n" 00611 "Active Theme Path:\t%6\n" 00612 "Default Theme Path:\t%7\n" 00613 "SVG Search Paths:\t%8\n" 00614 "User DB Path:\t%9\n" ) 00615 .arg( myEnvironmentVar ) 00616 .arg( prefixPath() ) 00617 .arg( pluginPath() ) 00618 .arg( pkgDataPath() ) 00619 .arg( themeName() ) 00620 .arg( activeThemePath() ) 00621 .arg( defaultThemePath() ) 00622 .arg( svgPaths().join( tr( "\n\t\t", "match indentation of application state" ) ) ) 00623 .arg( qgisMasterDbFilePath() ); 00624 return myState; 00625 } 00626 00627 QString QgsApplication::reportStyleSheet() 00628 { 00629 // 00630 // Make the style sheet desktop preferences aware by using qappliation 00631 // palette as a basis for colors where appropriate 00632 // 00633 // QColor myColor1 = palette().highlight().color(); 00634 QColor myColor1( Qt::lightGray ); 00635 QColor myColor2 = myColor1; 00636 myColor2 = myColor2.lighter( 110 ); //10% lighter 00637 QString myStyle; 00638 myStyle = "p.glossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, " 00639 " stop: 0 " + myColor1.name() + "," 00640 " stop: 0.1 " + myColor2.name() + "," 00641 " stop: 0.5 " + myColor1.name() + "," 00642 " stop: 0.9 " + myColor2.name() + "," 00643 " stop: 1 " + myColor1.name() + ");" 00644 " color: black;" 00645 " padding-left: 4px;" 00646 " padding-top: 20px;" 00647 " padding-bottom: 8px;" 00648 " border: 1px solid #6c6c6c;" 00649 "}" 00650 "p.subheaderglossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, " 00651 " stop: 0 " + myColor1.name() + "," 00652 " stop: 0.1 " + myColor2.name() + "," 00653 " stop: 0.5 " + myColor1.name() + "," 00654 " stop: 0.9 " + myColor2.name() + "," 00655 " stop: 1 " + myColor1.name() + ");" 00656 " font-weight: bold;" 00657 " font-size: medium;" 00658 " line-height: 1.1em;" 00659 " width: 100%;" 00660 " color: black;" 00661 " padding-left: 4px;" 00662 " padding-right: 4px;" 00663 " padding-top: 20px;" 00664 " padding-bottom: 8px;" 00665 " border: 1px solid #6c6c6c;" 00666 "}" 00667 "th.glossy{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, " 00668 " stop: 0 " + myColor1.name() + "," 00669 " stop: 0.1 " + myColor2.name() + "," 00670 " stop: 0.5 " + myColor1.name() + "," 00671 " stop: 0.9 " + myColor2.name() + "," 00672 " stop: 1 " + myColor1.name() + ");" 00673 " color: black;" 00674 " border: 1px solid #6c6c6c;" 00675 "}" 00676 ".overview{ font: 1.82em; font-weight: bold;}" 00677 "body{ background: white;" 00678 " color: black;" 00679 " font-family: arial,sans-serif;" 00680 "}" 00681 "h1{ background-color: #F6F6F6;" 00682 " color: #8FB171; " 00683 " font-size: x-large; " 00684 " font-weight: normal;" 00685 " font-family: luxi serif, georgia, times new roman, times, serif;" 00686 " background: none;" 00687 " padding: 0.75em 0 0;" 00688 " margin: 0;" 00689 " line-height: 3em;" 00690 "}" 00691 "h2{ background-color: #F6F6F6;" 00692 " color: #8FB171; " 00693 " font-size: medium; " 00694 " font-weight: normal;" 00695 " font-family: luxi serif, georgia, times new roman, times, serif;" 00696 " background: none;" 00697 " padding: 0.75em 0 0;" 00698 " margin: 0;" 00699 " line-height: 1.1em;" 00700 "}" 00701 "h3{ background-color: #F6F6F6;" 00702 " color: #729FCF;" 00703 " font-family: luxi serif, georgia, times new roman, times, serif;" 00704 " font-weight: bold;" 00705 " font-size: large;" 00706 " text-align: right;" 00707 " border-bottom: 5px solid #DCEB5C;" 00708 "}" 00709 "h4{ background-color: #F6F6F6;" 00710 " color: #729FCF;" 00711 " font-family: luxi serif, georgia, times new roman, times, serif;" 00712 " font-weight: bold;" 00713 " font-size: medium;" 00714 " text-align: right;" 00715 "}" 00716 "h5{ background-color: #F6F6F6;" 00717 " color: #729FCF;" 00718 " font-family: luxi serif, georgia, times new roman, times, serif;" 00719 " font-weight: bold;" 00720 " font-size: small;" 00721 " text-align: right;" 00722 "}" 00723 "a{ color: #729FCF;" 00724 " font-family: arial,sans-serif;" 00725 " font-size: small;" 00726 "}" 00727 "label{ background-color: #FFFFCC;" 00728 " border: 1px solid black;" 00729 " margin: 1px;" 00730 " padding: 0px 3px; " 00731 " font-size: small;" 00732 "}"; 00733 return myStyle; 00734 } 00735 00736 void QgsApplication::registerOgrDrivers() 00737 { 00738 if ( 0 >= OGRGetDriverCount() ) 00739 { 00740 OGRRegisterAll(); 00741 } 00742 } 00743 00744 QString QgsApplication::absolutePathToRelativePath( QString aPath, QString targetPath ) 00745 { 00746 #if defined( Q_OS_WIN ) 00747 const Qt::CaseSensitivity cs = Qt::CaseInsensitive; 00748 00749 aPath.replace( "\\", "/" ); 00750 if ( aPath.startsWith( "//" ) ) 00751 { 00752 // keep UNC prefix 00753 aPath = "\\\\" + aPath.mid( 2 ); 00754 } 00755 00756 targetPath.replace( "\\", "/" ); 00757 if ( targetPath.startsWith( "//" ) ) 00758 { 00759 // keep UNC prefix 00760 targetPath = "\\\\" + targetPath.mid( 2 ); 00761 } 00762 #else 00763 const Qt::CaseSensitivity cs = Qt::CaseSensitive; 00764 #endif 00765 00766 QStringList targetElems = targetPath.split( "/", QString::SkipEmptyParts ); 00767 QStringList aPathElems = aPath.split( "/", QString::SkipEmptyParts ); 00768 00769 targetElems.removeAll( "." ); 00770 aPathElems.removeAll( "." ); 00771 00772 // remove common part 00773 int n = 0; 00774 while ( aPathElems.size() > 0 && 00775 targetElems.size() > 0 && 00776 aPathElems[0].compare( targetElems[0], cs ) == 0 ) 00777 { 00778 aPathElems.removeFirst(); 00779 targetElems.removeFirst(); 00780 n++; 00781 } 00782 00783 if ( n == 0 ) 00784 { 00785 // no common parts; might not even be a file 00786 return aPath; 00787 } 00788 00789 if ( targetElems.size() > 0 ) 00790 { 00791 // go up to the common directory 00792 for ( int i = 0; i < targetElems.size(); i++ ) 00793 { 00794 aPathElems.insert( 0, ".." ); 00795 } 00796 } 00797 else 00798 { 00799 // let it start with . nevertheless, 00800 // so relative path always start with either ./ or ../ 00801 aPathElems.insert( 0, "." ); 00802 } 00803 00804 return aPathElems.join( "/" ); 00805 } 00806 00807 QString QgsApplication::relativePathToAbsolutePath( QString rpath, QString targetPath ) 00808 { 00809 // relative path should always start with ./ or ../ 00810 if ( !rpath.startsWith( "./" ) && !rpath.startsWith( "../" ) ) 00811 { 00812 return rpath; 00813 } 00814 00815 #if defined(Q_OS_WIN) 00816 rpath.replace( "\\", "/" ); 00817 targetPath.replace( "\\", "/" ); 00818 00819 bool uncPath = targetPath.startsWith( "//" ); 00820 #endif 00821 00822 QStringList srcElems = rpath.split( "/", QString::SkipEmptyParts ); 00823 QStringList targetElems = targetPath.split( "/", QString::SkipEmptyParts ); 00824 00825 #if defined(Q_OS_WIN) 00826 if ( uncPath ) 00827 { 00828 targetElems.insert( 0, "" ); 00829 targetElems.insert( 0, "" ); 00830 } 00831 #endif 00832 00833 // append source path elements 00834 targetElems << srcElems; 00835 targetElems.removeAll( "." ); 00836 00837 // resolve .. 00838 int pos; 00839 while (( pos = targetElems.indexOf( ".." ) ) > 0 ) 00840 { 00841 // remove preceding element and .. 00842 targetElems.removeAt( pos - 1 ); 00843 targetElems.removeAt( pos - 1 ); 00844 } 00845 00846 #if !defined(Q_OS_WIN) 00847 // make path absolute 00848 targetElems.prepend( "" ); 00849 #endif 00850 00851 return targetElems.join( "/" ); 00852 } 00853 00854 void QgsApplication::skipGdalDriver( QString theDriver ) 00855 { 00856 if ( ABISYM( mGdalSkipList ).contains( theDriver ) || theDriver.isEmpty() ) 00857 { 00858 return; 00859 } 00860 ABISYM( mGdalSkipList ) << theDriver; 00861 applyGdalSkippedDrivers(); 00862 } 00863 00864 void QgsApplication::restoreGdalDriver( QString theDriver ) 00865 { 00866 if ( !ABISYM( mGdalSkipList ).contains( theDriver ) ) 00867 { 00868 return; 00869 } 00870 int myPos = ABISYM( mGdalSkipList ).indexOf( theDriver ); 00871 if ( myPos >= 0 ) 00872 { 00873 ABISYM( mGdalSkipList ).removeAt( myPos ); 00874 } 00875 applyGdalSkippedDrivers(); 00876 } 00877 00878 void QgsApplication::applyGdalSkippedDrivers() 00879 { 00880 ABISYM( mGdalSkipList ).removeDuplicates(); 00881 QString myDriverList = ABISYM( mGdalSkipList ).join( " " ); 00882 QgsDebugMsg( "Gdal Skipped driver list set to:" ); 00883 QgsDebugMsg( myDriverList ); 00884 CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() ); 00885 GDALAllRegister(); //to update driver list and skip missing ones 00886 } 00887 00888