Skip to content
Permalink
Browse files

bug fix for issue #6229

  • Loading branch information
tecoholic committed Aug 22, 2012
1 parent 4db6857 commit 447c0d1e545b5c956ff43cd64f28592d578d3595
@@ -80,7 +80,7 @@ void QgsStyleV2::clear()
sqlite3_close( mCurrentDB );
}

bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol )
bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol, bool update )
{
if ( !symbol || name.isEmpty() )
return false;
@@ -89,6 +89,9 @@ bool QgsStyleV2::addSymbol( QString name, QgsSymbolV2* symbol )

mSymbols.insert( name, symbol );

if ( update )
updateSymbol( SymbolEntity, name );

return true;
}

@@ -108,7 +111,7 @@ bool QgsStyleV2::saveSymbol( QString name, QgsSymbolV2* symbol, int groupid, QSt
QByteArray xmlArray;
QTextStream stream( &xmlArray );
symEl.save( stream, 4 );
char *query = sqlite3_mprintf( "INSERT INTO symbol VALUES (NULL, '%q', '%q', %d)",
char *query = sqlite3_mprintf( "INSERT INTO symbol VALUES (NULL, '%q', '%q', %d);",
name.toUtf8().constData(), xmlArray.constData(), groupid );

if ( !runEmptyQuery( query ) )
@@ -170,17 +173,19 @@ QStringList QgsStyleV2::symbolNames()
}


bool QgsStyleV2::addColorRamp( QString name, QgsVectorColorRampV2* colorRamp )
bool QgsStyleV2::addColorRamp( QString name, QgsVectorColorRampV2* colorRamp, bool update )
{
if ( !colorRamp || name.isEmpty() )
return false;

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

QgsDebugMsg( "Inserted " + name );
mColorRamps.insert( name, colorRamp );

if ( update )
updateSymbol( ColorrampEntity, name );

return true;
}

@@ -201,7 +206,7 @@ bool QgsStyleV2::saveColorRamp( QString name, QgsVectorColorRampV2* ramp, int gr
QByteArray xmlArray;
QTextStream stream( &xmlArray );
rampEl.save( stream, 4 );
char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d)",
char *query = sqlite3_mprintf( "INSERT INTO colorramp VALUES (NULL, '%q', '%q', %d);",
name.toUtf8().constData(), xmlArray.constData(), groupid );

if ( !runEmptyQuery( query ) )
@@ -1378,3 +1383,64 @@ bool QgsStyleV2::importXML( QString filename )
mFileName = filename;
return true;
}

bool QgsStyleV2::updateSymbol( StyleEntity type, QString name )
{
QDomDocument doc( "dummy" );
QDomElement symEl;
QByteArray xmlArray;
QTextStream stream( &xmlArray );

char *query;

if ( type == SymbolEntity )
{
// check if it is an existing symbol
if ( !symbolNames().contains( name ) )
{
QgsDebugMsg( "Update request recieved for unavailable symbol" );
return false;
}

symEl = QgsSymbolLayerV2Utils::saveSymbol( name, symbol( name ), doc );
if ( symEl.isNull() )
{
QgsDebugMsg( "Couldn't convert symbol to valid XML!" );
return false;
}
symEl.save( stream, 4 );
query = sqlite3_mprintf( "UPDATE symbol SET xml='%q' WHERE name='%q';",
xmlArray.constData(), name.toUtf8().constData() );
}
else if ( type == ColorrampEntity )
{
if ( !colorRampNames().contains( name ) )
{
QgsDebugMsg( "Update requested for unavailable color ramp." );
return false;
}

symEl = QgsSymbolLayerV2Utils::saveColorRamp( name, colorRamp( name ), doc );
if ( symEl.isNull() )
{
QgsDebugMsg( "Couldn't convert color ramp to valid XML!" );
return false;
}
symEl.save( stream, 4 );
query = sqlite3_mprintf( "UPDATE colorramp SET xml='%q' WHERE name='%q';",
xmlArray.constData(), name.toUtf8().constData() );
}
else
{
QgsDebugMsg( "Updating the unsupported StyleEntity" );
return false;
}


if ( !runEmptyQuery( query ) )
{
QgsDebugMsg( "Couldn't insert symbol into the database!" );
return false;
}
return true;
}
@@ -79,7 +79,14 @@ class CORE_EXPORT QgsStyleV2
~QgsStyleV2();

//! add color ramp to style. takes ramp's ownership
bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp );
/*!
* \note Adding a color ramp with the name of existing one replaces it.
* \param name is the name of the color ramp being added or updated
* \param colorRamp is the Vector color ramp
* \param update set to true when the style DB has to be updated, by default it is false
* \return sucess status of the operation
*/
bool addColorRamp( QString name, QgsVectorColorRampV2* colorRamp, bool update = false );

//! adds a new group and returns the group's id
/*!
@@ -98,7 +105,14 @@ class CORE_EXPORT QgsStyleV2
int addSmartgroup( QString name, QString op, QgsSmartConditionMap conditions );

//! add symbol to style. takes symbol's ownership
bool addSymbol( QString name, QgsSymbolV2* symbol );
/*!
* \note Adding a symbol with the name of existing one replaces it.
* \param name is the name of the symbol being added or updated
* \param symbol is the Vector symbol
* \param update set to true when the style DB has to be updated, by default it is false
* \return sucess status of the operation
*/
bool addSymbol( QString name, QgsSymbolV2* symbol, bool update = false );

//! adds a new tag and returns the tag's id
/*!
@@ -107,7 +121,7 @@ class CORE_EXPORT QgsStyleV2
*/
int addTag( QString tagName );

//! return a map of groupid and names for the given parent
//! return a map of groupid and names for the given parent group
QgsSymbolGroupMap childGroupNames( QString parent = "" );

//! remove all contents of the style
@@ -323,6 +337,15 @@ class CORE_EXPORT QgsStyleV2

//! gets the id from the table for the given name from the database, 0 if not found
int getId( QString table, QString name );

//! updates the properties of an existing symbol/colorramp
/*!
* \note This should not be called seperately, only called through addSymbol or addColorRamp
* \param type is either SymbolEntity or ColorrampEntity
* \param name is the name of an existing symbol or a color ramp
* \return Success state of the update operation
*/
bool updateSymbol( StyleEntity type, QString name );
};


@@ -490,7 +490,7 @@ bool QgsStyleV2ManagerDialog::editSymbol()
}

// by adding symbol to style with the same name the old effectively gets overwritten
mStyle->addSymbol( symbolName, symbol );
mStyle->addSymbol( symbolName, symbol, true );
mModified = true;
return true;
}
@@ -548,7 +548,7 @@ bool QgsStyleV2ManagerDialog::editColorRamp()
Q_ASSERT( 0 && "invalid ramp type" );
}

mStyle->addColorRamp( name, ramp );
mStyle->addColorRamp( name, ramp, true );
mModified = true;
return true;
}

0 comments on commit 447c0d1

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