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