|
45 | 45 | #define CPL_SUPRESS_CPLUSPLUS |
46 | 46 | #include <gdal.h> |
47 | 47 | #include <geos_c.h> |
| 48 | +#include <cpl_conv.h> // for setting gdal options |
48 | 49 |
|
49 | 50 | #include "qgsconfig.h" |
50 | 51 |
|
@@ -541,10 +542,11 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) : |
541 | 542 | } //default is central point |
542 | 543 |
|
543 | 544 | restoreGeometry( settings.value( "/Windows/Options/geometry" ).toByteArray() ); |
544 | | - tabWidget->setCurrentIndex( settings.value( "/Windows/Options/row" ).toInt() ); |
545 | 545 |
|
546 | | - loadGdalDriverList(); |
| 546 | + // load gdal driver list only when gdal tab is first opened |
| 547 | + mLoadedGdalDriverList = false; |
547 | 548 |
|
| 549 | + tabWidget->setCurrentIndex( settings.value( "/Windows/Options/row" ).toInt() ); |
548 | 550 | } |
549 | 551 |
|
550 | 552 | //! Destructor |
@@ -916,7 +918,8 @@ void QgsOptions::saveOptions() |
916 | 918 |
|
917 | 919 |
|
918 | 920 | // Gdal skip driver list |
919 | | - saveGdalDriverList(); |
| 921 | + if ( mLoadedGdalDriverList ) |
| 922 | + saveGdalDriverList(); |
920 | 923 | } |
921 | 924 |
|
922 | 925 |
|
@@ -1184,6 +1187,16 @@ void QgsOptions::on_mClearCache_clicked() |
1184 | 1187 | #endif |
1185 | 1188 | } |
1186 | 1189 |
|
| 1190 | +void QgsOptions::on_tabWidget_currentChanged( int theTab ) |
| 1191 | +{ |
| 1192 | + // load gdal driver list when gdal tab is first opened |
| 1193 | + if ( theTab == 1 && ! mLoadedGdalDriverList ) |
| 1194 | + { |
| 1195 | + loadGdalDriverList(); |
| 1196 | + } |
| 1197 | +} |
| 1198 | + |
| 1199 | +#if 0 |
1187 | 1200 | void QgsOptions::loadGdalDriverList() |
1188 | 1201 | { |
1189 | 1202 | QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers(); |
@@ -1228,19 +1241,120 @@ void QgsOptions::loadGdalDriverList() |
1228 | 1241 | lstGdalDrivers->addItem( mypItem ); |
1229 | 1242 | } |
1230 | 1243 | } |
| 1244 | +#endif |
| 1245 | + |
| 1246 | +void QgsOptions::loadGdalDriverList() |
| 1247 | +{ |
| 1248 | + QStringList mySkippedDrivers = QgsApplication::skippedGdalDrivers(); |
| 1249 | + GDALDriverH myGdalDriver; // current driver |
| 1250 | + QString myGdalDriverDescription; |
| 1251 | + QStringList myDrivers; |
| 1252 | + QMap<QString, QString> myDriversFlags, myDriversExt, myDriversLongName; |
| 1253 | + |
| 1254 | + // make sure we save list when accept() |
| 1255 | + mLoadedGdalDriverList = true; |
| 1256 | + |
| 1257 | + // allow to retrieve metadata from all drivers, they will be skipped again when saving |
| 1258 | + CPLSetConfigOption( "GDAL_SKIP", "" ); |
| 1259 | + GDALAllRegister(); |
| 1260 | + |
| 1261 | + int myGdalDriverCount = GDALGetDriverCount(); |
| 1262 | + for ( int i = 0; i < myGdalDriverCount; ++i ) |
| 1263 | + { |
| 1264 | + myGdalDriver = GDALGetDriver( i ); |
| 1265 | + |
| 1266 | + Q_CHECK_PTR( myGdalDriver ); |
| 1267 | + |
| 1268 | + if ( !myGdalDriver ) |
| 1269 | + { |
| 1270 | + QgsLogger::warning( "unable to get driver " + QString::number( i ) ); |
| 1271 | + continue; |
| 1272 | + } |
| 1273 | + myGdalDriverDescription = GDALGetDescription( myGdalDriver ); |
| 1274 | + myDrivers << myGdalDriverDescription; |
| 1275 | + |
| 1276 | + QgsDebugMsg( QString( "driver #%1 - %2" ).arg( i ).arg( myGdalDriverDescription ) ); |
| 1277 | + |
| 1278 | + // get driver R/W flags, taken from GDALGeneralCmdLineProcessor() |
| 1279 | + const char *pszRWFlag, *pszVirtualIO; |
| 1280 | + if ( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_CREATE, NULL ) ) |
| 1281 | + pszRWFlag = "rw+"; |
| 1282 | + else if ( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_CREATECOPY, |
| 1283 | + NULL ) ) |
| 1284 | + pszRWFlag = "rw"; |
| 1285 | + else |
| 1286 | + pszRWFlag = "ro"; |
| 1287 | + if ( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_VIRTUALIO, NULL ) ) |
| 1288 | + pszVirtualIO = "v"; |
| 1289 | + else |
| 1290 | + pszVirtualIO = ""; |
| 1291 | + myDriversFlags[myGdalDriverDescription] = QString( "%1%2" ).arg( pszRWFlag ).arg( pszVirtualIO ); |
| 1292 | + |
| 1293 | + // get driver extensions and long name |
| 1294 | + // the gdal provider can override/add extensions but there is no interface to query this |
| 1295 | + // aside from parsing QgsRasterLayer::buildSupportedRasterFileFilter() |
| 1296 | + myDriversExt[myGdalDriverDescription] = QString( GDALGetMetadataItem( myGdalDriver, "DMD_EXTENSION", "" ) ).toLower(); |
| 1297 | + myDriversLongName[myGdalDriverDescription] = QString( GDALGetMetadataItem( myGdalDriver, "DMD_LONGNAME", "" ) ); |
| 1298 | + |
| 1299 | + } |
| 1300 | + // restore GDAL_SKIP just in case |
| 1301 | + CPLSetConfigOption( "GDAL_SKIP", mySkippedDrivers.join( " " ).toUtf8() ); |
| 1302 | + |
| 1303 | + myDrivers.removeDuplicates(); |
| 1304 | + // myDrivers.sort(); |
| 1305 | + // sort list case insensitive - no existing function for this! |
| 1306 | + QMap<QString, QString> strMap; |
| 1307 | + foreach( QString str, myDrivers ) |
| 1308 | + { |
| 1309 | + strMap.insert( str.toLower(), str ); |
| 1310 | + } |
| 1311 | + myDrivers = strMap.values(); |
| 1312 | + |
| 1313 | + QStringListIterator myIterator( myDrivers ); |
| 1314 | + |
| 1315 | + while ( myIterator.hasNext() ) |
| 1316 | + { |
| 1317 | + QString myName = myIterator.next(); |
| 1318 | + |
| 1319 | + // QListWidgetItem * mypItem = new QListWidgetItem( myName ); |
| 1320 | + QTreeWidgetItem * mypItem = new QTreeWidgetItem( QStringList( myName ) ); |
| 1321 | + if ( mySkippedDrivers.contains( myName ) ) |
| 1322 | + { |
| 1323 | + mypItem->setCheckState( 0, Qt::Unchecked ); |
| 1324 | + } |
| 1325 | + else |
| 1326 | + { |
| 1327 | + mypItem->setCheckState( 0, Qt::Checked ); |
| 1328 | + } |
| 1329 | + |
| 1330 | + // add driver metadata |
| 1331 | + mypItem->setText( 1, myDriversExt[myName] ); |
| 1332 | + mypItem->setText( 2, myDriversFlags[myName] ); |
| 1333 | + mypItem->setText( 3, myDriversLongName[myName] ); |
| 1334 | + |
| 1335 | + lstGdalDrivers->addTopLevelItem( mypItem ); |
| 1336 | + } |
| 1337 | + // adjust column width |
| 1338 | + for ( int i = 0; i < 4; i++ ) |
| 1339 | + { |
| 1340 | + lstGdalDrivers->resizeColumnToContents( i ); |
| 1341 | + lstGdalDrivers->setColumnWidth( i, lstGdalDrivers->columnWidth( i ) + 5 ); |
| 1342 | + } |
| 1343 | +} |
1231 | 1344 |
|
1232 | 1345 | void QgsOptions::saveGdalDriverList() |
1233 | 1346 | { |
1234 | | - for ( int i = 0; i < lstGdalDrivers->count(); i++ ) |
| 1347 | + for ( int i = 0; i < lstGdalDrivers->topLevelItemCount(); i++ ) |
1235 | 1348 | { |
1236 | | - QListWidgetItem * mypItem = lstGdalDrivers->item( i ); |
1237 | | - if ( mypItem->checkState() == Qt::Unchecked ) |
| 1349 | + // QListWidgetItem * mypItem = lstGdalDrivers->item( i ); |
| 1350 | + QTreeWidgetItem * mypItem = lstGdalDrivers->topLevelItem( i ); |
| 1351 | + if ( mypItem->checkState( 0 ) == Qt::Unchecked ) |
1238 | 1352 | { |
1239 | | - QgsApplication::skipGdalDriver( mypItem->text() ); |
| 1353 | + QgsApplication::skipGdalDriver( mypItem->text( 0 ) ); |
1240 | 1354 | } |
1241 | 1355 | else |
1242 | 1356 | { |
1243 | | - QgsApplication::restoreGdalDriver( mypItem->text() ); |
| 1357 | + QgsApplication::restoreGdalDriver( mypItem->text( 0 ) ); |
1244 | 1358 | } |
1245 | 1359 | } |
1246 | 1360 | QSettings mySettings; |
|
0 commit comments