Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Shorten code for xml reading and writing
  • Loading branch information
mhugent committed Jan 22, 2013
1 parent f7f0b2d commit fadaaeb
Showing 1 changed file with 8 additions and 52 deletions.
60 changes: 8 additions & 52 deletions src/core/composer/qgscomposerscalebar.cpp
Expand Up @@ -36,11 +36,11 @@ QgsComposerScaleBar::QgsComposerScaleBar( QgsComposition* composition )
: QgsComposerItem( composition )
, mComposerMap( 0 )
, mNumUnitsPerSegment( 0 )
, mFontColor( QColor( 0, 0, 0 ) )
, mStyle( 0 )
, mSegmentMillimeters( 0.0 )
, mAlignment( Left )
, mUnits( MapUnits )
, mFontColor( QColor( 0, 0, 0 ) )
{
applyDefaultSettings();
applyDefaultSize();
Expand Down Expand Up @@ -423,26 +423,10 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) cons
composerScaleBarElem.setAttribute( "mapId", mComposerMap->id() );
}

//fill color
QColor brushColor = mBrush.color();
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 );
//colors
composerScaleBarElem.setAttribute( "brushColor", mBrush.color().name() );
composerScaleBarElem.setAttribute( "penColor", mPen.color().name() );
composerScaleBarElem.setAttribute( "fontColor", mFontColor.name() );

//alignment
composerScaleBarElem.setAttribute( "alignment", QString::number(( int ) mAlignment ) );
Expand Down Expand Up @@ -476,37 +460,9 @@ bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocume

//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 ));
}
//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 ));
}
//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 );
}


mBrush.setColor( QColor( itemElem.attribute( "brushColor", "#000000" ) ) );
mPen.setColor( QColor( itemElem.attribute( "penColor", "#000000" ) ) );
mFontColor.setNamedColor( itemElem.attribute( "fontColor", "#000000" ) );

//style
delete mStyle;
Expand Down

0 comments on commit fadaaeb

Please sign in to comment.