29 #include <QDomDocument>
30 #include <QDomElement>
31 #include <QFontMetricsF>
39 , mNumUnitsPerSegment( 0 )
40 , mFontColor( QColor( 0, 0, 0 ) )
42 , mSegmentMillimeters( 0.0 )
57 Q_UNUSED( itemStyle );
195 return composerMapRect.
width();
244 mPen = QPen( QColor( 0, 0, 0 ) );
245 mPen.setJoinStyle( Qt::MiterJoin );
246 mPen.setWidthF( 1.0 );
248 mBrush.setColor( QColor( 0, 0, 0 ) );
249 mBrush.setStyle( Qt::SolidPattern );
253 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
254 if ( !defaultFontString.isEmpty() )
256 mFont.setFamily( defaultFontString );
258 mFont.setPointSizeF( 12.0 );
271 double upperMagnitudeMultiplier = 1.0;
272 double widthInSelectedUnits =
mapWidth();
273 double initialUnitsPerSegment = widthInSelectedUnits / 10.0;
280 upperMagnitudeMultiplier = 1.0;
286 if ( initialUnitsPerSegment > 1000.0 )
288 upperMagnitudeMultiplier = 1000.0;
293 upperMagnitudeMultiplier = 1.0;
300 if ( initialUnitsPerSegment > 5419.95 )
302 upperMagnitudeMultiplier = 5419.95;
307 upperMagnitudeMultiplier = 1.0;
314 upperMagnitudeMultiplier = 1;
320 double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
321 int segmentMagnitude = floor( log10( segmentWidth ) );
322 double unitsPerSegment = upperMagnitudeMultiplier * ( pow( 10.0, segmentMagnitude ) );
323 double multiplier = floor(( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
325 if ( multiplier > 0 )
327 unitsPerSegment = unitsPerSegment * multiplier;
378 posWidthList.clear();
384 posWidthList.push_back( qMakePair( mCurrentXCoord,
mSegmentMillimeters / mNumSegmentsLeft ) );
402 if ( styleName ==
"Single Box" )
406 else if ( styleName ==
"Double Box" )
410 else if ( styleName ==
"Line Ticks Middle" || styleName ==
"Line Ticks Down" || styleName ==
"Line Ticks Up" )
413 if ( styleName ==
"Line Ticks Middle" )
417 else if ( styleName ==
"Line Ticks Down" )
421 else if ( styleName ==
"Line Ticks Up" )
427 else if ( styleName ==
"Numeric" )
477 QDomElement composerScaleBarElem = doc.createElement(
"ComposerScaleBar" );
478 composerScaleBarElem.setAttribute(
"height", QString::number(
mHeight ) );
479 composerScaleBarElem.setAttribute(
"labelBarSpace", QString::number(
mLabelBarSpace ) );
480 composerScaleBarElem.setAttribute(
"boxContentSpace", QString::number(
mBoxContentSpace ) );
481 composerScaleBarElem.setAttribute(
"numSegments",
mNumSegments );
483 composerScaleBarElem.setAttribute(
"numUnitsPerSegment", QString::number(
mNumUnitsPerSegment ) );
484 composerScaleBarElem.setAttribute(
"segmentMillimeters", QString::number(
mSegmentMillimeters ) );
486 composerScaleBarElem.setAttribute(
"font",
mFont.toString() );
487 composerScaleBarElem.setAttribute(
"outlineWidth", QString::number(
mPen.widthF() ) );
488 composerScaleBarElem.setAttribute(
"unitLabel",
mUnitLabeling );
489 composerScaleBarElem.setAttribute(
"units",
mUnits );
494 composerScaleBarElem.setAttribute(
"style",
mStyle->
name() );
504 composerScaleBarElem.setAttribute(
"brushColor",
mBrush.color().name() );
505 composerScaleBarElem.setAttribute(
"penColor",
mPen.color().name() );
506 composerScaleBarElem.setAttribute(
"fontColor",
mFontColor.name() );
509 composerScaleBarElem.setAttribute(
"alignment", QString::number((
int )
mAlignment ) );
511 elem.appendChild( composerScaleBarElem );
512 return _writeXML( composerScaleBarElem, doc );
517 if ( itemElem.isNull() )
522 mHeight = itemElem.attribute(
"height",
"5.0" ).toDouble();
523 mLabelBarSpace = itemElem.attribute(
"labelBarSpace",
"3.0" ).toDouble();
524 mBoxContentSpace = itemElem.attribute(
"boxContentSpace",
"1.0" ).toDouble();
525 mNumSegments = itemElem.attribute(
"numSegments",
"2" ).toInt();
530 mPen.setWidthF( itemElem.attribute(
"outlineWidth",
"1.0" ).toDouble() );
532 QString fontString = itemElem.attribute(
"font",
"" );
533 if ( !fontString.isEmpty() )
535 mFont.fromString( fontString );
540 mBrush.setColor( QColor( itemElem.attribute(
"brushColor",
"#000000" ) ) );
541 mPen.setColor( QColor( itemElem.attribute(
"penColor",
"#000000" ) ) );
542 mFontColor.setNamedColor( itemElem.attribute(
"fontColor",
"#000000" ) );
547 QString styleString = itemElem.attribute(
"style",
"" );
548 setStyle(
tr( styleString.toLocal8Bit().data() ) );
554 int mapId = itemElem.attribute(
"mapId",
"-1" ).toInt();
569 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
570 if ( composerItemList.size() > 0 )
572 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
589 move( -( widthAfter - width ) / 2.0, 0 );
593 move( -( widthAfter - width ), 0 );