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 );
187 return composerMapRect.
width();
232 mPen = QPen( QColor( 0, 0, 0 ) );
233 mPen.setWidthF( 1.0 );
235 mBrush.setColor( QColor( 0, 0, 0 ) );
236 mBrush.setStyle( Qt::SolidPattern );
238 mFont.setPointSizeF( 12.0 );
252 int nUnitsPerSegment = widthMeter / 10.0;
255 if ( nUnitsPerSegment > 1000 )
293 QgsComposerItem::update();
312 posWidthList.clear();
318 posWidthList.push_back( qMakePair( mCurrentXCoord,
mSegmentMillimeters / mNumSegmentsLeft ) );
336 if ( styleName ==
"Single Box" )
340 else if ( styleName ==
"Double Box" )
344 else if ( styleName ==
"Line Ticks Middle" || styleName ==
"Line Ticks Down" || styleName ==
"Line Ticks Up" )
347 if ( styleName ==
"Line Ticks Middle" )
351 else if ( styleName ==
"Line Ticks Down" )
355 else if ( styleName ==
"Line Ticks Up" )
361 else if ( styleName ==
"Numeric" )
411 QDomElement composerScaleBarElem = doc.createElement(
"ComposerScaleBar" );
412 composerScaleBarElem.setAttribute(
"height", QString::number(
mHeight ) );
413 composerScaleBarElem.setAttribute(
"labelBarSpace", QString::number(
mLabelBarSpace ) );
414 composerScaleBarElem.setAttribute(
"boxContentSpace", QString::number(
mBoxContentSpace ) );
415 composerScaleBarElem.setAttribute(
"numSegments",
mNumSegments );
417 composerScaleBarElem.setAttribute(
"numUnitsPerSegment", QString::number(
mNumUnitsPerSegment ) );
418 composerScaleBarElem.setAttribute(
"segmentMillimeters", QString::number(
mSegmentMillimeters ) );
420 composerScaleBarElem.setAttribute(
"font",
mFont.toString() );
421 composerScaleBarElem.setAttribute(
"outlineWidth", QString::number(
mPen.widthF() ) );
422 composerScaleBarElem.setAttribute(
"unitLabel",
mUnitLabeling );
423 composerScaleBarElem.setAttribute(
"units",
mUnits );
428 composerScaleBarElem.setAttribute(
"style",
mStyle->
name() );
438 composerScaleBarElem.setAttribute(
"brushColor",
mBrush.color().name() );
439 composerScaleBarElem.setAttribute(
"penColor",
mPen.color().name() );
440 composerScaleBarElem.setAttribute(
"fontColor",
mFontColor.name() );
443 composerScaleBarElem.setAttribute(
"alignment", QString::number((
int )
mAlignment ) );
445 elem.appendChild( composerScaleBarElem );
446 return _writeXML( composerScaleBarElem, doc );
451 if ( itemElem.isNull() )
456 mHeight = itemElem.attribute(
"height",
"5.0" ).toDouble();
457 mLabelBarSpace = itemElem.attribute(
"labelBarSpace",
"3.0" ).toDouble();
458 mBoxContentSpace = itemElem.attribute(
"boxContentSpace",
"1.0" ).toDouble();
459 mNumSegments = itemElem.attribute(
"numSegments",
"2" ).toInt();
464 mPen.setWidthF( itemElem.attribute(
"outlineWidth",
"1.0" ).toDouble() );
466 QString fontString = itemElem.attribute(
"font",
"" );
467 if ( !fontString.isEmpty() )
469 mFont.fromString( fontString );
474 mBrush.setColor( QColor( itemElem.attribute(
"brushColor",
"#000000" ) ) );
475 mPen.setColor( QColor( itemElem.attribute(
"penColor",
"#000000" ) ) );
476 mFontColor.setNamedColor( itemElem.attribute(
"fontColor",
"#000000" ) );
481 QString styleString = itemElem.attribute(
"style",
"" );
482 setStyle(
tr( styleString.toLocal8Bit().data() ) );
488 int mapId = itemElem.attribute(
"mapId",
"-1" ).toInt();
503 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
504 if ( composerItemList.size() > 0 )
506 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
523 move( -( widthAfter - width ) / 2.0, 0 );
527 move( -( widthAfter - width ), 0 );
Double box with alternating colors.
A rectangle specified with double values.
ScaleBarUnits
Added in version 1.9.
double mLabelBarSpace
Space between bar and Text labels.
double mHeight
Height of bars/lines.
double mNumUnitsPerSegment
Size of a segment (in map units)
bool writeXML(QDomElement &elem, QDomDocument &doc) const
stores state in Dom element
void setUnits(ScaleBarUnits u)
double mNumMapUnitsPerScaleBarUnit
Number of map units per scale bar units (e.g.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void setFont(const QFont &font)
A scale bar style that draws text in the form of '1:XXXXX'.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
void setUnitLabeling(const QString &label)
void setAlignment(Alignment a)
void applyDefaultSettings()
Apply default settings.
A item that forms part of a map composition.
void setNumSegments(int nSegments)
void segmentPositions(QList< QPair< double, double > > &posWidthList) const
Returns the x - positions of the segment borders (in item coordinates) and the width of the segment...
virtual QRectF calculateBoxSize() const
void setNumSegmentsLeft(int nSegmentsLeft)
ScaleBarUnits units() const
virtual void drawFrame(QPainter *p)
Draw black frame around item.
QgsScaleBarStyle * mStyle
Scalebar style.
virtual QString name() const =0
bool setEllipsoid(const QString &ellipsoid)
sets ellipsoid by its acronym
void update()
Adjusts box size and calls QgsComposerItem::update()
A scale bar that draws segments using short ticks.
void setNumMapUnitsPerScaleBarUnit(double d)
void adjustBoxSize()
Sets box size suitable to content.
void itemChanged()
Used e.g.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
double mSegmentMillimeters
Width of a segment (in mm)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
void setStyle(const QString &styleName)
Sets style by name.
virtual void draw(QPainter *p, double xOffset=0) const =0
Draws the style.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
const QgsMapRenderer * mapRenderer() const
QgsComposerScaleBar(QgsComposition *composition)
Alignment
Added in version 1.8.
int mNumSegmentsLeft
Number of segments on left side.
QgsComposition * mComposition
A class to represent a point geometry.
const QgsComposerMap * composerMap() const
Graphics scene for map printing.
Object representing map window.
QString style() const
Returns style name.
void setComposerMap(const QgsComposerMap *map)
void refreshSegmentMillimeters()
Calculates with of a segment in mm and stores it in mSegmentMillimeters.
void invalidateCurrentMap()
Sets mCompositionMap to 0 if the map is deleted.
void setBoxContentSpace(double space)
int id() const
Get identification number.
General purpose distance and area calculator.
int mNumSegments
Number of segments on right side.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
QgsRectangle extent() const
double numUnitsPerSegment() const
virtual void drawBackground(QPainter *p)
Draw background.
static QgsProject * instance()
access to canonical QgsProject instance
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
double measureLine(const QList< QgsPoint > &points)
measures line
double mBoxContentSpace
Space between content and item box.
void applyDefaultSize()
Apply default size (scale bar 1/5 of map item width)
QString mUnitLabeling
Labeling of map units.
double mapWidth() const
Returns diagonal of composer map in selected units (map units / meters / feet)
const QgsComposerMap * mComposerMap
Reference to composer map object.
void setNumUnitsPerSegment(double units)
double width() const
Width of the rectangle.
const QgsComposerMap * getComposerMapById(int id) const
Returns the composer map with specified id.
void move(double dx, double dy)
Moves item in canvas coordinates.
Scalebar style that draws a single box with alternating color for the segments.
void correctXPositionAlignment(double width, double widthAfter)
Moves scalebar position to the left / right depending on alignment and change in item width...
double xMinimum() const
Get the x minimum value (left side of rectangle)
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
void setTickPosition(TickPosition p)
QString firstLabelString() const
Returns string of first label (important for drawing, labeling, size calculation. ...