Skip to content

Commit

Permalink
QgsScalebar now saves colors in XML
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdalang authored and mhugent committed Jan 22, 2013
1 parent d033124 commit c5b8b69
Showing 1 changed file with 64 additions and 5 deletions.
69 changes: 64 additions & 5 deletions src/core/composer/qgscomposerscalebar.cpp
Expand Up @@ -425,11 +425,24 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) cons

//fill color
QColor brushColor = mBrush.color();
QDomElement colorElem = doc.createElement( "BrushColor" );
colorElem.setAttribute( "red", brushColor.red() );
colorElem.setAttribute( "green", brushColor.green() );
colorElem.setAttribute( "blue", brushColor.blue() );
composerScaleBarElem.appendChild( colorElem );
QDomElement brushColorElem = doc.createElement( "brushColor" );
brushColorElem.setAttribute( "red", brushColor.red() );
brushColorElem.setAttribute( "green", brushColor.green() );
brushColorElem.setAttribute( "blue", brushColor.blue() );
composerScaleBarElem.appendChild( brushColorElem );
//stroke color
QColor penColor = mPen.color();
QDomElement penColorElem = doc.createElement( "penColor" );
penColorElem.setAttribute( "red", penColor.red() );
penColorElem.setAttribute( "green", penColor.green() );
penColorElem.setAttribute( "blue", penColor.blue() );
composerScaleBarElem.appendChild( penColorElem );
//font color
QDomElement fontColorElem = doc.createElement( "fontColor" );
fontColorElem.setAttribute( "red", mFontColor.red() );
fontColorElem.setAttribute( "green", mFontColor.green() );
fontColorElem.setAttribute( "blue", mFontColor.blue() );
composerScaleBarElem.appendChild( fontColorElem );

//alignment
composerScaleBarElem.setAttribute( "alignment", QString::number(( int ) mAlignment ) );
Expand Down Expand Up @@ -461,6 +474,52 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume
mFont.fromString( fontString );
}

//colors
//fill color
QDomNodeList fillColorList = itemElem.elementsByTagName( "brushColor" );
if ( fillColorList.size() > 0 )
{
QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
int red = fillColorElem.attribute( "red", "0" ).toInt();
int green = fillColorElem.attribute( "green", "0" ).toInt();
int blue = fillColorElem.attribute( "blue", "0" ).toInt();
mBrush.setColor(QColor( red, green, blue ));
}
else
{
mBrush.setColor(QColor( 0, 0, 0 ));
}
//pen color
QDomNodeList penColorList = itemElem.elementsByTagName( "penColor" );
if ( penColorList.size() > 0 )
{
QDomElement penColorElem = penColorList.at( 0 ).toElement();
int red = penColorElem.attribute( "red", "0" ).toInt();
int green = penColorElem.attribute( "green", "0" ).toInt();
int blue = penColorElem.attribute( "blue", "0" ).toInt();
mPen.setColor(QColor( red, green, blue ));
}
else
{
mPen.setColor(QColor( 0, 0, 0 ));
}
//font color
QDomNodeList fontColorList = itemElem.elementsByTagName( "fontColor" );
if ( fontColorList.size() > 0 )
{
QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
int red = fontColorElem.attribute( "red", "0" ).toInt();
int green = fontColorElem.attribute( "green", "0" ).toInt();
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
mFontColor = QColor( red, green, blue );
}
else
{
mFontColor = QColor( 0, 0, 0 );
}



//style
delete mStyle;
mStyle = 0;
Expand Down

0 comments on commit c5b8b69

Please sign in to comment.