Skip to content

Commit b843f81

Browse files
committedJan 21, 2015
fixed browser single layer zip files path, fixes hopefully #11871
1 parent 670ad7b commit b843f81

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed
 

‎src/core/qgsdataitem.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren()
12801280
{
12811281
QVector<QgsDataItem*> children;
12821282
QString tmpPath;
1283-
QString childPath;
12841283
QSettings settings;
12851284
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
12861285

@@ -1330,7 +1329,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren()
13301329
if ( item )
13311330
{
13321331
QgsDebugMsgLevel( "loaded item", 3 );
1333-
childPath = tmpPath;
13341332
children.append( item );
13351333
break;
13361334
}
@@ -1343,12 +1341,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren()
13431341

13441342
}
13451343

1346-
if ( children.size() == 1 )
1347-
{
1348-
// save the name of the only child so we can get a normal data item from it
1349-
mPath = childPath;
1350-
}
1351-
13521344
return children;
13531345
}
13541346

@@ -1361,7 +1353,6 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString filePath, QS
13611353
{
13621354
QSettings settings;
13631355
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
1364-
QString vsiPath = path;
13651356
int zipFileCount = 0;
13661357
QStringList zipFileList;
13671358
QFileInfo fileInfo( filePath );
@@ -1416,14 +1407,21 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString filePath, QS
14161407
// if 1 or 0 child found, create a single data item using the normal path or the full path given by QgsZipItem
14171408
else
14181409
{
1410+
QString vsiPath = vsiPrefix + filePath;
14191411
if ( zipItem )
14201412
{
1421-
vsiPath = zipItem->path();
1413+
if ( zipItem->children().size() == 1 )
1414+
{
1415+
// take the name of the only child so we can get a normal data item from it
1416+
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( zipItem->children().first() );
1417+
if ( layerItem )
1418+
vsiPath = layerItem->uri();
1419+
}
14221420
zipFileCount = zipFileList.count();
14231421
delete zipItem;
14241422
}
14251423

1426-
QgsDebugMsgLevel( QString( "will try to create a normal dataItem from path= %2 or %3" ).arg( path ).arg( vsiPath ), 3 );
1424+
QgsDebugMsgLevel( QString( "will try to create a normal dataItem from filePath= %2 or vsiPath = %3" ).arg( filePath ).arg( vsiPath ), 3 );
14271425

14281426
// try to open using registered providers (gdal and ogr)
14291427
for ( int i = 0; i < mProviderNames.size(); i++ )
@@ -1437,7 +1435,7 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString filePath, QS
14371435
// (e.g. testZipItemVectorTransparency(), second test)
14381436
if (( mProviderNames[i] == "ogr" ) ||
14391437
( mProviderNames[i] == "gdal" && zipFileCount == 1 ) )
1440-
item = dataItem( path, parent );
1438+
item = dataItem( filePath, parent );
14411439
// try with /vsizip/
14421440
if ( ! item )
14431441
item = dataItem( vsiPath, parent );

‎src/providers/gdal/qgsgdaldataitems.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
228228
if ( !thePath.startsWith( vsiPrefix ) )
229229
thePath = vsiPrefix + thePath;
230230
// if this is a /vsigzip/path_to_zip.zip/file_inside_zip remove the full path from the name
231+
// no need to change the name I believe
232+
/*
231233
if (( is_vsizip || is_vsitar ) && ( thePath != vsiPrefix + parentItem->path() ) )
232234
{
233235
name = thePath;
234236
name = name.replace( vsiPrefix + parentItem->path() + "/", "" );
235237
}
238+
*/
236239
}
237240

238241
// return item without testing if:

‎src/providers/ogr/qgsogrdataitems.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
326326
if ( !thePath.startsWith( vsiPrefix ) )
327327
thePath = vsiPrefix + thePath;
328328
// if this is a /vsigzip/path_to_zip.zip/file_inside_zip remove the full path from the name
329+
// no need to change the name I believe
330+
/*
329331
if (( is_vsizip || is_vsitar ) && ( thePath != vsiPrefix + parentItem->path() ) )
330332
{
331333
name = thePath;
332334
name = name.replace( vsiPrefix + parentItem->path() + "/", "" );
333335
}
336+
*/
334337
}
335338

336339
// return item without testing if:

0 commit comments

Comments
 (0)
Please sign in to comment.