Skip to content

Commit c5b8b69

Browse files
olivierdalangmhugent
authored andcommitted
QgsScalebar now saves colors in XML
1 parent d033124 commit c5b8b69

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

src/core/composer/qgscomposerscalebar.cpp

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,24 @@ bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) cons
425425

426426
//fill color
427427
QColor brushColor = mBrush.color();
428-
QDomElement colorElem = doc.createElement( "BrushColor" );
429-
colorElem.setAttribute( "red", brushColor.red() );
430-
colorElem.setAttribute( "green", brushColor.green() );
431-
colorElem.setAttribute( "blue", brushColor.blue() );
432-
composerScaleBarElem.appendChild( colorElem );
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 );
433446

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

477+
//colors
478+
//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+
else
489+
{
490+
mBrush.setColor(QColor( 0, 0, 0 ));
491+
}
492+
//pen color
493+
QDomNodeList penColorList = itemElem.elementsByTagName( "penColor" );
494+
if ( penColorList.size() > 0 )
495+
{
496+
QDomElement penColorElem = penColorList.at( 0 ).toElement();
497+
int red = penColorElem.attribute( "red", "0" ).toInt();
498+
int green = penColorElem.attribute( "green", "0" ).toInt();
499+
int blue = penColorElem.attribute( "blue", "0" ).toInt();
500+
mPen.setColor(QColor( red, green, blue ));
501+
}
502+
else
503+
{
504+
mPen.setColor(QColor( 0, 0, 0 ));
505+
}
506+
//font color
507+
QDomNodeList fontColorList = itemElem.elementsByTagName( "fontColor" );
508+
if ( fontColorList.size() > 0 )
509+
{
510+
QDomElement fontColorElem = fontColorList.at( 0 ).toElement();
511+
int red = fontColorElem.attribute( "red", "0" ).toInt();
512+
int green = fontColorElem.attribute( "green", "0" ).toInt();
513+
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
514+
mFontColor = QColor( red, green, blue );
515+
}
516+
else
517+
{
518+
mFontColor = QColor( 0, 0, 0 );
519+
}
520+
521+
522+
464523
//style
465524
delete mStyle;
466525
mStyle = 0;

0 commit comments

Comments
 (0)