@@ -809,8 +809,7 @@ QVector<QgsDataItem *> QgsDirectoryItem::createChildren()
809
809
continue ;
810
810
}
811
811
812
- // vsizip support was added to GDAL/OGR 1.6 but GDAL_VERSION_NUM not available here
813
- // so we assume it's available anyway
812
+ if ( fileInfo.suffix () == QLatin1String ( " zip" ) )
814
813
{
815
814
QgsDataItem *item = QgsZipItem::itemFromPath ( this , path, name, mPath + ' /' + name );
816
815
if ( item )
@@ -1262,7 +1261,6 @@ QVector<QgsDataItem *> QgsFavoritesItem::createChildren( const QString &favDir,
1262
1261
1263
1262
// -----------------------------------------------------------------------
1264
1263
QStringList QgsZipItem::sProviderNames = QStringList();
1265
- QVector<dataItem_t *> QgsZipItem::sDataItemPtr = QVector<dataItem_t *>();
1266
1264
1267
1265
1268
1266
QgsZipItem::QgsZipItem ( QgsDataItem *parent, const QString &name, const QString &path )
@@ -1287,51 +1285,8 @@ void QgsZipItem::init()
1287
1285
1288
1286
if ( sProviderNames .isEmpty () )
1289
1287
{
1290
- // QStringList keys = QgsProviderRegistry::instance()->providerList();
1291
- // only use GDAL and OGR providers as we use the VSIFILE mechanism
1292
- QStringList keys;
1293
- // keys << "ogr" << "gdal";
1294
- keys << QStringLiteral ( " gdal" ) << QStringLiteral ( " ogr" );
1295
-
1296
- for ( const auto &k : qgis::as_const ( keys ) )
1297
- {
1298
- QgsDebugMsgLevel ( " provider " + k, 3 );
1299
- // some providers hangs with empty uri (PostGIS) etc...
1300
- // -> using libraries directly
1301
- std::unique_ptr< QLibrary > library ( QgsProviderRegistry::instance ()->createProviderLibrary ( k ) );
1302
- if ( library )
1303
- {
1304
- dataCapabilities_t *dataCapabilities = reinterpret_cast < dataCapabilities_t * >( cast_to_fptr ( library->resolve ( " dataCapabilities" ) ) );
1305
- if ( !dataCapabilities )
1306
- {
1307
- QgsDebugMsg ( library->fileName () + " does not have dataCapabilities" );
1308
- continue ;
1309
- }
1310
- if ( dataCapabilities () == QgsDataProvider::NoDataCapabilities )
1311
- {
1312
- QgsDebugMsg ( library->fileName () + " has NoDataCapabilities" );
1313
- continue ;
1314
- }
1315
- QgsDebugMsg ( QString ( " %1 dataCapabilities : %2" ).arg ( library->fileName () ).arg ( dataCapabilities () ) );
1316
-
1317
- dataItem_t *dataItem = reinterpret_cast < dataItem_t * >( cast_to_fptr ( library->resolve ( " dataItem" ) ) );
1318
- if ( ! dataItem )
1319
- {
1320
- QgsDebugMsg ( library->fileName () + " does not have dataItem" );
1321
- continue ;
1322
- }
1323
-
1324
- // mLibraries.append( library );
1325
- sDataItemPtr .append ( dataItem );
1326
- sProviderNames .append ( k );
1327
- }
1328
- else
1329
- {
1330
- // QgsDebugMsg ( "Cannot get provider " + k );
1331
- }
1332
- }
1288
+ sProviderNames << QStringLiteral ( " OGR" ) << QStringLiteral ( " OGR" );
1333
1289
}
1334
-
1335
1290
}
1336
1291
1337
1292
QVector<QgsDataItem *> QgsZipItem::createChildren ()
@@ -1343,7 +1298,7 @@ QVector<QgsDataItem *> QgsZipItem::createChildren()
1343
1298
1344
1299
mZipFileList .clear ();
1345
1300
1346
- QgsDebugMsgLevel ( QString ( " mFilePath = %1 path = %2 name= %3 scanZipSetting= %4 vsiPrefix= %5" ).arg ( mFilePath , path (), name (), scanZipSetting, mVsiPrefix ), 2 );
1301
+ QgsDebugMsgLevel ( QString ( " mFilePath = %1 path = %2 name= %3 scanZipSetting= %4 vsiPrefix= %5" ).arg ( mFilePath , path (), name (), scanZipSetting, mVsiPrefix ), 3 );
1347
1302
1348
1303
// if scanZipBrowser == no: skip to the next file
1349
1304
if ( scanZipSetting == QLatin1String ( " no" ) )
@@ -1354,18 +1309,22 @@ QVector<QgsDataItem *> QgsZipItem::createChildren()
1354
1309
// first get list of files
1355
1310
getZipFileList ();
1356
1311
1312
+ const QList<QgsDataItemProvider *> providers = QgsApplication::dataItemProviderRegistry ()->providers ();
1313
+
1357
1314
// loop over files inside zip
1358
1315
Q_FOREACH ( const QString &fileName, mZipFileList )
1359
1316
{
1360
1317
QFileInfo info ( fileName );
1361
1318
tmpPath = mVsiPrefix + mFilePath + ' /' + fileName;
1362
1319
QgsDebugMsgLevel ( " tmpPath = " + tmpPath, 3 );
1363
1320
1364
- // Q_FOREACH( dataItem_t *dataItem, mDataItemPtr )
1365
- for ( int i = 0 ; i < sProviderNames .size (); i++ )
1321
+ for ( QgsDataItemProvider *provider : providers )
1366
1322
{
1323
+ if ( !sProviderNames .contains ( provider->name () ) )
1324
+ continue ;
1325
+
1367
1326
// ugly hack to remove .dbf file if there is a .shp file
1368
- if ( sProviderNames [i] == QLatin1String ( " ogr " ) )
1327
+ if ( provider-> name () == QStringLiteral ( " OGR " ) )
1369
1328
{
1370
1329
if ( info.suffix ().compare ( QLatin1String ( " dbf" ), Qt::CaseInsensitive ) == 0 )
1371
1330
{
@@ -1378,26 +1337,19 @@ QVector<QgsDataItem *> QgsZipItem::createChildren()
1378
1337
}
1379
1338
}
1380
1339
1381
- // try to get data item from provider
1382
- dataItem_t *dataItem = sDataItemPtr . at ( i );
1383
- if ( dataItem )
1340
+ QgsDebugMsgLevel ( QString ( " trying to load item %1 with %2 " ). arg ( tmpPath, provider-> name () ), 3 );
1341
+ QgsDataItem *item = provider-> createDataItem ( tmpPath, this );
1342
+ if ( item )
1384
1343
{
1385
- QgsDebugMsgLevel ( QString ( " trying to load item %1 with %2" ).arg ( tmpPath, sProviderNames .at ( i ) ), 3 );
1386
- QgsDataItem *item = dataItem ( tmpPath, this );
1387
- if ( item )
1388
- {
1389
- QgsDebugMsgLevel ( " loaded item" , 3 );
1390
- // the item comes with zipped file name, set the name to relative path within zip file
1391
- item->setName ( fileName );
1392
- children.append ( item );
1393
- }
1394
- else
1395
- {
1396
- QgsDebugMsgLevel ( " not loaded item" , 3 );
1397
- }
1344
+ // the item comes with zipped file name, set the name to relative path within zip file
1345
+ item->setName ( fileName );
1346
+ children.append ( item );
1347
+ }
1348
+ else
1349
+ {
1350
+ QgsDebugMsgLevel ( " not loaded item" , 3 );
1398
1351
}
1399
1352
}
1400
-
1401
1353
}
1402
1354
1403
1355
return children;
@@ -1412,7 +1364,6 @@ QgsDataItem *QgsZipItem::itemFromPath( QgsDataItem *parent, const QString &fileP
1412
1364
{
1413
1365
QgsSettings settings;
1414
1366
QString scanZipSetting = settings.value ( QStringLiteral ( " qgis/scanZipInBrowser2" ), " basic" ).toString ();
1415
- int zipFileCount = 0 ;
1416
1367
QStringList zipFileList;
1417
1368
QString vsiPrefix = QgsZipItem::vsiPrefix ( filePath );
1418
1369
QgsZipItem *zipItem = nullptr ;
@@ -1462,48 +1413,8 @@ QgsDataItem *QgsZipItem::itemFromPath( QgsDataItem *parent, const QString &fileP
1462
1413
QgsDebugMsgLevel ( " returning zipItem" , 3 );
1463
1414
return zipItem;
1464
1415
}
1465
- // if 1 or 0 child found, create a single data item using the normal path or the full path given by QgsZipItem
1466
- else
1467
- {
1468
- QString vsiPath = vsiPrefix + filePath;
1469
- if ( zipItem )
1470
- {
1471
- QVector<QgsDataItem *> children = zipItem->children ();
1472
- if ( children.size () == 1 )
1473
- {
1474
- // take the name of the only child so we can get a normal data item from it
1475
- QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( children.first () );
1476
- if ( layerItem )
1477
- vsiPath = layerItem->uri ();
1478
- }
1479
- zipFileCount = zipFileList.count ();
1480
- delete zipItem;
1481
- }
1482
-
1483
- QgsDebugMsgLevel ( QString ( " will try to create a normal dataItem from filePath= %2 or vsiPath = %3" ).arg ( filePath, vsiPath ), 3 );
1484
-
1485
- // try to open using registered providers (gdal and ogr)
1486
- for ( int i = 0 ; i < sProviderNames .size (); i++ )
1487
- {
1488
- dataItem_t *dataItem = sDataItemPtr .at ( i );
1489
- if ( dataItem )
1490
- {
1491
- QgsDataItem *item = nullptr ;
1492
- // try first with normal path (Passthru)
1493
- // this is to simplify .qml handling, and without this some tests will fail
1494
- // (e.g. testZipItemVectorTransparency(), second test)
1495
- if ( ( sProviderNames .at ( i ) == QLatin1String ( " ogr" ) ) ||
1496
- ( sProviderNames .at ( i ) == QLatin1String ( " gdal" ) && zipFileCount == 1 ) )
1497
- item = dataItem ( filePath, parent );
1498
- // try with /vsizip/
1499
- if ( ! item )
1500
- item = dataItem ( vsiPath, parent );
1501
- if ( item )
1502
- return item;
1503
- }
1504
- }
1505
- }
1506
1416
1417
+ // if 1 or 0 child found, let provider(s) create individual items
1507
1418
return nullptr ;
1508
1419
}
1509
1420
0 commit comments