Skip to content

Commit

Permalink
fixed browser single layer zip files path, fixes hopefully #11871
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jan 21, 2015
1 parent 670ad7b commit b843f81
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/core/qgsdataitem.cpp
Expand Up @@ -1280,7 +1280,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren()
{
QVector<QgsDataItem*> children;
QString tmpPath;
QString childPath;
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();

Expand Down Expand Up @@ -1330,7 +1329,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren()
if ( item )
{
QgsDebugMsgLevel( "loaded item", 3 );
childPath = tmpPath;
children.append( item );
break;
}
Expand All @@ -1343,12 +1341,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren()

}

if ( children.size() == 1 )
{
// save the name of the only child so we can get a normal data item from it
mPath = childPath;
}

return children;
}

Expand All @@ -1361,7 +1353,6 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString filePath, QS
{
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
QString vsiPath = path;
int zipFileCount = 0;
QStringList zipFileList;
QFileInfo fileInfo( filePath );
Expand Down Expand Up @@ -1416,14 +1407,21 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString filePath, QS
// if 1 or 0 child found, create a single data item using the normal path or the full path given by QgsZipItem
else
{
QString vsiPath = vsiPrefix + filePath;
if ( zipItem )
{
vsiPath = zipItem->path();
if ( zipItem->children().size() == 1 )
{
// take the name of the only child so we can get a normal data item from it
QgsLayerItem *layerItem = qobject_cast<QgsLayerItem*>( zipItem->children().first() );
if ( layerItem )
vsiPath = layerItem->uri();
}
zipFileCount = zipFileList.count();
delete zipItem;
}

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

// try to open using registered providers (gdal and ogr)
for ( int i = 0; i < mProviderNames.size(); i++ )
Expand All @@ -1437,7 +1435,7 @@ QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString filePath, QS
// (e.g. testZipItemVectorTransparency(), second test)
if (( mProviderNames[i] == "ogr" ) ||
( mProviderNames[i] == "gdal" && zipFileCount == 1 ) )
item = dataItem( path, parent );
item = dataItem( filePath, parent );
// try with /vsizip/
if ( ! item )
item = dataItem( vsiPath, parent );
Expand Down
3 changes: 3 additions & 0 deletions src/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -228,11 +228,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
if ( !thePath.startsWith( vsiPrefix ) )
thePath = vsiPrefix + thePath;
// if this is a /vsigzip/path_to_zip.zip/file_inside_zip remove the full path from the name
// no need to change the name I believe
/*
if (( is_vsizip || is_vsitar ) && ( thePath != vsiPrefix + parentItem->path() ) )
{
name = thePath;
name = name.replace( vsiPrefix + parentItem->path() + "/", "" );
}
*/
}

// return item without testing if:
Expand Down
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrdataitems.cpp
Expand Up @@ -326,11 +326,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
if ( !thePath.startsWith( vsiPrefix ) )
thePath = vsiPrefix + thePath;
// if this is a /vsigzip/path_to_zip.zip/file_inside_zip remove the full path from the name
// no need to change the name I believe
/*
if (( is_vsizip || is_vsitar ) && ( thePath != vsiPrefix + parentItem->path() ) )
{
name = thePath;
name = name.replace( vsiPrefix + parentItem->path() + "/", "" );
}
*/
}

// return item without testing if:
Expand Down

0 comments on commit b843f81

Please sign in to comment.