Skip to content
Permalink
Browse files

fix symbol and color ramp saving - issues #6222 and #6227

  • Loading branch information
etiennesky committed Aug 23, 2012
1 parent 6bf56e8 commit b145998078c1a8fbb825eaf57f3d58edd62102d5
@@ -85,12 +85,21 @@ bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol, bool update )
if ( !symbol || name.isEmpty() )
return false;

delete mSymbols.value( name );

mSymbols.insert( name, symbol );

if ( update )
updateSymbol( SymbolEntity, name );
// delete previous symbol (if any)
if ( mSymbols.contains( name ) )
{
// TODO remove groups and tags?
delete mSymbols.value( name );
mSymbols.insert( name, symbol );
if ( update )
updateSymbol( SymbolEntity, name );
}
else
{
mSymbols.insert( name, symbol );
if ( update )
saveSymbol( name, symbol, 0, QStringList() );
}

return true;
}
@@ -179,12 +188,20 @@ bool QgsStyleV2::addColorRamp( QString name, QgsVectorColorRampV2* colorRamp, bo
return false;

// delete previous symbol (if any)
delete mColorRamps.value( name );

mColorRamps.insert( name, colorRamp );

if ( update )
updateSymbol( ColorrampEntity, name );
if ( mSymbols.contains( name ) )
{
// TODO remove groups and tags?
delete mColorRamps.value( name );
mColorRamps.insert( name, colorRamp );
if ( update )
updateSymbol( ColorrampEntity, name );
}
else
{
mColorRamps.insert( name, colorRamp );
if ( update )
saveColorRamp( name, colorRamp, 0, QStringList() );
}

return true;
}
@@ -1398,7 +1415,7 @@ bool QgsStyleV2::updateSymbol( StyleEntity type, QString name )
// check if it is an existing symbol
if ( !symbolNames().contains( name ) )
{
QgsDebugMsg( "Update request recieved for unavailable symbol" );
QgsDebugMsg( "Update request received for unavailable symbol" );
return false;
}

@@ -1410,7 +1427,7 @@ bool QgsStyleV2::updateSymbol( StyleEntity type, QString name )
}
symEl.save( stream, 4 );
query = sqlite3_mprintf( "UPDATE symbol SET xml='%q' WHERE name='%q';",
xmlArray.constData(), name.toUtf8().constData() );
xmlArray.constData(), name.toUtf8().constData() );
}
else if ( type == ColorrampEntity )
{
@@ -1428,7 +1445,7 @@ bool QgsStyleV2::updateSymbol( StyleEntity type, QString name )
}
symEl.save( stream, 4 );
query = sqlite3_mprintf( "UPDATE colorramp SET xml='%q' WHERE name='%q';",
xmlArray.constData(), name.toUtf8().constData() );
xmlArray.constData(), name.toUtf8().constData() );
}
else
{
@@ -90,7 +90,7 @@ class CORE_EXPORT QgsStyleV2

//! adds a new group and returns the group's id
/*!
* \param groupname the name of the new group as QString
* \param groupName the name of the new group as QString
* \param parent is the id of the parent group when a subgrouo is to be created. By default it is 0 indicating it is not a sub-group
* \return returns an int, which is the DB id of the new group created, 0 if the group couldn't be created
*/
@@ -351,9 +351,8 @@ bool QgsStyleV2ManagerDialog::addSymbol()
}

// add new symbol to style and re-populate the list
mStyle->addSymbol( name, symbol );
mStyle->addSymbol( name, symbol, true );
// TODO groups and tags
mStyle->saveSymbol( name, symbol, 0, QStringList() );
mModified = true;
return true;
}
@@ -435,7 +434,8 @@ QString QgsStyleV2ManagerDialog::addColorRampStatic( QWidget* parent, QgsStyleV2
}

// add new symbol to style and re-populate the list
style->addColorRamp( name, ramp );
style->addColorRamp( name, ramp, true );
// TODO groups and tags
return name;
}

@@ -113,24 +113,24 @@ void TestStyleV2::testCreateColorRamps()
QgsVectorGradientColorRampV2::StopsMap stops;
stops[ 0.5 ] = QColor( Qt::white );
gradientRamp->setStops( stops );
QVERIFY( mStyle->addColorRamp( "test_gradient", gradientRamp ) );
QVERIFY( mStyle->addColorRamp( "test_gradient", gradientRamp, true ) );

// random ramp
QgsVectorRandomColorRampV2* randomRamp = new QgsVectorRandomColorRampV2();
QVERIFY( mStyle->addColorRamp( "test_random", randomRamp ) );
QVERIFY( mStyle->addColorRamp( "test_random", randomRamp, true ) );

// color brewer ramp
QgsVectorColorBrewerColorRampV2* cb1Ramp = new QgsVectorColorBrewerColorRampV2();
QVERIFY( mStyle->addColorRamp( "test_cb1", cb1Ramp ) );
QVERIFY( mStyle->addColorRamp( "test_cb1", cb1Ramp, true ) );
QgsVectorColorBrewerColorRampV2* cb2Ramp = new QgsVectorColorBrewerColorRampV2( "RdYlGn", 6 );
QVERIFY( mStyle->addColorRamp( "test_cb2", cb2Ramp ) );
QVERIFY( mStyle->addColorRamp( "test_cb2", cb2Ramp, true ) );

// if ( QgsCptCityColorRampV2::hasBasicSchemes() )
// {
QgsCptCityColorRampV2* cc1Ramp = new QgsCptCityColorRampV2( "jjg/misc/temperature", "" );
QVERIFY( mStyle->addColorRamp( "test_cc1", cc1Ramp ) );
QVERIFY( mStyle->addColorRamp( "test_cc1", cc1Ramp, true ) );
QgsCptCityColorRampV2* cc2Ramp = new QgsCptCityColorRampV2( "cb/div/PiYG", "_10" );
QVERIFY( mStyle->addColorRamp( "test_cc2", cc2Ramp ) );
QVERIFY( mStyle->addColorRamp( "test_cc2", cc2Ramp, true ) );
// }
// else
// {
@@ -188,12 +188,12 @@ void TestStyleV2::testLoadColorRamps()

void TestStyleV2::testSaveLoad()
{
QEXPECT_FAIL("", "save() currently disabled in core", Abort);

mStyle->save();
// save not needed anymore, because used update=true in addColorRamp()
// mStyle->save();
mStyle->clear();
mStyle->load( QgsApplication::userStyleV2Path() );

// basic test to see that ramp is present
QStringList colorRamps = mStyle->colorRampNames();
QStringList colorRampsTest = QStringList() << "test_gradient";

@@ -206,6 +206,9 @@ void TestStyleV2::testSaveLoad()
if ( ramp )
delete ramp;
}

// test content again
testLoadColorRamps();
}


0 comments on commit b145998

Please sign in to comment.
You can’t perform that action at this time.