QGIS API Documentation  2.12.0-Lyon
qgscomposerarrow.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerarrow.cpp
3  ----------------------
4  begin : November 2009
5  copyright : (C) 2009 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscomposerarrow.h"
19 #include "qgscomposition.h"
20 #include "qgscomposerutils.h"
21 #include "qgssymbollayerv2utils.h"
22 #include <QPainter>
23 #include <QSvgRenderer>
24 #include <QVector2D>
25 
26 #include <cmath>
27 
29  : QgsComposerItem( c )
30  , mStartPoint( 0, 0 )
31  , mStopPoint( 0, 0 )
32  , mStartXIdx( 0 )
33  , mStartYIdx( 0 )
34  , mMarkerMode( DefaultMarker )
35  , mArrowHeadOutlineWidth( 1.0 )
36  , mArrowHeadOutlineColor( Qt::black )
37  , mArrowHeadFillColor( Qt::black )
38  , mBoundsBehaviour( 24 )
39  , mLineSymbol( 0 )
40 {
41  init();
42 }
43 
44 QgsComposerArrow::QgsComposerArrow( const QPointF& startPoint, const QPointF& stopPoint, QgsComposition* c )
45  : QgsComposerItem( c )
46  , mStartPoint( startPoint )
47  , mStopPoint( stopPoint )
48  , mMarkerMode( DefaultMarker )
49  , mArrowHeadOutlineWidth( 1.0 )
50  , mArrowHeadOutlineColor( Qt::black )
51  , mArrowHeadFillColor( Qt::black )
52  , mBoundsBehaviour( 24 )
53  , mLineSymbol( 0 )
54 {
55  mStartXIdx = mStopPoint.x() < mStartPoint.x();
56  mStartYIdx = mStopPoint.y() < mStartPoint.y();
57  init();
58  adaptItemSceneRect();
59 }
60 
62 {
63  delete mLineSymbol;
64 }
65 
66 void QgsComposerArrow::init()
67 {
68  setArrowHeadWidth( 4 );
69  mPen.setColor( mArrowHeadOutlineColor );
70  mPen.setWidthF( 1 );
71  mBrush.setColor( mArrowHeadFillColor );
72  createDefaultLineSymbol();
73 
74  //default to no background
75  setBackgroundEnabled( false );
76 }
77 
78 
79 void QgsComposerArrow::createDefaultLineSymbol()
80 {
81  delete mLineSymbol;
82  QgsStringMap properties;
83  properties.insert( "color", "0,0,0,255" );
84  properties.insert( "width", "1" );
85  properties.insert( "capstyle", "square" );
86  mLineSymbol = QgsLineSymbolV2::createSimple( properties );
87 }
88 
89 void QgsComposerArrow::paint( QPainter* painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
90 {
91  Q_UNUSED( itemStyle );
92  Q_UNUSED( pWidget );
93  if ( !painter || !painter->device() )
94  {
95  return;
96  }
97  if ( !shouldDrawItem() )
98  {
99  return;
100  }
101 
102  drawBackground( painter );
103 
104  painter->save();
105  //antialiasing on
106  painter->setRenderHint( QPainter::Antialiasing, true );
107 
108  //draw line section
109  drawLine( painter );
110 
111  //draw arrowhead if required
112  if ( mMarkerMode != NoMarker )
113  {
114  painter->setBrush( mBrush );
115  painter->setPen( mPen );
116 
117  if ( mMarkerMode == DefaultMarker )
118  {
119  drawHardcodedMarker( painter, EndMarker );
120  }
121  else if ( mMarkerMode == SVGMarker )
122  {
123  drawSVGMarker( painter, StartMarker, mStartMarkerFile );
124  drawSVGMarker( painter, EndMarker, mEndMarkerFile );
125  }
126  }
127 
128  painter->restore();
129 
130  drawFrame( painter );
131  if ( isSelected() )
132  {
133  drawSelectionBoxes( painter );
134  }
135 }
136 
137 void QgsComposerArrow::setSceneRect( const QRectF& rectangle )
138 {
139  //update rect for data defined size and position
140  QRectF evaluatedRect = evalItemRect( rectangle );
141 
142  if ( evaluatedRect.width() < 0 )
143  {
144  mStartXIdx = 1 - mStartXIdx;
145  }
146  if ( evaluatedRect.height() < 0 )
147  {
148  mStartYIdx = 1 - mStartYIdx;
149  }
150 
151  double margin = computeMarkerMargin();
152 
153  // Ensure the rectangle is at least as large as needed to include the markers
154  QRectF rect = rectangle.united( QRectF( evaluatedRect.x(), evaluatedRect.y(), 2. * margin, 2. * margin ) );
155 
156  // Compute new start and stop positions
157  double x[2] = {rect.x(), rect.x() + rect.width()};
158  double y[2] = {rect.y(), rect.y() + rect.height()};
159 
160  double xsign = x[mStartXIdx] < x[1 - mStartXIdx] ? 1.0 : -1.0;
161  double ysign = y[mStartYIdx] < y[1 - mStartYIdx] ? 1.0 : -1.0;
162 
163  mStartPoint = QPointF( x[mStartXIdx] + xsign * margin, y[mStartYIdx] + ysign * margin );
164  mStopPoint = QPointF( x[1 - mStartXIdx] - xsign * margin, y[1 - mStartYIdx] - ysign * margin );
165 
167 }
168 
169 void QgsComposerArrow::drawLine( QPainter *painter )
170 {
171  if ( ! mLineSymbol || ! mComposition )
172  {
173  return;
174  }
175 
176  QPaintDevice* thePaintDevice = painter->device();
177  painter->save();
178  //setup painter scaling to dots so that raster symbology is drawn to scale
179  double dotsPerMM = thePaintDevice->logicalDpiX() / 25.4;
180  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); //scale painter from mm to dots
181 
182  //setup render context
184  //context units should be in dots
185  ms.setOutputDpi( painter->device()->logicalDpiX() );
187  context.setForceVectorOutput( true );
188  context.setPainter( painter );
189  QgsExpressionContext* expressionContext = createExpressionContext();
190  context.setExpressionContext( *expressionContext );
191  delete expressionContext;
192 
193  //line scaled to dots
194  QPolygonF line;
195  line << QPointF( mStartPoint.x() - pos().x(), mStartPoint.y() - pos().y() ) * dotsPerMM
196  << QPointF( mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y() ) * dotsPerMM;
197 
198  mLineSymbol->startRender( context );
199  mLineSymbol->renderPolyline( line, 0, context );
200  mLineSymbol->stopRender( context );
201  painter->restore();
202 
203 }
204 
205 void QgsComposerArrow::drawHardcodedMarker( QPainter *p, MarkerType type )
206 {
207  Q_UNUSED( type );
208  if ( mBoundsBehaviour == 22 )
209  {
210  //if arrow was created in versions prior to 2.4, use the old rendering style
211  QgsComposerUtils::drawArrowHead( p, mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y(), QgsComposerUtils::angle( mStartPoint, mStopPoint ), mArrowHeadWidth );
212  }
213  else
214  {
215  QVector2D dir = QVector2D( mStopPoint - mStartPoint ).normalized();
216  QPointF stop = mStopPoint + ( dir * 0.5 * mArrowHeadWidth ).toPointF();
217  QgsComposerUtils::drawArrowHead( p, stop.x() - pos().x(), stop.y() - pos().y(), QgsComposerUtils::angle( mStartPoint, stop ), mArrowHeadWidth );
218  }
219 }
220 
221 void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QString &markerPath )
222 {
223  Q_UNUSED( markerPath );
224  double ang = QgsComposerUtils::angle( mStartPoint, mStopPoint );
225 
226  double arrowHeadHeight;
227  if ( type == StartMarker )
228  {
229  arrowHeadHeight = mStartArrowHeadHeight;
230  }
231  else
232  {
233  arrowHeadHeight = mStopArrowHeadHeight;
234  }
235  if ( mArrowHeadWidth <= 0 || arrowHeadHeight <= 0 )
236  {
237  //bad image size
238  return;
239  }
240 
241  QPointF imageFixPoint;
242  imageFixPoint.setX( mArrowHeadWidth / 2.0 );
243  QPointF canvasPoint;
244  if ( type == StartMarker )
245  {
246  canvasPoint = QPointF( mStartPoint.x() - pos().x(), mStartPoint.y() - pos().y() );
247  imageFixPoint.setY( mStartArrowHeadHeight );
248  }
249  else //end marker
250  {
251  canvasPoint = QPointF( mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y() );
252  imageFixPoint.setY( 0 );
253  }
254 
255  //rasterize svg
256  QSvgRenderer r;
257  if ( type == StartMarker )
258  {
259  if ( mStartMarkerFile.isEmpty() || !r.load( mStartMarkerFile ) )
260  {
261  return;
262  }
263  }
264  else //end marker
265  {
266  if ( mEndMarkerFile.isEmpty() || !r.load( mEndMarkerFile ) )
267  {
268  return;
269  }
270  }
271 
272  p->save();
273  p->setRenderHint( QPainter::Antialiasing );
274  if ( mBoundsBehaviour == 22 )
275  {
276  //if arrow was created in versions prior to 2.4, use the old rendering style
277  //rotate image fix point for backtransform
278  QPointF fixPoint;
279  if ( type == StartMarker )
280  {
281  fixPoint.setX( 0 ); fixPoint.setY( arrowHeadHeight / 2.0 );
282  }
283  else
284  {
285  fixPoint.setX( 0 ); fixPoint.setY( -arrowHeadHeight / 2.0 );
286  }
287  QPointF rotatedFixPoint;
288  double angleRad = ang / 180 * M_PI;
289  rotatedFixPoint.setX( fixPoint.x() * cos( angleRad ) + fixPoint.y() * -sin( angleRad ) );
290  rotatedFixPoint.setY( fixPoint.x() * sin( angleRad ) + fixPoint.y() * cos( angleRad ) );
291  p->translate( canvasPoint.x() - rotatedFixPoint.x(), canvasPoint.y() - rotatedFixPoint.y() );
292  }
293  else
294  {
295  p->translate( canvasPoint.x(), canvasPoint.y() );
296  }
297 
298  p->rotate( ang );
299  p->translate( -mArrowHeadWidth / 2.0, -arrowHeadHeight / 2.0 );
300  r.render( p, QRectF( 0, 0, mArrowHeadWidth, arrowHeadHeight ) );
301  p->restore();
302 
303  return;
304 }
305 
307 {
308  QSvgRenderer r;
309  mStartMarkerFile = svgPath;
310  if ( svgPath.isEmpty() || !r.load( svgPath ) )
311  {
312  mStartArrowHeadHeight = 0;
313  }
314  else
315  {
316  //calculate mArrowHeadHeight from svg file and mArrowHeadWidth
317  QRect viewBox = r.viewBox();
318  mStartArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
319  }
320  adaptItemSceneRect();
321 }
322 
324 {
325  QSvgRenderer r;
326  mEndMarkerFile = svgPath;
327  if ( svgPath.isEmpty() || !r.load( svgPath ) )
328  {
329  mStopArrowHeadHeight = 0;
330  }
331  else
332  {
333  //calculate mArrowHeadHeight from svg file and mArrowHeadWidth
334  QRect viewBox = r.viewBox();
335  mStopArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
336  }
337  adaptItemSceneRect();
338 }
339 
341 {
342  if ( mLineSymbol )
343  {
344  return mLineSymbol->color();
345  }
346 
347  return Qt::black;
348 }
349 
351 {
352  if ( mLineSymbol )
353  {
354  mLineSymbol->setColor( c );
355  }
356  mArrowHeadOutlineColor = c;
357  mArrowHeadFillColor = c;
358  mPen.setColor( c );
359  mBrush.setColor( c );
360 }
361 
363 {
364  mArrowHeadOutlineColor = color;
365  mPen.setColor( color );
366 }
367 
369 {
370  mArrowHeadFillColor = color;
371  mBrush.setColor( color );
372 }
373 
375 {
376  if ( mLineSymbol )
377  {
378  mLineSymbol->setWidth( width );
379  }
380  mArrowHeadOutlineWidth = width;
381  mPen.setWidthF( mArrowHeadOutlineWidth );
382 
383  adaptItemSceneRect();
384 }
385 
387 {
388  if ( mLineSymbol )
389  {
390  return mLineSymbol->width();
391  }
392 
393  return 0;
394 }
395 
397 {
398  mArrowHeadOutlineWidth = width;
399  mPen.setWidthF( mArrowHeadOutlineWidth );
400 
401  adaptItemSceneRect();
402 }
403 
405 {
406  delete mLineSymbol;
407  mLineSymbol = symbol;
408 }
409 
411 {
412  mArrowHeadWidth = width;
413  setStartMarker( mStartMarkerFile );
414  setEndMarker( mEndMarkerFile );
415  adaptItemSceneRect();
416 }
417 
418 double QgsComposerArrow::computeMarkerMargin() const
419 {
420  double margin = 0;
421 
422  if ( mBoundsBehaviour == 22 )
423  {
424  //if arrow was created in versions prior to 2.4, use the old rendering style
425  if ( mMarkerMode == DefaultMarker )
426  {
427  margin = mPen.widthF() / 2.0 + mArrowHeadWidth / 2.0;
428  }
429  else if ( mMarkerMode == NoMarker )
430  {
431  margin = mPen.widthF() / 2.0;
432  }
433  else if ( mMarkerMode == SVGMarker )
434  {
435  double maxArrowHeight = qMax( mStartArrowHeadHeight, mStopArrowHeadHeight );
436  margin = mPen.widthF() / 2 + qMax( mArrowHeadWidth / 2.0, maxArrowHeight / 2.0 );
437  }
438  }
439  else
440  {
441  if ( mMarkerMode == DefaultMarker )
442  {
443  margin = mPen.widthF() / std::sqrt( 2.0 ) + mArrowHeadWidth / 2.0;
444  }
445  else if ( mMarkerMode == NoMarker )
446  {
447  margin = mPen.widthF() / std::sqrt( 2.0 );
448  }
449  else if ( mMarkerMode == SVGMarker )
450  {
451  double startMarkerMargin = std::sqrt( 0.25 * ( mStartArrowHeadHeight * mStartArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
452  double stopMarkerMargin = std::sqrt( 0.25 * ( mStopArrowHeadHeight * mStopArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
453  double markerMargin = qMax( startMarkerMargin, stopMarkerMargin );
454  margin = qMax( mPen.widthF() / std::sqrt( 2.0 ), markerMargin );
455  }
456  }
457  return margin;
458 }
459 
460 void QgsComposerArrow::adaptItemSceneRect()
461 {
462  //rectangle containing start and end point
463  QRectF rect = QRectF( qMin( mStartPoint.x(), mStopPoint.x() ), qMin( mStartPoint.y(), mStopPoint.y() ),
464  qAbs( mStopPoint.x() - mStartPoint.x() ), qAbs( mStopPoint.y() - mStartPoint.y() ) );
465  double enlarge = computeMarkerMargin();
466  rect.adjust( -enlarge, -enlarge, enlarge, enlarge );
468 }
469 
471 {
472  mMarkerMode = mode;
473  adaptItemSceneRect();
474 }
475 
477 {
478  QDomElement composerArrowElem = doc.createElement( "ComposerArrow" );
479  composerArrowElem.setAttribute( "arrowHeadWidth", QString::number( mArrowHeadWidth ) );
480  composerArrowElem.setAttribute( "arrowHeadFillColor", QgsSymbolLayerV2Utils::encodeColor( mArrowHeadFillColor ) );
481  composerArrowElem.setAttribute( "arrowHeadOutlineColor", QgsSymbolLayerV2Utils::encodeColor( mArrowHeadOutlineColor ) );
482  composerArrowElem.setAttribute( "outlineWidth", QString::number( mArrowHeadOutlineWidth ) );
483  composerArrowElem.setAttribute( "markerMode", mMarkerMode );
484  composerArrowElem.setAttribute( "startMarkerFile", mStartMarkerFile );
485  composerArrowElem.setAttribute( "endMarkerFile", mEndMarkerFile );
486  composerArrowElem.setAttribute( "boundsBehaviourVersion", QString::number( mBoundsBehaviour ) );
487 
488  QDomElement styleElem = doc.createElement( "lineStyle" );
489  QDomElement lineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mLineSymbol, doc );
490  styleElem.appendChild( lineStyleElem );
491  composerArrowElem.appendChild( styleElem );
492 
493  //start point
494  QDomElement startPointElem = doc.createElement( "StartPoint" );
495  startPointElem.setAttribute( "x", QString::number( mStartPoint.x() ) );
496  startPointElem.setAttribute( "y", QString::number( mStartPoint.y() ) );
497  composerArrowElem.appendChild( startPointElem );
498 
499  //stop point
500  QDomElement stopPointElem = doc.createElement( "StopPoint" );
501  stopPointElem.setAttribute( "x", QString::number( mStopPoint.x() ) );
502  stopPointElem.setAttribute( "y", QString::number( mStopPoint.y() ) );
503  composerArrowElem.appendChild( stopPointElem );
504 
505  elem.appendChild( composerArrowElem );
506  return _writeXML( composerArrowElem, doc );
507 }
508 
509 bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument& doc )
510 {
511  mArrowHeadWidth = itemElem.attribute( "arrowHeadWidth", "2.0" ).toDouble();
512  mArrowHeadFillColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "arrowHeadFillColor", "0,0,0,255" ) );
513  mArrowHeadOutlineColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "arrowHeadOutlineColor", "0,0,0,255" ) );
514  mArrowHeadOutlineWidth = itemElem.attribute( "outlineWidth", "1.0" ).toDouble();
515  setStartMarker( itemElem.attribute( "startMarkerFile", "" ) );
516  setEndMarker( itemElem.attribute( "endMarkerFile", "" ) );
517  mMarkerMode = QgsComposerArrow::MarkerMode( itemElem.attribute( "markerMode", "0" ).toInt() );
518  //if bounds behaviour version is not set, default to 2.2 behaviour
519  mBoundsBehaviour = itemElem.attribute( "boundsBehaviourVersion", "22" ).toInt();
520 
521  //arrow style
522  QDomElement styleElem = itemElem.firstChildElement( "lineStyle" );
523  if ( !styleElem.isNull() )
524  {
525  QDomElement lineStyleElem = styleElem.firstChildElement( "symbol" );
526  if ( !lineStyleElem.isNull() )
527  {
528  delete mLineSymbol;
529  mLineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( lineStyleElem );
530  }
531  }
532  else
533  {
534  //old project file, read arrow width and color
535  delete mLineSymbol;
536 
537  QgsStringMap properties;
538  properties.insert( "width", itemElem.attribute( "outlineWidth", "1.0" ) );
539 
540  if ( mBoundsBehaviour == 22 )
541  {
542  //if arrow was created in versions prior to 2.4, use the old rendering style
543  properties.insert( "capstyle", "flat" );
544  }
545  else
546  {
547  properties.insert( "capstyle", "square" );
548  }
549  int red = 0;
550  int blue = 0;
551  int green = 0;
552  int alpha = 255;
553 
554  QDomNodeList arrowColorList = itemElem.elementsByTagName( "ArrowColor" );
555  if ( arrowColorList.size() > 0 )
556  {
557  QDomElement arrowColorElem = arrowColorList.at( 0 ).toElement();
558  red = arrowColorElem.attribute( "red", "0" ).toInt();
559  green = arrowColorElem.attribute( "green", "0" ).toInt();
560  blue = arrowColorElem.attribute( "blue", "0" ).toInt();
561  alpha = arrowColorElem.attribute( "alpha", "255" ).toInt();
562  mArrowHeadFillColor = QColor( red, green, blue, alpha );
563  mArrowHeadOutlineColor = QColor( red, green, blue, alpha );
564  }
565  properties.insert( "color", QString( "%1,%2,%3,%4" ).arg( red ).arg( green ).arg( blue ).arg( alpha ) );
566  mLineSymbol = QgsLineSymbolV2::createSimple( properties );
567  }
568 
569  mPen.setColor( mArrowHeadOutlineColor );
570  mPen.setWidthF( mArrowHeadOutlineWidth );
571  mBrush.setColor( mArrowHeadFillColor );
572 
573  //restore general composer item properties
574  //needs to be before start point / stop point because setSceneRect()
575  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
576  if ( composerItemList.size() > 0 )
577  {
578  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
579  _readXML( composerItemElem, doc );
580  }
581 
582  //start point
583  QDomNodeList startPointList = itemElem.elementsByTagName( "StartPoint" );
584  if ( startPointList.size() > 0 )
585  {
586  QDomElement startPointElem = startPointList.at( 0 ).toElement();
587  mStartPoint.setX( startPointElem.attribute( "x", "0.0" ).toDouble() );
588  mStartPoint.setY( startPointElem.attribute( "y", "0.0" ).toDouble() );
589  }
590 
591  //stop point
592  QDomNodeList stopPointList = itemElem.elementsByTagName( "StopPoint" );
593  if ( stopPointList.size() > 0 )
594  {
595  QDomElement stopPointElem = stopPointList.at( 0 ).toElement();
596  mStopPoint.setX( stopPointElem.attribute( "x", "0.0" ).toDouble() );
597  mStopPoint.setY( stopPointElem.attribute( "y", "0.0" ).toDouble() );
598  }
599 
600  mStartXIdx = mStopPoint.x() < mStartPoint.x();
601  mStartYIdx = mStopPoint.y() < mStartPoint.y();
602 
603  adaptItemSceneRect();
604  emit itemChanged();
605  return true;
606 }
607 
608 
QgsComposerArrow(QgsComposition *c)
Constructor.
void setForceVectorOutput(bool force)
QDomNodeList elementsByTagName(const QString &tagname) const
qreal x() const
qreal y() const
Q_DECL_DEPRECATED void setOutlineWidth(double width)
Sets the pen width for drawing the line and arrow head.
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
void render(QPainter *painter)
qreal x() const
qreal y() const
QString attribute(const QString &name, const QString &defValue) const
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
void itemChanged()
Emitted when the item changes.
static QString encodeColor(const QColor &color)
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void scale(qreal sx, qreal sy)
A item that forms part of a map composition.
void setStartMarker(const QString &svgPath)
Sets the marker to draw at the start of the line.
static QDomElement saveSymbol(const QString &symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
void save()
int height() const
virtual void drawFrame(QPainter *p)
Draw black frame around item.
void rotate(qreal angle)
void setArrowHeadWidth(double width)
Sets the width of the arrow head in mm.
double toDouble(bool *ok) const
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the objects's current state.
void adjust(qreal dx1, qreal dy1, qreal dx2, qreal dy2)
void setWidth(double width)
void setArrowHeadOutlineWidth(const double width)
Sets the pen width for the outline of the arrow head.
Q_DECL_DEPRECATED double outlineWidth() const
Returns the pen width for drawing the line and arrow head.
The QgsMapSettings class contains configuration for rendering of the map.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
QDomElement toElement() const
void setSceneRect(const QRectF &rectangle) override
Modifies position of start and endpoint and calls QgsComposerItem::setSceneRect.
void setColor(const QColor &color)
static void drawArrowHead(QPainter *p, const double x, const double y, const double angle, const double arrowHeadWidth)
Draws an arrow head on to a QPainter.
QPointF pos() const
QString number(int n, int base)
qreal x() const
qreal y() const
double width() const
Q_DECL_DEPRECATED QColor arrowColor() const
Returns the color for the line and arrow head.
bool load(const QString &filename)
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
void setPen(const QColor &color)
void setAttribute(const QString &name, const QString &value)
bool isSelected() const
int toInt(bool *ok, int base) const
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isEmpty() const
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=0)
Evaluates an item's bounding rect to consider data defined position and size of item and reference po...
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
#define M_PI
QPaintDevice * device() const
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
void setPainter(QPainter *p)
void setArrowHeadOutlineColor(const QColor &color)
Sets the color used to draw the outline around the arrow head.
void setLineSymbol(QgsLineSymbolV2 *symbol)
Sets the line symbol used for drawing the line portion of the arrow.
QRectF united(const QRectF &rectangle) const
void setMarkerMode(MarkerMode mode)
Sets the marker mode, which controls how the arrow endpoints are drawn.
Q_DECL_DEPRECATED void setArrowColor(const QColor &c)
Sets the color for the line and arrow head.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
void setColor(const QColor &color)
void setBackgroundEnabled(const bool drawBackground)
Set whether this item has a Background drawn around it or not.
void setArrowHeadFillColor(const QColor &color)
Sets the color used to fill the arrow head.
Graphics scene for map printing.
int logicalDpiX() const
bool isNull() const
void restore()
QgsComposition * mComposition
Contains information about the context of a rendering operation.
int width() const
qreal width() const
void stopRender(QgsRenderContext &context)
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
virtual void drawBackground(QPainter *p)
Draw background.
void setX(qreal x)
void setY(qreal y)
QDomElement firstChildElement(const QString &tagName) const
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...
qreal widthF() const
void translate(const QPointF &offset)
qreal height() const
QVector2D normalized() const
static QColor decodeColor(const QString &str)
iterator insert(const Key &key, const T &value)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from DOM document.
int size() const
static double angle(const QPointF &p1, const QPointF &p2)
Calculates the angle of the line from p1 to p2 (counter clockwise, starting from a line from north to...
QDomElement createElement(const QString &tagName)
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Stores state in DOM element.
void setColor(const QColor &color)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint - draw on canvas.
void setEndMarker(const QString &svgPath)
Sets the marker to draw at the end of the line.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QDomNode at(int index) const
QRectF rect() const
QColor color() const