QGIS API Documentation  2.15.0-Master (af20121)
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( nullptr )
40 {
41  init();
42 }
43 
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( nullptr )
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, nullptr, 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 );
282  fixPoint.setY( arrowHeadHeight / 2.0 );
283  }
284  else
285  {
286  fixPoint.setX( 0 );
287  fixPoint.setY( -arrowHeadHeight / 2.0 );
288  }
289  QPointF rotatedFixPoint;
290  double angleRad = ang / 180 * M_PI;
291  rotatedFixPoint.setX( fixPoint.x() * cos( angleRad ) + fixPoint.y() * -sin( angleRad ) );
292  rotatedFixPoint.setY( fixPoint.x() * sin( angleRad ) + fixPoint.y() * cos( angleRad ) );
293  p->translate( canvasPoint.x() - rotatedFixPoint.x(), canvasPoint.y() - rotatedFixPoint.y() );
294  }
295  else
296  {
297  p->translate( canvasPoint.x(), canvasPoint.y() );
298  }
299 
300  p->rotate( ang );
301  p->translate( -mArrowHeadWidth / 2.0, -arrowHeadHeight / 2.0 );
302  r.render( p, QRectF( 0, 0, mArrowHeadWidth, arrowHeadHeight ) );
303  p->restore();
304 
305  return;
306 }
307 
309 {
310  QSvgRenderer r;
311  mStartMarkerFile = svgPath;
312  if ( svgPath.isEmpty() || !r.load( svgPath ) )
313  {
314  mStartArrowHeadHeight = 0;
315  }
316  else
317  {
318  //calculate mArrowHeadHeight from svg file and mArrowHeadWidth
319  QRect viewBox = r.viewBox();
320  mStartArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
321  }
322  adaptItemSceneRect();
323 }
324 
326 {
327  QSvgRenderer r;
328  mEndMarkerFile = svgPath;
329  if ( svgPath.isEmpty() || !r.load( svgPath ) )
330  {
331  mStopArrowHeadHeight = 0;
332  }
333  else
334  {
335  //calculate mArrowHeadHeight from svg file and mArrowHeadWidth
336  QRect viewBox = r.viewBox();
337  mStopArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
338  }
339  adaptItemSceneRect();
340 }
341 
343 {
344  if ( mLineSymbol )
345  {
346  return mLineSymbol->color();
347  }
348 
349  return Qt::black;
350 }
351 
353 {
354  if ( mLineSymbol )
355  {
356  mLineSymbol->setColor( c );
357  }
358  mArrowHeadOutlineColor = c;
359  mArrowHeadFillColor = c;
360  mPen.setColor( c );
361  mBrush.setColor( c );
362 }
363 
365 {
366  mArrowHeadOutlineColor = color;
367  mPen.setColor( color );
368 }
369 
371 {
372  mArrowHeadFillColor = color;
373  mBrush.setColor( color );
374 }
375 
377 {
378  if ( mLineSymbol )
379  {
380  mLineSymbol->setWidth( width );
381  }
382  mArrowHeadOutlineWidth = width;
383  mPen.setWidthF( mArrowHeadOutlineWidth );
384 
385  adaptItemSceneRect();
386 }
387 
389 {
390  if ( mLineSymbol )
391  {
392  return mLineSymbol->width();
393  }
394 
395  return 0;
396 }
397 
399 {
400  mArrowHeadOutlineWidth = width;
401  mPen.setWidthF( mArrowHeadOutlineWidth );
402 
403  adaptItemSceneRect();
404 }
405 
407 {
408  delete mLineSymbol;
409  mLineSymbol = symbol;
410 }
411 
413 {
414  mArrowHeadWidth = width;
415  setStartMarker( mStartMarkerFile );
416  setEndMarker( mEndMarkerFile );
417  adaptItemSceneRect();
418 }
419 
420 double QgsComposerArrow::computeMarkerMargin() const
421 {
422  double margin = 0;
423 
424  if ( mBoundsBehaviour == 22 )
425  {
426  //if arrow was created in versions prior to 2.4, use the old rendering style
427  if ( mMarkerMode == DefaultMarker )
428  {
429  margin = mPen.widthF() / 2.0 + mArrowHeadWidth / 2.0;
430  }
431  else if ( mMarkerMode == NoMarker )
432  {
433  margin = mPen.widthF() / 2.0;
434  }
435  else if ( mMarkerMode == SVGMarker )
436  {
437  double maxArrowHeight = qMax( mStartArrowHeadHeight, mStopArrowHeadHeight );
438  margin = mPen.widthF() / 2 + qMax( mArrowHeadWidth / 2.0, maxArrowHeight / 2.0 );
439  }
440  }
441  else
442  {
443  if ( mMarkerMode == DefaultMarker )
444  {
445  margin = mPen.widthF() / std::sqrt( 2.0 ) + mArrowHeadWidth / 2.0;
446  }
447  else if ( mMarkerMode == NoMarker )
448  {
449  margin = mPen.widthF() / std::sqrt( 2.0 );
450  }
451  else if ( mMarkerMode == SVGMarker )
452  {
453  double startMarkerMargin = std::sqrt( 0.25 * ( mStartArrowHeadHeight * mStartArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
454  double stopMarkerMargin = std::sqrt( 0.25 * ( mStopArrowHeadHeight * mStopArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
455  double markerMargin = qMax( startMarkerMargin, stopMarkerMargin );
456  margin = qMax( mPen.widthF() / std::sqrt( 2.0 ), markerMargin );
457  }
458  }
459  return margin;
460 }
461 
462 void QgsComposerArrow::adaptItemSceneRect()
463 {
464  //rectangle containing start and end point
465  QRectF rect = QRectF( qMin( mStartPoint.x(), mStopPoint.x() ), qMin( mStartPoint.y(), mStopPoint.y() ),
466  qAbs( mStopPoint.x() - mStartPoint.x() ), qAbs( mStopPoint.y() - mStartPoint.y() ) );
467  double enlarge = computeMarkerMargin();
468  rect.adjust( -enlarge, -enlarge, enlarge, enlarge );
470 }
471 
473 {
474  mMarkerMode = mode;
475  adaptItemSceneRect();
476 }
477 
479 {
480  QDomElement composerArrowElem = doc.createElement( "ComposerArrow" );
481  composerArrowElem.setAttribute( "arrowHeadWidth", QString::number( mArrowHeadWidth ) );
482  composerArrowElem.setAttribute( "arrowHeadFillColor", QgsSymbolLayerV2Utils::encodeColor( mArrowHeadFillColor ) );
483  composerArrowElem.setAttribute( "arrowHeadOutlineColor", QgsSymbolLayerV2Utils::encodeColor( mArrowHeadOutlineColor ) );
484  composerArrowElem.setAttribute( "outlineWidth", QString::number( mArrowHeadOutlineWidth ) );
485  composerArrowElem.setAttribute( "markerMode", mMarkerMode );
486  composerArrowElem.setAttribute( "startMarkerFile", mStartMarkerFile );
487  composerArrowElem.setAttribute( "endMarkerFile", mEndMarkerFile );
488  composerArrowElem.setAttribute( "boundsBehaviourVersion", QString::number( mBoundsBehaviour ) );
489 
490  QDomElement styleElem = doc.createElement( "lineStyle" );
491  QDomElement lineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mLineSymbol, doc );
492  styleElem.appendChild( lineStyleElem );
493  composerArrowElem.appendChild( styleElem );
494 
495  //start point
496  QDomElement startPointElem = doc.createElement( "StartPoint" );
497  startPointElem.setAttribute( "x", QString::number( mStartPoint.x() ) );
498  startPointElem.setAttribute( "y", QString::number( mStartPoint.y() ) );
499  composerArrowElem.appendChild( startPointElem );
500 
501  //stop point
502  QDomElement stopPointElem = doc.createElement( "StopPoint" );
503  stopPointElem.setAttribute( "x", QString::number( mStopPoint.x() ) );
504  stopPointElem.setAttribute( "y", QString::number( mStopPoint.y() ) );
505  composerArrowElem.appendChild( stopPointElem );
506 
507  elem.appendChild( composerArrowElem );
508  return _writeXML( composerArrowElem, doc );
509 }
510 
511 bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument& doc )
512 {
513  mArrowHeadWidth = itemElem.attribute( "arrowHeadWidth", "2.0" ).toDouble();
514  mArrowHeadFillColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "arrowHeadFillColor", "0,0,0,255" ) );
515  mArrowHeadOutlineColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "arrowHeadOutlineColor", "0,0,0,255" ) );
516  mArrowHeadOutlineWidth = itemElem.attribute( "outlineWidth", "1.0" ).toDouble();
517  setStartMarker( itemElem.attribute( "startMarkerFile", "" ) );
518  setEndMarker( itemElem.attribute( "endMarkerFile", "" ) );
519  mMarkerMode = QgsComposerArrow::MarkerMode( itemElem.attribute( "markerMode", "0" ).toInt() );
520  //if bounds behaviour version is not set, default to 2.2 behaviour
521  mBoundsBehaviour = itemElem.attribute( "boundsBehaviourVersion", "22" ).toInt();
522 
523  //arrow style
524  QDomElement styleElem = itemElem.firstChildElement( "lineStyle" );
525  if ( !styleElem.isNull() )
526  {
527  QDomElement lineStyleElem = styleElem.firstChildElement( "symbol" );
528  if ( !lineStyleElem.isNull() )
529  {
530  delete mLineSymbol;
531  mLineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( lineStyleElem );
532  }
533  }
534  else
535  {
536  //old project file, read arrow width and color
537  delete mLineSymbol;
538 
539  QgsStringMap properties;
540  properties.insert( "width", itemElem.attribute( "outlineWidth", "1.0" ) );
541 
542  if ( mBoundsBehaviour == 22 )
543  {
544  //if arrow was created in versions prior to 2.4, use the old rendering style
545  properties.insert( "capstyle", "flat" );
546  }
547  else
548  {
549  properties.insert( "capstyle", "square" );
550  }
551  int red = 0;
552  int blue = 0;
553  int green = 0;
554  int alpha = 255;
555 
556  QDomNodeList arrowColorList = itemElem.elementsByTagName( "ArrowColor" );
557  if ( !arrowColorList.isEmpty() )
558  {
559  QDomElement arrowColorElem = arrowColorList.at( 0 ).toElement();
560  red = arrowColorElem.attribute( "red", "0" ).toInt();
561  green = arrowColorElem.attribute( "green", "0" ).toInt();
562  blue = arrowColorElem.attribute( "blue", "0" ).toInt();
563  alpha = arrowColorElem.attribute( "alpha", "255" ).toInt();
564  mArrowHeadFillColor = QColor( red, green, blue, alpha );
565  mArrowHeadOutlineColor = QColor( red, green, blue, alpha );
566  }
567  properties.insert( "color", QString( "%1,%2,%3,%4" ).arg( red ).arg( green ).arg( blue ).arg( alpha ) );
568  mLineSymbol = QgsLineSymbolV2::createSimple( properties );
569  }
570 
571  mPen.setColor( mArrowHeadOutlineColor );
572  mPen.setWidthF( mArrowHeadOutlineWidth );
573  mBrush.setColor( mArrowHeadFillColor );
574 
575  //restore general composer item properties
576  //needs to be before start point / stop point because setSceneRect()
577  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
578  if ( !composerItemList.isEmpty() )
579  {
580  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
581  _readXML( composerItemElem, doc );
582  }
583 
584  //start point
585  QDomNodeList startPointList = itemElem.elementsByTagName( "StartPoint" );
586  if ( !startPointList.isEmpty() )
587  {
588  QDomElement startPointElem = startPointList.at( 0 ).toElement();
589  mStartPoint.setX( startPointElem.attribute( "x", "0.0" ).toDouble() );
590  mStartPoint.setY( startPointElem.attribute( "y", "0.0" ).toDouble() );
591  }
592 
593  //stop point
594  QDomNodeList stopPointList = itemElem.elementsByTagName( "StopPoint" );
595  if ( !stopPointList.isEmpty() )
596  {
597  QDomElement stopPointElem = stopPointList.at( 0 ).toElement();
598  mStopPoint.setX( stopPointElem.attribute( "x", "0.0" ).toDouble() );
599  mStopPoint.setY( stopPointElem.attribute( "y", "0.0" ).toDouble() );
600  }
601 
602  mStartXIdx = mStopPoint.x() < mStartPoint.x();
603  mStartYIdx = mStopPoint.y() < mStartPoint.y();
604 
605  adaptItemSceneRect();
606  emit itemChanged();
607  return true;
608 }
609 
610 
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)
virtual int type() const override
Return composer item type.
QDomNode appendChild(const QDomNode &newChild)
void render(QPainter *painter)
qreal x() const
qreal y() const
QString attribute(const QString &name, const QString &defValue) const
static double angle(QPointF p1, QPointF p2)
Calculates the angle of the line from p1 to p2 (counter clockwise, starting from a line from north to...
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.
QRectF evalItemRect(const QRectF &newRect, const bool resizeOnly=false, const QgsExpressionContext *context=nullptr)
Evaluates an item&#39;s bounding rect to consider data defined position and size of item and reference po...
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 item&#39;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.
bool isEmpty() const
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=nullptr)
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
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.
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