31 #include <QDomDocument>
32 #include <QDomElement>
33 #include <QFontMetricsF>
41 , mNumUnitsPerSegment( 0 )
42 , mFontColor( QColor( 0, 0, 0 ) )
44 , mSegmentMillimeters( 0.0 )
47 , mLineJoinStyle( Qt::MiterJoin )
48 , mLineCapStyle( Qt::SquareCap )
61 Q_UNUSED( itemStyle );
203 return composerMapRect.
width();
281 mPen = QPen( Qt::black );
284 mPen.setWidthF( 1.0 );
286 mBrush.setColor( Qt::black );
287 mBrush.setStyle( Qt::SolidPattern );
290 mBrush2.setStyle( Qt::SolidPattern );
294 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
295 if ( !defaultFontString.isEmpty() )
297 mFont.setFamily( defaultFontString );
299 mFont.setPointSizeF( 12.0 );
312 double upperMagnitudeMultiplier = 1.0;
313 double widthInSelectedUnits =
mapWidth();
314 double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
321 upperMagnitudeMultiplier = 1.0;
327 if ( initialUnitsPerSegment > 1000.0 )
329 upperMagnitudeMultiplier = 1000.0;
334 upperMagnitudeMultiplier = 1.0;
341 if ( initialUnitsPerSegment > 5419.95 )
343 upperMagnitudeMultiplier = 5419.95;
348 upperMagnitudeMultiplier = 1.0;
355 upperMagnitudeMultiplier = 1;
361 double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
362 int segmentMagnitude = floor( log10( segmentWidth ) );
363 double unitsPerSegment = upperMagnitudeMultiplier * ( pow( 10.0, segmentMagnitude ) );
364 double multiplier = floor(( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
366 if ( multiplier > 0 )
368 unitsPerSegment = unitsPerSegment * multiplier;
390 if ( rect().
height() > box.height() )
393 box.setHeight( rect().
height() );
400 if ( newRect.width() < box.width() )
402 newRect.setWidth( box.width() );
404 if ( newRect.height() < box.height() )
406 newRect.setHeight( box.height() );
415 if ( rectangle.height() > box.height() )
418 box.setHeight( rectangle.height() );
420 box.moveTopLeft( rectangle.topLeft() );
426 if ( newRect.width() < box.width() )
428 newRect.setWidth( box.width() );
430 if ( newRect.height() < box.height() )
432 newRect.setHeight( box.height() );
464 posWidthList.clear();
471 posWidthList.push_back( qMakePair( mCurrentXCoord, leftSegmentSize ) );
472 mCurrentXCoord += leftSegmentSize;
489 if ( styleName ==
"Single Box" )
493 else if ( styleName ==
"Double Box" )
497 else if ( styleName ==
"Line Ticks Middle" || styleName ==
"Line Ticks Down" || styleName ==
"Line Ticks Up" )
500 if ( styleName ==
"Line Ticks Middle" )
504 else if ( styleName ==
"Line Ticks Down" )
508 else if ( styleName ==
"Line Ticks Up" )
514 else if ( styleName ==
"Numeric" )
564 QDomElement composerScaleBarElem = doc.createElement(
"ComposerScaleBar" );
565 composerScaleBarElem.setAttribute(
"height", QString::number(
mHeight ) );
566 composerScaleBarElem.setAttribute(
"labelBarSpace", QString::number(
mLabelBarSpace ) );
567 composerScaleBarElem.setAttribute(
"boxContentSpace", QString::number(
mBoxContentSpace ) );
568 composerScaleBarElem.setAttribute(
"numSegments",
mNumSegments );
570 composerScaleBarElem.setAttribute(
"numUnitsPerSegment", QString::number(
mNumUnitsPerSegment ) );
571 composerScaleBarElem.setAttribute(
"segmentMillimeters", QString::number(
mSegmentMillimeters ) );
573 composerScaleBarElem.setAttribute(
"font",
mFont.toString() );
574 composerScaleBarElem.setAttribute(
"outlineWidth", QString::number(
mPen.widthF() ) );
575 composerScaleBarElem.setAttribute(
"unitLabel",
mUnitLabeling );
576 composerScaleBarElem.setAttribute(
"units",
mUnits );
583 composerScaleBarElem.setAttribute(
"style",
mStyle->
name() );
595 QDomElement fillColorElem = doc.createElement(
"fillColor" );
596 QColor fillColor =
mBrush.color();
597 fillColorElem.setAttribute(
"red", QString::number( fillColor.red() ) );
598 fillColorElem.setAttribute(
"green", QString::number( fillColor.green() ) );
599 fillColorElem.setAttribute(
"blue", QString::number( fillColor.blue() ) );
600 fillColorElem.setAttribute(
"alpha", QString::number( fillColor.alpha() ) );
601 composerScaleBarElem.appendChild( fillColorElem );
604 QDomElement fillColor2Elem = doc.createElement(
"fillColor2" );
605 QColor fillColor2 =
mBrush2.color();
606 fillColor2Elem.setAttribute(
"red", QString::number( fillColor2.red() ) );
607 fillColor2Elem.setAttribute(
"green", QString::number( fillColor2.green() ) );
608 fillColor2Elem.setAttribute(
"blue", QString::number( fillColor2.blue() ) );
609 fillColor2Elem.setAttribute(
"alpha", QString::number( fillColor2.alpha() ) );
610 composerScaleBarElem.appendChild( fillColor2Elem );
613 QDomElement strokeColorElem = doc.createElement(
"strokeColor" );
614 QColor strokeColor =
mPen.color();
615 strokeColorElem.setAttribute(
"red", QString::number( strokeColor.red() ) );
616 strokeColorElem.setAttribute(
"green", QString::number( strokeColor.green() ) );
617 strokeColorElem.setAttribute(
"blue", QString::number( strokeColor.blue() ) );
618 strokeColorElem.setAttribute(
"alpha", QString::number( strokeColor.alpha() ) );
619 composerScaleBarElem.appendChild( strokeColorElem );
622 QDomElement fontColorElem = doc.createElement(
"textColor" );
623 fontColorElem.setAttribute(
"red", QString::number(
mFontColor.red() ) );
624 fontColorElem.setAttribute(
"green", QString::number(
mFontColor.green() ) );
625 fontColorElem.setAttribute(
"blue", QString::number(
mFontColor.blue() ) );
626 fontColorElem.setAttribute(
"alpha", QString::number(
mFontColor.alpha() ) );
627 composerScaleBarElem.appendChild( fontColorElem );
630 composerScaleBarElem.setAttribute(
"alignment", QString::number((
int )
mAlignment ) );
632 elem.appendChild( composerScaleBarElem );
633 return _writeXML( composerScaleBarElem, doc );
638 if ( itemElem.isNull() )
643 mHeight = itemElem.attribute(
"height",
"5.0" ).toDouble();
644 mLabelBarSpace = itemElem.attribute(
"labelBarSpace",
"3.0" ).toDouble();
645 mBoxContentSpace = itemElem.attribute(
"boxContentSpace",
"1.0" ).toDouble();
646 mNumSegments = itemElem.attribute(
"numSegments",
"2" ).toInt();
651 mPen.setWidthF( itemElem.attribute(
"outlineWidth",
"1.0" ).toDouble() );
657 QString fontString = itemElem.attribute(
"font",
"" );
658 if ( !fontString.isEmpty() )
660 mFont.fromString( fontString );
665 QDomNodeList fillColorList = itemElem.elementsByTagName(
"fillColor" );
666 if ( fillColorList.size() > 0 )
668 QDomElement fillColorElem = fillColorList.at( 0 ).toElement();
669 bool redOk, greenOk, blueOk, alphaOk;
670 int fillRed, fillGreen, fillBlue, fillAlpha;
672 fillRed = fillColorElem.attribute(
"red" ).toDouble( &redOk );
673 fillGreen = fillColorElem.attribute(
"green" ).toDouble( &greenOk );
674 fillBlue = fillColorElem.attribute(
"blue" ).toDouble( &blueOk );
675 fillAlpha = fillColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
677 if ( redOk && greenOk && blueOk && alphaOk )
679 mBrush.setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
684 mBrush.setColor( QColor( itemElem.attribute(
"brushColor",
"#000000" ) ) );
688 QDomNodeList fillColor2List = itemElem.elementsByTagName(
"fillColor2" );
689 if ( fillColor2List.size() > 0 )
691 QDomElement fillColor2Elem = fillColor2List.at( 0 ).toElement();
692 bool redOk, greenOk, blueOk, alphaOk;
693 int fillRed, fillGreen, fillBlue, fillAlpha;
695 fillRed = fillColor2Elem.attribute(
"red" ).toDouble( &redOk );
696 fillGreen = fillColor2Elem.attribute(
"green" ).toDouble( &greenOk );
697 fillBlue = fillColor2Elem.attribute(
"blue" ).toDouble( &blueOk );
698 fillAlpha = fillColor2Elem.attribute(
"alpha" ).toDouble( &alphaOk );
700 if ( redOk && greenOk && blueOk && alphaOk )
702 mBrush2.setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) );
707 mBrush2.setColor( QColor( itemElem.attribute(
"brush2Color",
"#ffffff" ) ) );
711 QDomNodeList strokeColorList = itemElem.elementsByTagName(
"strokeColor" );
712 if ( strokeColorList.size() > 0 )
714 QDomElement strokeColorElem = strokeColorList.at( 0 ).toElement();
715 bool redOk, greenOk, blueOk, alphaOk;
716 int strokeRed, strokeGreen, strokeBlue, strokeAlpha;
718 strokeRed = strokeColorElem.attribute(
"red" ).toDouble( &redOk );
719 strokeGreen = strokeColorElem.attribute(
"green" ).toDouble( &greenOk );
720 strokeBlue = strokeColorElem.attribute(
"blue" ).toDouble( &blueOk );
721 strokeAlpha = strokeColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
723 if ( redOk && greenOk && blueOk && alphaOk )
725 mPen.setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) );
730 mPen.setColor( QColor( itemElem.attribute(
"penColor",
"#000000" ) ) );
734 QDomNodeList textColorList = itemElem.elementsByTagName(
"textColor" );
735 if ( textColorList.size() > 0 )
737 QDomElement textColorElem = textColorList.at( 0 ).toElement();
738 bool redOk, greenOk, blueOk, alphaOk;
739 int textRed, textGreen, textBlue, textAlpha;
741 textRed = textColorElem.attribute(
"red" ).toDouble( &redOk );
742 textGreen = textColorElem.attribute(
"green" ).toDouble( &greenOk );
743 textBlue = textColorElem.attribute(
"blue" ).toDouble( &blueOk );
744 textAlpha = textColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
746 if ( redOk && greenOk && blueOk && alphaOk )
748 mFontColor = QColor( textRed, textGreen, textBlue, textAlpha );
753 mFontColor.setNamedColor( itemElem.attribute(
"fontColor",
"#000000" ) );
759 QString styleString = itemElem.attribute(
"style",
"" );
760 setStyle(
tr( styleString.toLocal8Bit().data() ) );
766 int mapId = itemElem.attribute(
"mapId",
"-1" ).toInt();
781 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
782 if ( composerItemList.size() > 0 )
784 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
801 move( -( widthAfter - width ) / 2.0, 0 );
805 move( -( widthAfter - width ), 0 );