Skip to content

Commit

Permalink
scanItemsInBrowser2/scanZipInBrowser2 : remove QgsApplication::upgrad…
Browse files Browse the repository at this point in the history
…eConfig() and fix tests
  • Loading branch information
etiennesky committed Nov 15, 2012
1 parent 565d2eb commit 7d0d5d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 98 deletions.
85 changes: 0 additions & 85 deletions src/core/qgsapplication.cpp
Expand Up @@ -583,9 +583,6 @@ void QgsApplication::initQgis()

// create map layer registry if doesn't exist
QgsMapLayerRegistry::instance();

// upgrade config options from older version
upgradeConfig();
}

void QgsApplication::exitQgis()
Expand Down Expand Up @@ -862,86 +859,4 @@ void QgsApplication::applyGdalSkippedDrivers()
GDALAllRegister(); //to update driver list and skip missing ones
}

void QgsApplication::upgradeConfig()
{
QSettings settings;

/* Due to changes in settings storage types for "scan items" and "scan zip" settings,
qgis-1.8 and qgis-1.9 have conficting values, so the keys have been renamed
Here we do a 1-time check to copy old setting to new setting
*/

// use a special settings key so we only check once
if ( ! settings.value( "/qgis/scanInBrowserUpgradeChecked", false ).toBool() )
{
QVariant v;
int i;
QString s;
bool ok;

// check if new setting is empty
if ( settings.value( "/qgis/scanItemsInBrowser2" ).isNull() )
{
v = settings.value( "/qgis/scanItemsInBrowser" );
i = v.toInt( &ok );
// check if value was defined in qgis-1.8 (as int)
if ( ! v.isNull() && ok )
{
// convert old setting to new setting
switch ( i )
{
case 0:
s = "contents";
break;
case 1:
s = "extension";
break;
default:
s = "";
break;
}
settings.setValue( "/qgis/scanItemsInBrowser2", s );
}
// check if value was defined in qgis-1.9 (as QString)
else if ( ! v.isNull() && !v.toString().isEmpty() )
{
s = v.toString();
settings.setValue( "/qgis/scanItemsInBrowser2", s );
}
}

if ( settings.value( "/qgis/scanZipInBrowser2" ).isNull() )
{
v = settings.value( "/qgis/scanZipInBrowser" );
i = v.toInt( & ok );
if ( ! v.isNull() && ok )
{
switch ( i )
{
case 0:
s = "No";
break;
case 1: // passthru removed, use basic instead
case 2:
s = "basic";
break;
case 3:
s = "full";
break;
default:
s = "";
break;
}
settings.setValue( "/qgis/scanZipInBrowser2", s );
}
else if ( ! v.isNull() && !v.toString().isEmpty() )
{
s = v.toString();
settings.setValue( "/qgis/scanZipInBrowser2", s );
}
}

settings.setValue( "/qgis/scanInBrowserUpgradeChecked", true );
}
}

4 changes: 0 additions & 4 deletions src/core/qgsapplication.h
Expand Up @@ -270,10 +270,6 @@ class CORE_EXPORT QgsApplication: public QApplication
* @note added in 2.0 */
static void applyGdalSkippedDrivers();

/** upgrades config options from older version, called by initQGis
* @note added in 2.0 */
static void upgradeConfig();

signals:
//! @note not available in python bindings
void preNotify( QObject * receiver, QEvent * event, bool * done );
Expand Down
16 changes: 9 additions & 7 deletions tests/src/core/testqgsdataitem.cpp
Expand Up @@ -42,7 +42,7 @@ class TestQgsDataItem: public QObject

private:
QgsDirectoryItem* mDirItem;
int mScanItemsSetting;
QString mScanItemsSetting;
bool isValidDirItem( QgsDirectoryItem *item );
};

Expand All @@ -62,7 +62,7 @@ void TestQgsDataItem::initTestCase()
QCoreApplication::setApplicationName( "QGIS-TEST" );
// save current scanItemsSetting value
QSettings settings;
mScanItemsSetting = settings.value( "/qgis/scanItemsInBrowser2", 0 ).toInt();
mScanItemsSetting = settings.value( "/qgis/scanItemsInBrowser2", QVariant( "" ) ).toString();

//create a directory item that will be used in all tests...
mDirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR );
Expand Down Expand Up @@ -94,9 +94,11 @@ void TestQgsDataItem::testValid()
void TestQgsDataItem::testDirItemChildren()
{
QSettings settings;
for ( int iSetting = 0 ; iSetting <= 1 ; iSetting++ )
QStringList tmpSettings;
tmpSettings << "" << "contents" << "extension";
foreach ( QString tmpSetting, tmpSettings )
{
settings.setValue( "/qgis/scanItemsInBrowser2", iSetting );
settings.setValue( "/qgis/scanItemsInBrowser2", tmpSetting );
QgsDirectoryItem* dirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR );
QVERIFY( isValidDirItem( dirItem ) );

Expand All @@ -112,9 +114,9 @@ void TestQgsDataItem::testDirItemChildren()
QFileInfo info( layerItem->path() );
QString lFile = info.fileName();
QString lProvider = layerItem->providerKey();
QString errStr = QString( "layer #%1 - %2 provider = %3 iSetting = %4" ).arg( i ).arg( lFile ).arg( lProvider ).arg( iSetting );
QString errStr = QString( "layer #%1 - %2 provider = %3 tmpSetting = %4" ).arg( i ).arg( lFile ).arg( lProvider ).arg( tmpSetting );

QgsDebugMsg( QString( "testing child name=%1 provider=%2 path=%3" ).arg( layerItem->name() ).arg( lProvider ).arg( lFile ) );
QgsDebugMsg( QString( "testing child name=%1 provider=%2 path=%3 tmpSetting = %4" ).arg( layerItem->name() ).arg( lProvider ).arg( lFile ).arg( tmpSetting ) );

if ( lFile == "landsat.tif" )
{
Expand All @@ -139,7 +141,7 @@ void TestQgsDataItem::testDirItemChildren()

// test layerName() does not include extension for gdal and ogr items (bug #5621)
QString lName = layerItem->layerName();
errStr = QString( "layer #%1 - %2 lName = %3 iSetting = %4" ).arg( i ).arg( lFile ).arg( lName ).arg( iSetting );
errStr = QString( "layer #%1 - %2 lName = %3 tmpSetting = %4" ).arg( i ).arg( lFile ).arg( lName ).arg( tmpSetting );

if ( lFile == "landsat.tif" )
{
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testziplayer.cpp
Expand Up @@ -274,8 +274,8 @@ void TestZipLayer::initTestCase()
// save current zipSetting value
QSettings settings;
mSettingsKey = "/qgis/scanZipInBrowser2";
mScanZipSetting = settings.value( mSettingsKey, "basic" ).toString();
mScanZipSettings << "basic" << "full";
mScanZipSetting = settings.value( mSettingsKey, "" ).toString();
mScanZipSettings << "" << "basic" << "full";
}

void TestZipLayer::cleanupTestCase()
Expand Down

0 comments on commit 7d0d5d3

Please sign in to comment.