Skip to content

Commit fadaaeb

Browse files
committedJan 22, 2013
Shorten code for xml reading and writing
1 parent f7f0b2d commit fadaaeb

File tree

1 file changed

+8
-52
lines changed

1 file changed

+8
-52
lines changed
 

‎src/core/composer/qgscomposerscalebar.cpp

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ QgsComposerScaleBar::QgsComposerScaleBar( QgsComposition* composition )
3636
: QgsComposerItem( composition )
3737
, mComposerMap( 0 )
3838
, mNumUnitsPerSegment( 0 )
39+
, mFontColor( QColor( 0, 0, 0 ) )
3940
, mStyle( 0 )
4041
, mSegmentMillimeters( 0.0 )
4142
, mAlignment( Left )
4243
, mUnits( MapUnits )
43-
, mFontColor( QColor( 0, 0, 0 ) )
4444
{
4545
applyDefaultSettings();
4646
applyDefaultSize();
@@ -423,26 +423,10 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) cons
423423
composerScaleBarElem.setAttribute( "mapId", mComposerMap->id() );
424424
}
425425

426-
//fill color
427-
QColor brushColor = mBrush.color();
428-
QDomElement brushColorElem = doc.createElement( "brushColor" );
429-
brushColorElem.setAttribute( "red", brushColor.red() );
430-
brushColorElem.setAttribute( "green", brushColor.green() );
431-
brushColorElem.setAttribute( "blue", brushColor.blue() );
432-
composerScaleBarElem.appendChild( brushColorElem );
433-
//stroke color
434-
QColor penColor = mPen.color();
435-
QDomElement penColorElem = doc.createElement( "penColor" );
436-
penColorElem.setAttribute( "red", penColor.red() );
437-
penColorElem.setAttribute( "green", penColor.green() );
438-
penColorElem.setAttribute( "blue", penColor.blue() );
439-
composerScaleBarElem.appendChild( penColorElem );
440-
//font color
441-
QDomElement fontColorElem = doc.createElement( "fontColor" );
442-
fontColorElem.setAttribute( "red", mFontColor.red() );
443-
fontColorElem.setAttribute( "green", mFontColor.green() );
444-
fontColorElem.setAttribute( "blue", mFontColor.blue() );
445-
composerScaleBarElem.appendChild( fontColorElem );
426+
//colors
427+
composerScaleBarElem.setAttribute( "brushColor", mBrush.color().name() );
428+
composerScaleBarElem.setAttribute( "penColor", mPen.color().name() );
429+
composerScaleBarElem.setAttribute( "fontColor", mFontColor.name() );
446430

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

477461
//colors
478462
//fill color
479-
QDomNodeList fillColorList = itemElem.elementsByTagName( "brushColor" );
480-
if ( fillColorList.size() > 0 )
481-
{
482-
QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
483-
int red = fillColorElem.attribute( "red", "0" ).toInt();
484-
int green = fillColorElem.attribute( "green", "0" ).toInt();
485-
int blue = fillColorElem.attribute( "blue", "0" ).toInt();
486-
mBrush.setColor(QColor( red, green, blue ));
487-
}
488-
//pen color
489-
QDomNodeList penColorList = itemElem.elementsByTagName( "penColor" );
490-
if ( penColorList.size() > 0 )
491-
{
492-
QDomElement penColorElem = penColorList.at( 0 ).toElement();
493-
int red = penColorElem.attribute( "red", "0" ).toInt();
494-
int green = penColorElem.attribute( "green", "0" ).toInt();
495-
int blue = penColorElem.attribute( "blue", "0" ).toInt();
496-
mPen.setColor(QColor( red, green, blue ));
497-
}
498-
//font color
499-
QDomNodeList fontColorList = itemElem.elementsByTagName( "fontColor" );
500-
if ( fontColorList.size() > 0 )
501-
{
502-
QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
503-
int red = fontColorElem.attribute( "red", "0" ).toInt();
504-
int green = fontColorElem.attribute( "green", "0" ).toInt();
505-
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
506-
mFontColor = QColor( red, green, blue );
507-
}
508-
509-
463+
mBrush.setColor( QColor( itemElem.attribute( "brushColor", "#000000" ) ) );
464+
mPen.setColor( QColor( itemElem.attribute( "penColor", "#000000" ) ) );
465+
mFontColor.setNamedColor( itemElem.attribute( "fontColor", "#000000" ) );
510466

511467
//style
512468
delete mStyle;

0 commit comments

Comments
 (0)
Please sign in to comment.