QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerscalebar.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerscalebar.cpp
3  -------------------
4  begin : March 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : blazek@itc.it
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "qgscomposerscalebar.h"
18 #include "qgscomposermap.h"
19 #include "qgscomposition.h"
20 #include "qgsdistancearea.h"
21 #include "qgsscalebarstyle.h"
23 #include "qgsmaprenderer.h"
26 #include "qgsticksscalebarstyle.h"
27 #include "qgsrectangle.h"
28 #include "qgsproject.h"
29 #include "qgssymbollayerv2utils.h"
30 #include <QDomDocument>
31 #include <QDomElement>
32 #include <QFontMetricsF>
33 #include <QPainter>
34 #include <QSettings>
35 #include <cmath>
36 
38  : QgsComposerItem( composition )
39  , mComposerMap( 0 )
40  , mNumUnitsPerSegment( 0 )
41  , mFontColor( QColor( 0, 0, 0 ) )
42  , mStyle( 0 )
43  , mSegmentMillimeters( 0.0 )
44  , mAlignment( Left )
45  , mUnits( MapUnits )
46  , mLineJoinStyle( Qt::MiterJoin )
47  , mLineCapStyle( Qt::SquareCap )
48 {
51 }
52 
54 {
55  delete mStyle;
56 }
57 
58 void QgsComposerScaleBar::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
59 {
60  Q_UNUSED( itemStyle );
61  Q_UNUSED( pWidget );
62  if ( !mStyle || !painter )
63  {
64  return;
65  }
66 
67  drawBackground( painter );
68 
69  //x-offset is half of first label width because labels are drawn centered
70  QString firstLabel = firstLabelString();
71  double firstLabelWidth = textWidthMillimeters( mFont, firstLabel );
72 
73  mStyle->draw( painter, firstLabelWidth / 2 );
74 
75  //draw frame and selection boxes if necessary
76  drawFrame( painter );
77  if ( isSelected() )
78  {
79  drawSelectionBoxes( painter );
80  }
81 }
82 
84 {
85  if ( !mStyle )
86  {
87  mNumSegments = nSegments;
88  return;
89  }
90  double width = mStyle->calculateBoxSize().width();
91  mNumSegments = nSegments;
92  double widthAfter = mStyle->calculateBoxSize().width();
93  correctXPositionAlignment( width, widthAfter );
94  emit itemChanged();
95 }
96 
98 {
99  if ( !mStyle )
100  {
102  return;
103  }
104  double width = mStyle->calculateBoxSize().width();
107  double widthAfter = mStyle->calculateBoxSize().width();
108  correctXPositionAlignment( width, widthAfter );
109  emit itemChanged();
110 }
111 
113 {
114  if ( !mStyle )
115  {
116  mNumSegmentsLeft = nSegmentsLeft;
117  return;
118  }
119  double width = mStyle->calculateBoxSize().width();
120  mNumSegmentsLeft = nSegmentsLeft;
121  double widthAfter = mStyle->calculateBoxSize().width();
122  correctXPositionAlignment( width, widthAfter );
123  emit itemChanged();
124 }
125 
127 {
128  if ( !mStyle )
129  {
130  mBoxContentSpace = space;
131  return;
132  }
133  double width = mStyle->calculateBoxSize().width();
134  mBoxContentSpace = space;
135  double widthAfter = mStyle->calculateBoxSize().width();
136  correctXPositionAlignment( width, widthAfter );
137  emit itemChanged();
138 }
139 
141 {
142  if ( mComposerMap )
143  {
144  disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( updateSegmentSize() ) );
145  disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
146  }
147  mComposerMap = map;
148 
149  if ( !map )
150  {
151  return;
152  }
153 
154  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( updateSegmentSize() ) );
155  connect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
156 
158  emit itemChanged();
159 }
160 
162 {
163  if ( !mComposerMap )
164  {
165  return;
166  }
167 
168  disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( updateSegmentSize() ) );
169  disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
170  mComposerMap = 0;
171 }
172 
174 {
175  if ( mComposerMap )
176  {
177  //get extent of composer map
178  QgsRectangle composerMapRect = *( mComposerMap->currentMapExtent() );
179 
180  //get mm dimension of composer map
181  QRectF composerItemRect = mComposerMap->rect();
182 
183  //calculate size depending on mNumUnitsPerSegment
184  mSegmentMillimeters = composerItemRect.width() / mapWidth() * mNumUnitsPerSegment;
185  }
186 }
187 
189 {
190  if ( !mComposerMap )
191  {
192  return 0.0;
193  }
194 
195  QgsRectangle composerMapRect = *( mComposerMap->currentMapExtent() );
196  if ( mUnits == MapUnits )
197  {
198  return composerMapRect.width();
199  }
200  else
201  {
202  QgsDistanceArea da;
205  da.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", "WGS84" ) );
206 
207  double measure = da.measureLine( QgsPoint( composerMapRect.xMinimum(), composerMapRect.yMinimum() ), QgsPoint( composerMapRect.xMaximum(), composerMapRect.yMinimum() ) );
209  {
211  }
213  {
215  }
216  return measure;
217  }
218 }
219 
221 {
222  mAlignment = a;
223  update();
224  emit itemChanged();
225 }
226 
228 {
229  mUnits = u;
231  emit itemChanged();
232 }
233 
234 void QgsComposerScaleBar::setLineJoinStyle( Qt::PenJoinStyle style )
235 {
236  if ( mLineJoinStyle == style )
237  {
238  //no change
239  return;
240  }
242  mPen.setJoinStyle( mLineJoinStyle );
243  update();
244  emit itemChanged();
245 }
246 
247 void QgsComposerScaleBar::setLineCapStyle( Qt::PenCapStyle style )
248 {
249  if ( mLineCapStyle == style )
250  {
251  //no change
252  return;
253  }
255  mPen.setCapStyle( mLineCapStyle );
256  update();
257  emit itemChanged();
258 }
259 
261 {
262  mNumSegments = 2;
263  mNumSegmentsLeft = 0;
264 
266 
267  //style
268  delete mStyle;
269  mStyle = new QgsSingleBoxScaleBarStyle( this );
270 
271  mHeight = 3;
272 
273  mPen = QPen( QColor( 0, 0, 0 ) );
274  mPen.setJoinStyle( mLineJoinStyle );
275  mPen.setCapStyle( mLineCapStyle );
276  mPen.setWidthF( 1.0 );
277 
278  mBrush.setColor( QColor( 0, 0, 0 ) );
279  mBrush.setStyle( Qt::SolidPattern );
280 
281  //get default composer font from settings
282  QSettings settings;
283  QString defaultFontString = settings.value( "/Composer/defaultFont" ).toString();
284  if ( !defaultFontString.isEmpty() )
285  {
286  mFont.setFamily( defaultFontString );
287  }
288  mFont.setPointSizeF( 12.0 );
289  mFontColor = QColor( 0, 0, 0 );
290 
291  mLabelBarSpace = 3.0;
292  mBoxContentSpace = 1.0;
293  emit itemChanged();
294 }
295 
297 {
298  if ( mComposerMap )
299  {
300  setUnits( u );
301  double upperMagnitudeMultiplier = 1.0;
302  double widthInSelectedUnits = mapWidth();
303  double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
304  setNumUnitsPerSegment( initialUnitsPerSegment );
305 
306  switch ( mUnits )
307  {
308  case MapUnits:
309  {
310  upperMagnitudeMultiplier = 1.0;
311  setUnitLabeling( tr( "units" ) );
312  break;
313  }
314  case Meters:
315  {
316  if ( initialUnitsPerSegment > 1000.0 )
317  {
318  upperMagnitudeMultiplier = 1000.0;
319  setUnitLabeling( tr( "km" ) );
320  }
321  else
322  {
323  upperMagnitudeMultiplier = 1.0;
324  setUnitLabeling( tr( "m" ) );
325  }
326  break;
327  }
328  case Feet:
329  {
330  if ( initialUnitsPerSegment > 5419.95 )
331  {
332  upperMagnitudeMultiplier = 5419.95;
333  setUnitLabeling( tr( "miles" ) );
334  }
335  else
336  {
337  upperMagnitudeMultiplier = 1.0;
338  setUnitLabeling( tr( "ft" ) );
339  }
340  break;
341  }
342  case NauticalMiles:
343  {
344  upperMagnitudeMultiplier = 1;
345  setUnitLabeling( tr( "Nm" ) );
346  break;
347  }
348  }
349 
350  double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
351  int segmentMagnitude = floor( log10( segmentWidth ) );
352  double unitsPerSegment = upperMagnitudeMultiplier * ( pow( 10.0, segmentMagnitude ) );
353  double multiplier = floor(( widthInSelectedUnits / ( unitsPerSegment * 10.0 ) ) / 2.5 ) * 2.5;
354 
355  if ( multiplier > 0 )
356  {
357  unitsPerSegment = unitsPerSegment * multiplier;
358  }
359  setNumUnitsPerSegment( unitsPerSegment );
360  setNumMapUnitsPerScaleBarUnit( upperMagnitudeMultiplier );
361 
362  setNumSegments( 4 );
363  setNumSegmentsLeft( 2 );
364  }
365 
367  adjustBoxSize();
368  emit itemChanged();
369 }
370 
372 {
373  if ( !mStyle )
374  {
375  return;
376  }
377 
378  QRectF box = mStyle->calculateBoxSize();
379  setSceneRect( box );
380 }
381 
383 {
384  //Don't adjust box size for numeric scale bars:
385  if ( mStyle->name() != "Numeric" )
386  {
387  adjustBoxSize();
388  }
389  QgsComposerItem::update();
390 }
391 
393 {
394  if ( !mStyle )
395  {
396  return;
397  }
398  double width = mStyle->calculateBoxSize().width();
400  double widthAfter = mStyle->calculateBoxSize().width();
401  correctXPositionAlignment( width, widthAfter );
402  update();
403  emit itemChanged();
404 }
405 
406 void QgsComposerScaleBar::segmentPositions( QList<QPair<double, double> >& posWidthList ) const
407 {
408  posWidthList.clear();
409  double mCurrentXCoord = mPen.widthF() + mBoxContentSpace;
410 
411  //left segments
412  for ( int i = 0; i < mNumSegmentsLeft; ++i )
413  {
414  posWidthList.push_back( qMakePair( mCurrentXCoord, mSegmentMillimeters / mNumSegmentsLeft ) );
415  mCurrentXCoord += mSegmentMillimeters / mNumSegmentsLeft;
416  }
417 
418  //right segments
419  for ( int i = 0; i < mNumSegments; ++i )
420  {
421  posWidthList.push_back( qMakePair( mCurrentXCoord, mSegmentMillimeters ) );
422  mCurrentXCoord += mSegmentMillimeters;
423  }
424 }
425 
426 void QgsComposerScaleBar::setStyle( const QString& styleName )
427 {
428  delete mStyle;
429  mStyle = 0;
430 
431  //switch depending on style name
432  if ( styleName == "Single Box" )
433  {
434  mStyle = new QgsSingleBoxScaleBarStyle( this );
435  }
436  else if ( styleName == "Double Box" )
437  {
438  mStyle = new QgsDoubleBoxScaleBarStyle( this );
439  }
440  else if ( styleName == "Line Ticks Middle" || styleName == "Line Ticks Down" || styleName == "Line Ticks Up" )
441  {
442  QgsTicksScaleBarStyle* tickStyle = new QgsTicksScaleBarStyle( this );
443  if ( styleName == "Line Ticks Middle" )
444  {
446  }
447  else if ( styleName == "Line Ticks Down" )
448  {
450  }
451  else if ( styleName == "Line Ticks Up" )
452  {
454  }
455  mStyle = tickStyle;
456  }
457  else if ( styleName == "Numeric" )
458  {
459  mStyle = new QgsNumericScaleBarStyle( this );
460  }
461  emit itemChanged();
462 }
463 
465 {
466  if ( mStyle )
467  {
468  return mStyle->name();
469  }
470  else
471  {
472  return "";
473  }
474 }
475 
477 {
478  if ( mNumSegmentsLeft > 0 )
479  {
480  return QString::number( mNumUnitsPerSegment / mNumMapUnitsPerScaleBarUnit );
481  }
482  else
483  {
484  return "0";
485  }
486 }
487 
489 {
490  return mFont;
491 }
492 
493 void QgsComposerScaleBar::setFont( const QFont& font )
494 {
495  mFont = font;
496  update();
497  emit itemChanged();
498 }
499 
500 bool QgsComposerScaleBar::writeXML( QDomElement& elem, QDomDocument & doc ) const
501 {
502  if ( elem.isNull() )
503  {
504  return false;
505  }
506 
507  QDomElement composerScaleBarElem = doc.createElement( "ComposerScaleBar" );
508  composerScaleBarElem.setAttribute( "height", QString::number( mHeight ) );
509  composerScaleBarElem.setAttribute( "labelBarSpace", QString::number( mLabelBarSpace ) );
510  composerScaleBarElem.setAttribute( "boxContentSpace", QString::number( mBoxContentSpace ) );
511  composerScaleBarElem.setAttribute( "numSegments", mNumSegments );
512  composerScaleBarElem.setAttribute( "numSegmentsLeft", mNumSegmentsLeft );
513  composerScaleBarElem.setAttribute( "numUnitsPerSegment", QString::number( mNumUnitsPerSegment ) );
514  composerScaleBarElem.setAttribute( "segmentMillimeters", QString::number( mSegmentMillimeters ) );
515  composerScaleBarElem.setAttribute( "numMapUnitsPerScaleBarUnit", QString::number( mNumMapUnitsPerScaleBarUnit ) );
516  composerScaleBarElem.setAttribute( "font", mFont.toString() );
517  composerScaleBarElem.setAttribute( "outlineWidth", QString::number( mPen.widthF() ) );
518  composerScaleBarElem.setAttribute( "unitLabel", mUnitLabeling );
519  composerScaleBarElem.setAttribute( "units", mUnits );
520  composerScaleBarElem.setAttribute( "lineJoinStyle", QgsSymbolLayerV2Utils::encodePenJoinStyle( mLineJoinStyle ) );
521  composerScaleBarElem.setAttribute( "lineCapStyle", QgsSymbolLayerV2Utils::encodePenCapStyle( mLineCapStyle ) );
522 
523  //style
524  if ( mStyle )
525  {
526  composerScaleBarElem.setAttribute( "style", mStyle->name() );
527  }
528 
529  //map id
530  if ( mComposerMap )
531  {
532  composerScaleBarElem.setAttribute( "mapId", mComposerMap->id() );
533  }
534 
535  //colors
536  composerScaleBarElem.setAttribute( "brushColor", mBrush.color().name() );
537  composerScaleBarElem.setAttribute( "penColor", mPen.color().name() );
538  composerScaleBarElem.setAttribute( "fontColor", mFontColor.name() );
539 
540  //alignment
541  composerScaleBarElem.setAttribute( "alignment", QString::number(( int ) mAlignment ) );
542 
543  elem.appendChild( composerScaleBarElem );
544  return _writeXML( composerScaleBarElem, doc );
545 }
546 
547 bool QgsComposerScaleBar::readXML( const QDomElement& itemElem, const QDomDocument& doc )
548 {
549  if ( itemElem.isNull() )
550  {
551  return false;
552  }
553 
554  mHeight = itemElem.attribute( "height", "5.0" ).toDouble();
555  mLabelBarSpace = itemElem.attribute( "labelBarSpace", "3.0" ).toDouble();
556  mBoxContentSpace = itemElem.attribute( "boxContentSpace", "1.0" ).toDouble();
557  mNumSegments = itemElem.attribute( "numSegments", "2" ).toInt();
558  mNumSegmentsLeft = itemElem.attribute( "numSegmentsLeft", "0" ).toInt();
559  mNumUnitsPerSegment = itemElem.attribute( "numUnitsPerSegment", "1.0" ).toDouble();
560  mSegmentMillimeters = itemElem.attribute( "segmentMillimeters", "0.0" ).toDouble();
561  mNumMapUnitsPerScaleBarUnit = itemElem.attribute( "numMapUnitsPerScaleBarUnit", "1.0" ).toDouble();
562  mPen.setWidthF( itemElem.attribute( "outlineWidth", "1.0" ).toDouble() );
563  mUnitLabeling = itemElem.attribute( "unitLabel" );
564  mLineJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "lineJoinStyle", "miter" ) );
565  mPen.setJoinStyle( mLineJoinStyle );
566  mLineCapStyle = QgsSymbolLayerV2Utils::decodePenCapStyle( itemElem.attribute( "lineCapStyle", "square" ) );
567  mPen.setCapStyle( mLineCapStyle );
568  QString fontString = itemElem.attribute( "font", "" );
569  if ( !fontString.isEmpty() )
570  {
571  mFont.fromString( fontString );
572  }
573 
574  //colors
575  //fill color
576  mBrush.setColor( QColor( itemElem.attribute( "brushColor", "#000000" ) ) );
577  mPen.setColor( QColor( itemElem.attribute( "penColor", "#000000" ) ) );
578  mFontColor.setNamedColor( itemElem.attribute( "fontColor", "#000000" ) );
579 
580  //style
581  delete mStyle;
582  mStyle = 0;
583  QString styleString = itemElem.attribute( "style", "" );
584  setStyle( tr( styleString.toLocal8Bit().data() ) );
585 
586  mUnits = ( ScaleBarUnits )itemElem.attribute( "units" ).toInt();
587  mAlignment = ( Alignment )( itemElem.attribute( "alignment", "0" ).toInt() );
588 
589  //map
590  int mapId = itemElem.attribute( "mapId", "-1" ).toInt();
591  if ( mapId >= 0 )
592  {
595  if ( mComposerMap )
596  {
597  connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( updateSegmentSize() ) );
598  connect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
599  }
600  }
601 
603 
604  //restore general composer item properties
605  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
606  if ( composerItemList.size() > 0 )
607  {
608  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
609  _readXML( composerItemElem, doc );
610  }
611 
612  return true;
613 }
614 
615 void QgsComposerScaleBar::correctXPositionAlignment( double width, double widthAfter )
616 {
617  //Don't adjust position for numeric scale bars:
618  if ( mStyle->name() == "Numeric" )
619  {
620  return;
621  }
622 
623  if ( mAlignment == Middle )
624  {
625  move( -( widthAfter - width ) / 2.0, 0 );
626  }
627  else if ( mAlignment == Right )
628  {
629  move( -( widthAfter - width ), 0 );
630  }
631 }
632 
Double box with alternating colors.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
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)
void setLineCapStyle(Qt::PenCapStyle style)
Sets cap style used when drawing the lines in the scalebar.
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'.
Qt::PenJoinStyle mLineJoinStyle
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
void setUnitLabeling(const QString &label)
void applyDefaultSize(ScaleBarUnits u=Meters)
Apply default size (scale bar 1/5 of map item width)
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)
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
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)
void setLineJoinStyle(Qt::PenJoinStyle style)
Sets join style used when drawing the lines in the scalebar.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:194
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:179
static Qt::PenCapStyle decodePenCapStyle(QString str)
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...
Qt::PenCapStyle mLineCapStyle
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
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
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.
Definition: qgspoint.h:63
const QgsComposerMap * composerMap() const
Graphics scene for map printing.
Object representing map window.
QString style() const
Returns style name.
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
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.
virtual void drawBackground(QPainter *p)
Draw background.
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
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.
static double fromUnitToUnitFactor(QGis::UnitType fromUnit, QGis::UnitType toUnit)
Returns the conversion factor between the specified units.
Definition: qgis.cpp:123
QString mUnitLabeling
Labeling of map units.
static Qt::PenJoinStyle decodePenJoinStyle(QString str)
double mapWidth() const
Returns diagonal of composer map in selected units (map units / meters / feet / nautical miles) ...
const QgsComposerMap * mComposerMap
Reference to composer map object.
void setNumUnitsPerSegment(double units)
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:199
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)
Definition: qgsrectangle.h:184
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. ...
static QString encodePenCapStyle(Qt::PenCapStyle style)
#define tr(sourceText)