Skip to content
Permalink
Browse files
fix ziplayer handling for windows
  • Loading branch information
etiennesky committed May 8, 2012
1 parent d3eae08 commit e23e21f90744456e2b43370b6d71296e0bb3c62b
Showing with 49 additions and 22 deletions.
  1. +0 −1 src/core/qgsdataitem.cpp
  2. +8 −7 src/core/qgsmaplayer.cpp
  3. +41 −14 tests/src/core/testziplayer.cpp
@@ -897,7 +897,6 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )

QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QString name )
{

QSettings settings;
int scanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
QString vsizipPath = path;
@@ -553,15 +553,16 @@ QString QgsMapLayer::styleURI( )
{
QString myURI = publicSource();

// if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
if ( myURI.left( 9 ) == "/vsigzip/" )
// if file is using the VSIFILE mechanism, remove the prefix
if ( myURI.startsWith( "/vsigzip/", Qt::CaseInsensitive ) )
{
myURI.remove( 1, 9 );
myURI.remove( 0, 9 );
}
else if ( myURI.left( 8 ) == "/vsizip/" && myURI.right( 4 ) == ".zip" )
else if ( myURI.startsWith( "/vsizip/", Qt::CaseInsensitive ) &&
myURI.endsWith( ".zip", Qt::CaseInsensitive ) )
{
// ideally we should look for .qml file inside zip file
myURI.remove( 1, 8 );
myURI.remove( 0, 8 );
}

QFileInfo myFileInfo( myURI );
@@ -570,12 +571,12 @@ QString QgsMapLayer::styleURI( )
if ( myFileInfo.exists() )
{
// if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
if ( myURI.right( 3 ) == ".gz" )
if ( myURI.endsWith( ".gz", Qt::CaseInsensitive ) )
{
myURI.chop( 3 );
myFileInfo.setFile( myURI );
}
else if ( myURI.right( 4 ) == ".zip" )
else if ( myURI.endsWith( ".zip", Qt::CaseInsensitive ) )
{
myURI.chop( 4 );
myFileInfo.setFile( myURI );
@@ -41,7 +41,6 @@ class TestZipLayer: public QObject
private:

QString mDataDir;
QSettings mSettings;
int mMaxScanZipSetting;
int mScanZipSetting;

@@ -191,7 +190,11 @@ bool TestZipLayer::testZipItem( QString myFileName, QString myChildName = "" )
int TestZipLayer::getLayerTransparency( QString myFileName, QString myProviderKey, int myScanZipSetting )
{
int myTransparency = -1;
mSettings.setValue( "/qgis/scanZipInBrowser", myScanZipSetting );
QSettings settings;
settings.setValue( "/qgis/scanZipInBrowser", myScanZipSetting );
if ( myScanZipSetting != settings.value( "/qgis/scanZipInBrowser" ).toInt() )
return myTransparency;

QgsMapLayer * myLayer = NULL;
if ( myScanZipSetting == 1 )
myLayer = getLayer( myFileName, "", myProviderKey );
@@ -214,10 +217,16 @@ void TestZipLayer::initTestCase()
QgsApplication::initQgis();
// save data dir
mDataDir = QString( TEST_DATA_DIR ) + QDir::separator();
// set zipSetting to 1 (Passthru) and save current value
mScanZipSetting = mSettings.value( "/qgis/scanZipInBrowser", 1 ).toInt();
mSettings.setValue( "/qgis/scanZipInBrowser", 1 );
// max zipSetting value, depending on zlib presence
// Set up the QSettings environment
QCoreApplication::setOrganizationName( "QuantumGIS" );
QCoreApplication::setOrganizationDomain( "qgis.org" );
QCoreApplication::setApplicationName( "QGIS-TEST" );

// save current zipSetting value
QSettings settings;
mScanZipSetting = settings.value( "/qgis/scanZipInBrowser", 1 ).toInt();

// max zipSetting value depends on zlib presence
mMaxScanZipSetting = 1;
#ifdef HAVE_ZLIB
mMaxScanZipSetting = 3;
@@ -228,12 +237,14 @@ void TestZipLayer::initTestCase()
void TestZipLayer::cleanupTestCase()
{
// restore zipSetting
mSettings.setValue( "/qgis/scanZipInBrowser", mScanZipSetting );
QSettings settings;
settings.setValue( "/qgis/scanZipInBrowser", mScanZipSetting );
}


void TestZipLayer::testPassthruVectorZip()
{
QSettings settings;
QString myFileName = mDataDir + "points2.zip";
QgsDebugMsg( "GDAL: " + QString( GDAL_RELEASE_NAME ) );
#if GDAL_VERSION_NUM < 1800
@@ -242,62 +253,76 @@ void TestZipLayer::testPassthruVectorZip()
QgsDebugMsg( "FILE: " + QString( myFileName ) );
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
{
mSettings.setValue( "/qgis/scanZipInBrowser", i );
settings.setValue( "/qgis/scanZipInBrowser", i );
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
QVERIFY( testZipItemPassthru( myFileName, "ogr" ) );
}
}

void TestZipLayer::testPassthruVectorGzip()
{
QSettings settings;
#if GDAL_VERSION_NUM < 1700
QSKIP( "This test requires GDAL > 1.7", SkipSingle );
#endif
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
{
mSettings.setValue( "/qgis/scanZipInBrowser", i );
settings.setValue( "/qgis/scanZipInBrowser", i );
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
QVERIFY( testZipItemPassthru( mDataDir + "points3.geojson.gz", "ogr" ) );
}
}

void TestZipLayer::testPassthruRasterZip()
{
QSettings settings;
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
{
mSettings.setValue( "/qgis/scanZipInBrowser", i );
settings.setValue( "/qgis/scanZipInBrowser", i );
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
QVERIFY( testZipItemPassthru( mDataDir + "landsat_b1.zip", "gdal" ) );
}
}

void TestZipLayer::testPassthruRasterGzip()
{
QSettings settings;
for ( int i = 1 ; i <= mMaxScanZipSetting ; i++ )
{
mSettings.setValue( "/qgis/scanZipInBrowser", i );
settings.setValue( "/qgis/scanZipInBrowser", i );
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
QVERIFY( testZipItemPassthru( mDataDir + "landsat_b1.tif.gz", "gdal" ) );
}
}

void TestZipLayer::testZipItemRaster()
{
QSettings settings;

#ifndef HAVE_ZLIB
QSKIP( "This test requires ZLIB", SkipSingle );
#endif

for ( int i = 2 ; i <= mMaxScanZipSetting ; i++ )
{
mSettings.setValue( "/qgis/scanZipInBrowser", i );
settings.setValue( "/qgis/scanZipInBrowser", i );
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
QVERIFY( testZipItem( mDataDir + "testzip.zip", "landsat_b1.tif" ) );
}
}

void TestZipLayer::testZipItemVector()
{
QSettings settings;

#ifndef HAVE_ZLIB
QSKIP( "This test requires ZLIB", SkipSingle );
#endif

for ( int i = 2 ; i <= mMaxScanZipSetting ; i++ )
{
mSettings.setValue( "/qgis/scanZipInBrowser", i );
settings.setValue( "/qgis/scanZipInBrowser", i );
QVERIFY( i == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
QVERIFY( testZipItem( mDataDir + "testzip.zip", "points.shp" ) );
}
}
@@ -311,7 +336,9 @@ void TestZipLayer::testZipItemAll()
// test for all items inside zip, using zipSetting 3 (Full Scan) which will ignore invalid items
// using zipSetting 2 (Basic Scan) would raise errors, because QgsZipItem would not test for valid items
// and return child names of the invalid items
mSettings.setValue( "/qgis/scanZipInBrowser", 3 );
QSettings settings;
settings.setValue( "/qgis/scanZipInBrowser", 3 );
QVERIFY( 3 == settings.value( "/qgis/scanZipInBrowser" ).toInt() );
QVERIFY( testZipItem( mDataDir + "testzip.zip", "" ) );
}

0 comments on commit e23e21f

Please sign in to comment.