Skip to content

Commit

Permalink
add QgsApplication::upgradeConfig to upgrade any configs that changed…
Browse files Browse the repository at this point in the history
… from 1.8

use different keys for scanItemsInBrowser and scanZipInBrowser in qgis-1.9 because new storage type (string vs. int) causes conflicts with 1.8
  • Loading branch information
etiennesky committed Nov 6, 2012
1 parent 038acbc commit b754f07
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2546,7 +2546,7 @@ bool QgisApp::askUserForZipItemLayers( QString path )
QgsDebugMsg( "askUserForZipItemLayers( " + path + ")" );

// if scanZipBrowser == no: skip to the next file
if ( settings.value( "/qgis/scanZipInBrowser", "basic" ).toString() == "no" )
if ( settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString() == "no" )
{
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
cmbScanItemsInBrowser->clear();
cmbScanItemsInBrowser->addItem( tr( "Check file contents" ), "contents" ); // 0
cmbScanItemsInBrowser->addItem( tr( "Check extension" ), "extension" ); // 1
int index = cmbScanItemsInBrowser->findData( settings.value( "/qgis/scanItemsInBrowser", "" ) );
int index = cmbScanItemsInBrowser->findData( settings.value( "/qgis/scanItemsInBrowser2", "" ) );
if ( index == -1 ) index = 1;
cmbScanItemsInBrowser->setCurrentIndex( index );

Expand All @@ -238,7 +238,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
// cmbScanZipInBrowser->addItem( tr( "Passthru" ) ); // 1 - removed
cmbScanZipInBrowser->addItem( tr( "Basic scan" ), QVariant( "basic" ) );
cmbScanZipInBrowser->addItem( tr( "Full scan" ), QVariant( "full" ) );
index = cmbScanZipInBrowser->findData( settings.value( "/qgis/scanZipInBrowser", "" ) );
index = cmbScanZipInBrowser->findData( settings.value( "/qgis/scanZipInBrowser2", "" ) );
if ( index == -1 ) index = 1;
cmbScanZipInBrowser->setCurrentIndex( index );

Expand Down Expand Up @@ -881,9 +881,9 @@ void QgsOptions::saveOptions()
settings.setValue( "/qgis/attributeTableBehaviour", cmbAttrTableBehaviour->currentIndex() );
settings.setValue( "/qgis/attributeTableRowCache", spinBoxAttrTableRowCache->value() );
settings.setValue( "/qgis/promptForRasterSublayers", cmbPromptRasterSublayers->currentIndex() );
settings.setValue( "/qgis/scanItemsInBrowser",
settings.setValue( "/qgis/scanItemsInBrowser2",
cmbScanItemsInBrowser->itemData( cmbScanItemsInBrowser->currentIndex() ).toString() );
settings.setValue( "/qgis/scanZipInBrowser",
settings.setValue( "/qgis/scanZipInBrowser2",
cmbScanZipInBrowser->itemData( cmbScanZipInBrowser->currentIndex() ).toString() );
settings.setValue( "/qgis/ignoreShapeEncoding", cbxIgnoreShapeEncoding->isChecked() );
settings.setValue( "/qgis/dockIdentifyResults", cbxIdentifyResultsDocked->isChecked() );
Expand Down
87 changes: 87 additions & 0 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ 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 @@ -858,3 +861,87 @@ void QgsApplication::applyGdalSkippedDrivers()
CPLSetConfigOption( "GDAL_SKIP", myDriverList.toUtf8() );
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: 4 additions & 0 deletions src/core/qgsapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ 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
8 changes: 4 additions & 4 deletions src/core/qgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren( )

QString vsiPrefix = QgsZipItem::vsiPrefix( path );
// vsizip support was added to GDAL/OGR 1.6 but GDAL_VERSION_NUM not available here
if (( settings.value( "/qgis/scanZipInBrowser", QVariant( "basic" ) ).toString() != "no" ) &&
if (( settings.value( "/qgis/scanZipInBrowser2", QVariant( "basic" ) ).toString() != "no" ) &&
( vsiPrefix == "/vsizip/" || vsiPrefix == "/vsitar/" ) )
{
QgsDataItem * item = QgsZipItem::itemFromPath( this, path, name );
Expand Down Expand Up @@ -857,7 +857,7 @@ QVector<QgsDataItem*> QgsZipItem::createChildren( )
QString tmpPath;
QString childPath;
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();

mZipFileList.clear();

Expand Down Expand Up @@ -955,7 +955,7 @@ QString QgsZipItem::vsiPrefix( QString path )
QgsDataItem* QgsZipItem::itemFromPath( QgsDataItem* parent, QString path, QString name )
{
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
QString vsiPath = path;
int zipFileCount = 0;
QStringList zipFileList;
Expand Down Expand Up @@ -1059,7 +1059,7 @@ const QStringList & QgsZipItem::getZipFileList()

QString tmpPath;
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();

QgsDebugMsgLevel( QString( "path = %1 name= %2 scanZipSetting= %3 vsiPrefix= %4" ).arg( path() ).arg( name() ).arg( scanZipSetting ).arg( mVsiPrefix ), 3 );

Expand Down
4 changes: 2 additions & 2 deletions src/providers/gdal/qgsgdaldataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )

// zip settings + info
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
QString vsiPrefix = QgsZipItem::vsiPrefix( thePath );
bool is_vsizip = ( vsiPrefix == "/vsizip/" );
bool is_vsigzip = ( vsiPrefix == "/vsigzip/" );
Expand Down Expand Up @@ -217,7 +217,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
// not zipfile and scan items == "Check extension"
if ((( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) ||
( !is_vsizip && !is_vsitar &&
( settings.value( "/qgis/scanItemsInBrowser",
( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ) )
{
// if this is a VRT file make sure it is raster VRT to avoid duplicates
Expand Down
2 changes: 1 addition & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,7 @@ void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString
// VSIFileHandler (see qgsogrprovider.cpp)
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
QSettings settings;
if ( settings.value( "/qgis/scanZipInBrowser", "basic" ).toString() != "no" )
if ( settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString() != "no" )
{
QString glob = "*.zip";
glob += " *.gz";
Expand Down
4 changes: 2 additions & 2 deletions src/providers/ogr/qgsogrdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )

// zip settings + info
QSettings settings;
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser", "basic" ).toString();
QString scanZipSetting = settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString();
QString vsiPrefix = QgsZipItem::vsiPrefix( thePath );
bool is_vsizip = ( vsiPrefix == "/vsizip/" );
bool is_vsigzip = ( vsiPrefix == "/vsigzip/" );
Expand Down Expand Up @@ -318,7 +318,7 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
// not zipfile and scan items == "Check extension"
if ((( is_vsizip || is_vsitar ) && scanZipSetting == "basic" ) ||
( !is_vsizip && !is_vsitar &&
( settings.value( "/qgis/scanItemsInBrowser",
( settings.value( "/qgis/scanItemsInBrowser2",
"extension" ).toString() == "extension" ) ) )
{
// if this is a VRT file make sure it is vector VRT to avoid duplicates
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ QString createFilters( QString type )
// This does not work for some file types, see VSIFileHandler doc.
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1600
QSettings settings;
if ( settings.value( "/qgis/scanZipInBrowser", "basic" ).toString() != "no" )
if ( settings.value( "/qgis/scanZipInBrowser2", "basic" ).toString() != "no" )
{
myFileFilters += createFileFilter_( QObject::tr( "GDAL/OGR VSIFileHandler" ), "*.zip *.gz *.tar *.tar.gz *.tgz" );
myExtensions << "zip" << "gz" << "tar" << "tar.gz" << "tgz";
Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testqgsdataitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void TestQgsDataItem::initTestCase()
QCoreApplication::setApplicationName( "QGIS-TEST" );
// save current scanItemsSetting value
QSettings settings;
mScanItemsSetting = settings.value( "/qgis/scanItemsInBrowser", 0 ).toInt();
mScanItemsSetting = settings.value( "/qgis/scanItemsInBrowser2", 0 ).toInt();

This comment has been minimized.

Copy link
@brushtyler

brushtyler Nov 6, 2012

Contributor

is 0 the correct default value for scanItemsInBrowser2?

This comment has been minimized.

Copy link
@etiennesky

etiennesky Nov 6, 2012

Author Contributor

no this is a mistake


//create a directory item that will be used in all tests...
mDirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR );
Expand All @@ -72,7 +72,7 @@ void TestQgsDataItem::cleanupTestCase()
{
// restore scanItemsSetting
QSettings settings;
settings.setValue( "/qgis/scanItemsInBrowser", mScanItemsSetting );
settings.setValue( "/qgis/scanItemsInBrowser2", mScanItemsSetting );
if ( mDirItem )
delete mDirItem;
}
Expand All @@ -96,7 +96,7 @@ void TestQgsDataItem::testDirItemChildren()
QSettings settings;
for ( int iSetting = 0 ; iSetting <= 1 ; iSetting++ )
{
settings.setValue( "/qgis/scanItemsInBrowser", iSetting );
settings.setValue( "/qgis/scanItemsInBrowser2", iSetting );
QgsDirectoryItem* dirItem = new QgsDirectoryItem( 0, "Test", TEST_DATA_DIR );
QVERIFY( isValidDirItem( dirItem ) );

Expand Down
Loading

5 comments on commit b754f07

@brushtyler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Etienne,
since we have broken APIs and the next release will be QGis 2.0, IMHO it isn't worth to convert the 1.8 settings values to 1.9/2.0 ones if they need a so twisted conversion (it's some code we will need to maintain).

I'd just replace scanZipInBrowser with scanZipInBrowser2.

@etiennesky
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I justs didn't want things to break for current users, but uf you think it's not worth it I can remove that and fix the default above

@brushtyler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I justs didn't want things to break for current users, but uf you think it's not worth it I can remove that

It would be worth for critical tasks that makes master unusable, but IMO a such minor break could occur in the development version, especially if the next release will be 2.0.

@etiennesky
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for your input

@etiennesky
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I fixed this in 565d2eb..7d0d5d3 - thanks

Please sign in to comment.