QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 : marco@hugis.net
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();
59 }
60 
62 {
63  delete mLineSymbol;
64 }
65 
67 {
68  setArrowHeadWidth( 4 );
69  mPen.setColor( mArrowHeadOutlineColor );
70  mPen.setWidthF( 1 );
71  mBrush.setColor( mArrowHeadFillColor );
73 
74  //default to no background
75  setBackgroundEnabled( false );
76 }
77 
78 
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" );
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 
98  drawBackground( painter );
99 
100  painter->save();
101  //antialiasing on
102  painter->setRenderHint( QPainter::Antialiasing, true );
103 
104  //draw line section
105  drawLine( painter );
106 
107  //draw arrowhead if required
108  if ( mMarkerMode != NoMarker )
109  {
110  painter->setBrush( mBrush );
111  painter->setPen( mPen );
112 
113  if ( mMarkerMode == DefaultMarker )
114  {
115  drawHardcodedMarker( painter, EndMarker );
116  }
117  else if ( mMarkerMode == SVGMarker )
118  {
121  }
122  }
123 
124  painter->restore();
125 
126  drawFrame( painter );
127  if ( isSelected() )
128  {
129  drawSelectionBoxes( painter );
130  }
131 }
132 
133 void QgsComposerArrow::setSceneRect( const QRectF& rectangle )
134 {
135  //update rect for data defined size and position
136  QRectF evaluatedRect = evalItemRect( rectangle );
137 
138  if ( evaluatedRect.width() < 0 )
139  {
140  mStartXIdx = 1 - mStartXIdx;
141  }
142  if ( evaluatedRect.height() < 0 )
143  {
144  mStartYIdx = 1 - mStartYIdx;
145  }
146 
147  double margin = computeMarkerMargin();
148 
149  // Ensure the rectangle is at least as large as needed to include the markers
150  QRectF rect = rectangle.united( QRectF( evaluatedRect.x(), evaluatedRect.y(), 2. * margin, 2. * margin ) );
151 
152  // Compute new start and stop positions
153  double x[2] = {rect.x(), rect.x() + rect.width()};
154  double y[2] = {rect.y(), rect.y() + rect.height()};
155 
156  double xsign = x[mStartXIdx] < x[1 - mStartXIdx] ? 1.0 : -1.0;
157  double ysign = y[mStartYIdx] < y[1 - mStartYIdx] ? 1.0 : -1.0;
158 
159  mStartPoint = QPointF( x[mStartXIdx] + xsign * margin, y[mStartYIdx] + ysign * margin );
160  mStopPoint = QPointF( x[1 - mStartXIdx] - xsign * margin, y[1 - mStartYIdx] - ysign * margin );
161 
163 }
164 
165 void QgsComposerArrow::drawLine( QPainter *painter )
166 {
167  if ( ! mLineSymbol || ! mComposition )
168  {
169  return;
170  }
171 
172  QPaintDevice* thePaintDevice = painter->device();
173  painter->save();
174  //setup painter scaling to dots so that raster symbology is drawn to scale
175  double dotsPerMM = thePaintDevice->logicalDpiX() / 25.4;
176  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); //scale painter from mm to dots
177 
178  //setup render context
180  //context units should be in dots
181  ms.setOutputDpi( painter->device()->logicalDpiX() );
183  context.setForceVectorOutput( true );
184  context.setPainter( painter );
185 
186  //line scaled to dots
187  QPolygonF line;
188  line << QPointF( mStartPoint.x() - pos().x(), mStartPoint.y() - pos().y() ) * dotsPerMM
189  << QPointF( mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y() ) * dotsPerMM;
190 
191  mLineSymbol->startRender( context );
192  mLineSymbol->renderPolyline( line, 0, context );
193  mLineSymbol->stopRender( context );
194  painter->restore();
195 
196 }
197 
199 {
200  Q_UNUSED( type );
201  if ( mBoundsBehaviour == 22 )
202  {
203  //if arrow was created in versions prior to 2.4, use the old rendering style
205  }
206  else
207  {
208  QVector2D dir = QVector2D( mStopPoint - mStartPoint ).normalized();
209  QPointF stop = mStopPoint + ( dir * 0.5 * mArrowHeadWidth ).toPointF();
210  QgsComposerUtils::drawArrowHead( p, stop.x() - pos().x(), stop.y() - pos().y(), QgsComposerUtils::angle( mStartPoint, stop ), mArrowHeadWidth );
211  }
212 }
213 
214 void QgsComposerArrow::drawSVGMarker( QPainter* p, MarkerType type, const QString &markerPath )
215 {
216  Q_UNUSED( markerPath );
218 
219  double arrowHeadHeight;
220  if ( type == StartMarker )
221  {
222  arrowHeadHeight = mStartArrowHeadHeight;
223  }
224  else
225  {
226  arrowHeadHeight = mStopArrowHeadHeight;
227  }
228 
229  //prepare paint device
230  int dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
231  double viewScaleFactor = horizontalViewScaleFactor();
232  int imageWidth = mArrowHeadWidth / 25.4 * dpi;
233  int imageHeight = arrowHeadHeight / 25.4 * dpi;
234 
235  //make nicer preview
237  {
238  imageWidth *= qMin( viewScaleFactor, 10.0 );
239  imageHeight *= qMin( viewScaleFactor, 10.0 );
240  }
241  QImage markerImage( imageWidth, imageHeight, QImage::Format_ARGB32 );
242  QColor markerBG( 255, 255, 255, 0 ); //transparent white background
243  markerImage.fill( markerBG.rgba() );
244 
245  QPointF imageFixPoint;
246  imageFixPoint.setX( mArrowHeadWidth / 2.0 );
247  QPointF canvasPoint;
248  if ( type == StartMarker )
249  {
250  canvasPoint = QPointF( mStartPoint.x() - pos().x(), mStartPoint.y() - pos().y() );
251  imageFixPoint.setY( mStartArrowHeadHeight );
252  }
253  else //end marker
254  {
255  canvasPoint = QPointF( mStopPoint.x() - pos().x(), mStopPoint.y() - pos().y() );
256  imageFixPoint.setY( 0 );
257  }
258 
259  //rasterize svg
260  QSvgRenderer r;
261  if ( type == StartMarker )
262  {
263  if ( mStartMarkerFile.isEmpty() || !r.load( mStartMarkerFile ) )
264  {
265  return;
266  }
267  }
268  else //end marker
269  {
270  if ( mEndMarkerFile.isEmpty() || !r.load( mEndMarkerFile ) )
271  {
272  return;
273  }
274  }
275 
276  QPainter imagePainter( &markerImage );
277  r.render( &imagePainter );
278 
279  p->save();
280  if ( mBoundsBehaviour == 22 )
281  {
282  //if arrow was created in versions prior to 2.4, use the old rendering style
283  //rotate image fix point for backtransform
284  QPointF fixPoint;
285  if ( type == StartMarker )
286  {
287  fixPoint.setX( 0 ); fixPoint.setY( arrowHeadHeight / 2.0 );
288  }
289  else
290  {
291  fixPoint.setX( 0 ); fixPoint.setY( -arrowHeadHeight / 2.0 );
292  }
293  QPointF rotatedFixPoint;
294  double angleRad = ang / 180 * M_PI;
295  rotatedFixPoint.setX( fixPoint.x() * cos( angleRad ) + fixPoint.y() * -sin( angleRad ) );
296  rotatedFixPoint.setY( fixPoint.x() * sin( angleRad ) + fixPoint.y() * cos( angleRad ) );
297  p->translate( canvasPoint.x() - rotatedFixPoint.x() , canvasPoint.y() - rotatedFixPoint.y() );
298  }
299  else
300  {
301  p->translate( canvasPoint.x() , canvasPoint.y() );
302  }
303 
304  p->rotate( ang );
305  p->translate( -mArrowHeadWidth / 2.0, -arrowHeadHeight / 2.0 );
306 
307  p->drawImage( QRectF( 0, 0, mArrowHeadWidth, arrowHeadHeight ), markerImage, QRectF( 0, 0, imageWidth, imageHeight ) );
308  p->restore();
309 
310  return;
311 }
312 
313 void QgsComposerArrow::setStartMarker( const QString& svgPath )
314 {
315  QSvgRenderer r;
316  if ( svgPath.isEmpty() || !r.load( svgPath ) )
317  {
318  return;
319  // mStartArrowHeadHeight = 0;
320  }
321  mStartMarkerFile = svgPath;
322 
323  //calculate mArrowHeadHeight from svg file and mArrowHeadWidth
324  QRect viewBox = r.viewBox();
325  mStartArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
327 }
328 
329 void QgsComposerArrow::setEndMarker( const QString& svgPath )
330 {
331  QSvgRenderer r;
332  if ( svgPath.isEmpty() || !r.load( svgPath ) )
333  {
334  return;
335  // mStopArrowHeadHeight = 0;
336  }
337  mEndMarkerFile = svgPath;
338 
339  //calculate mArrowHeadHeight from svg file and mArrowHeadWidth
340  QRect viewBox = r.viewBox();
341  mStopArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
343 }
344 
346 {
347  if ( mLineSymbol )
348  {
349  return mLineSymbol->color();
350  }
351 
352  return Qt::black;
353 }
354 
355 void QgsComposerArrow::setArrowColor( const QColor &c )
356 {
357  if ( mLineSymbol )
358  {
359  mLineSymbol->setColor( c );
360  }
363  mPen.setColor( c );
364  mBrush.setColor( c );
365 }
366 
368 {
369  mArrowHeadOutlineColor = color;
370  mPen.setColor( color );
371 }
372 
373 void QgsComposerArrow::setArrowHeadFillColor( const QColor &color )
374 {
375  mArrowHeadFillColor = color;
376  mBrush.setColor( color );
377 }
378 
380 {
381  if ( mLineSymbol )
382  {
383  mLineSymbol->setWidth( width );
384  }
385  mArrowHeadOutlineWidth = width;
386  mPen.setWidthF( mArrowHeadOutlineWidth );
387 
389 }
390 
392 {
393  if ( mLineSymbol )
394  {
395  return mLineSymbol->width();
396  }
397 
398  return 0;
399 }
400 
402 {
403  mArrowHeadOutlineWidth = width;
404  mPen.setWidthF( mArrowHeadOutlineWidth );
405 
407 }
408 
410 {
411  delete mLineSymbol;
412  mLineSymbol = symbol;
413 }
414 
416 {
417  mArrowHeadWidth = width;
421 }
422 
424 {
425  double margin = 0;
426 
427  if ( mBoundsBehaviour == 22 )
428  {
429  //if arrow was created in versions prior to 2.4, use the old rendering style
430  if ( mMarkerMode == DefaultMarker )
431  {
432  margin = mPen.widthF() / 2.0 + mArrowHeadWidth / 2.0;
433  }
434  else if ( mMarkerMode == NoMarker )
435  {
436  margin = mPen.widthF() / 2.0;
437  }
438  else if ( mMarkerMode == SVGMarker )
439  {
440  double maxArrowHeight = qMax( mStartArrowHeadHeight, mStopArrowHeadHeight );
441  margin = mPen.widthF() / 2 + qMax( mArrowHeadWidth / 2.0, maxArrowHeight / 2.0 );
442  }
443  }
444  else
445  {
446  if ( mMarkerMode == DefaultMarker )
447  {
448  margin = mPen.widthF() / std::sqrt( 2.0 ) + mArrowHeadWidth / 2.0;
449  }
450  else if ( mMarkerMode == NoMarker )
451  {
452  margin = mPen.widthF() / std::sqrt( 2.0 );
453  }
454  else if ( mMarkerMode == SVGMarker )
455  {
456  double startMarkerMargin = std::sqrt( 0.25 * ( mStartArrowHeadHeight * mStartArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
457  double stopMarkerMargin = std::sqrt( 0.25 * ( mStopArrowHeadHeight * mStopArrowHeadHeight + mArrowHeadWidth * mArrowHeadWidth ) );
458  double markerMargin = qMax( startMarkerMargin, stopMarkerMargin );
459  margin = qMax( mPen.widthF() / std::sqrt( 2.0 ), markerMargin );
460  }
461  }
462  return margin;
463 }
464 
466 {
467  //rectangle containing start and end point
468  QRectF rect = QRectF( qMin( mStartPoint.x(), mStopPoint.x() ), qMin( mStartPoint.y(), mStopPoint.y() ),
469  qAbs( mStopPoint.x() - mStartPoint.x() ), qAbs( mStopPoint.y() - mStartPoint.y() ) );
470  double enlarge = computeMarkerMargin();
471  rect.adjust( -enlarge, -enlarge, enlarge, enlarge );
473 }
474 
476 {
477  mMarkerMode = mode;
479 }
480 
481 bool QgsComposerArrow::writeXML( QDomElement& elem, QDomDocument & doc ) const
482 {
483  QDomElement composerArrowElem = doc.createElement( "ComposerArrow" );
484  composerArrowElem.setAttribute( "arrowHeadWidth", QString::number( mArrowHeadWidth ) );
485  composerArrowElem.setAttribute( "arrowHeadFillColor", QgsSymbolLayerV2Utils::encodeColor( mArrowHeadFillColor ) );
486  composerArrowElem.setAttribute( "arrowHeadOutlineColor", QgsSymbolLayerV2Utils::encodeColor( mArrowHeadOutlineColor ) );
487  composerArrowElem.setAttribute( "outlineWidth", QString::number( mArrowHeadOutlineWidth ) );
488  composerArrowElem.setAttribute( "markerMode", mMarkerMode );
489  composerArrowElem.setAttribute( "startMarkerFile", mStartMarkerFile );
490  composerArrowElem.setAttribute( "endMarkerFile", mEndMarkerFile );
491  composerArrowElem.setAttribute( "boundsBehaviourVersion", QString::number( mBoundsBehaviour ) );
492 
493  QDomElement styleElem = doc.createElement( "lineStyle" );
494  QDomElement lineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mLineSymbol, doc );
495  styleElem.appendChild( lineStyleElem );
496  composerArrowElem.appendChild( styleElem );
497 
498  //start point
499  QDomElement startPointElem = doc.createElement( "StartPoint" );
500  startPointElem.setAttribute( "x", QString::number( mStartPoint.x() ) );
501  startPointElem.setAttribute( "y", QString::number( mStartPoint.y() ) );
502  composerArrowElem.appendChild( startPointElem );
503 
504  //stop point
505  QDomElement stopPointElem = doc.createElement( "StopPoint" );
506  stopPointElem.setAttribute( "x", QString::number( mStopPoint.x() ) );
507  stopPointElem.setAttribute( "y", QString::number( mStopPoint.y() ) );
508  composerArrowElem.appendChild( stopPointElem );
509 
510  elem.appendChild( composerArrowElem );
511  return _writeXML( composerArrowElem, doc );
512 }
513 
514 bool QgsComposerArrow::readXML( const QDomElement& itemElem, const QDomDocument& doc )
515 {
516  mArrowHeadWidth = itemElem.attribute( "arrowHeadWidth", "2.0" ).toDouble();
517  mArrowHeadFillColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "arrowHeadFillColor", "0,0,0,255" ) );
518  mArrowHeadOutlineColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "arrowHeadOutlineColor", "0,0,0,255" ) );
519  mArrowHeadOutlineWidth = itemElem.attribute( "outlineWidth", "1.0" ).toDouble();
520  setStartMarker( itemElem.attribute( "startMarkerFile", "" ) );
521  setEndMarker( itemElem.attribute( "endMarkerFile", "" ) );
522  mMarkerMode = QgsComposerArrow::MarkerMode( itemElem.attribute( "markerMode", "0" ).toInt() );
523  //if bounds behaviour version is not set, default to 2.2 behaviour
524  mBoundsBehaviour = itemElem.attribute( "boundsBehaviourVersion", "22" ).toInt();
525 
526  //arrow style
527  QDomElement styleElem = itemElem.firstChildElement( "lineStyle" );
528  if ( !styleElem.isNull() )
529  {
530  QDomElement lineStyleElem = styleElem.firstChildElement( "symbol" );
531  if ( !lineStyleElem.isNull( ) )
532  {
533  delete mLineSymbol;
534  mLineSymbol = dynamic_cast<QgsLineSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( lineStyleElem ) );
535  }
536  }
537  else
538  {
539  //old project file, read arrow width and color
540  delete mLineSymbol;
541 
542  QgsStringMap properties;
543  properties.insert( "width", itemElem.attribute( "outlineWidth", "1.0" ) );
544 
545  if ( mBoundsBehaviour == 22 )
546  {
547  //if arrow was created in versions prior to 2.4, use the old rendering style
548  properties.insert( "capstyle", "flat" );
549  }
550  else
551  {
552  properties.insert( "capstyle", "square" );
553  }
554  int red = 0;
555  int blue = 0;
556  int green = 0;
557  int alpha = 255;
558 
559  QDomNodeList arrowColorList = itemElem.elementsByTagName( "ArrowColor" );
560  if ( arrowColorList.size() > 0 )
561  {
562  QDomElement arrowColorElem = arrowColorList.at( 0 ).toElement();
563  red = arrowColorElem.attribute( "red", "0" ).toInt();
564  green = arrowColorElem.attribute( "green", "0" ).toInt();
565  blue = arrowColorElem.attribute( "blue", "0" ).toInt();
566  alpha = arrowColorElem.attribute( "alpha", "255" ).toInt();
567  mArrowHeadFillColor = QColor( red, green, blue, alpha );
568  mArrowHeadOutlineColor = QColor( red, green, blue, alpha );
569  }
570  properties.insert( "color", QString( "%1,%2,%3,%4" ).arg( red ).arg( green ).arg( blue ).arg( alpha ) );
572  }
573 
574  mPen.setColor( mArrowHeadOutlineColor );
575  mPen.setWidthF( mArrowHeadOutlineWidth );
576  mBrush.setColor( mArrowHeadFillColor );
577 
578  //restore general composer item properties
579  //needs to be before start point / stop point because setSceneRect()
580  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
581  if ( composerItemList.size() > 0 )
582  {
583  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
584  _readXML( composerItemElem, doc );
585  }
586 
587  //start point
588  QDomNodeList startPointList = itemElem.elementsByTagName( "StartPoint" );
589  if ( startPointList.size() > 0 )
590  {
591  QDomElement startPointElem = startPointList.at( 0 ).toElement();
592  mStartPoint.setX( startPointElem.attribute( "x", "0.0" ).toDouble() );
593  mStartPoint.setY( startPointElem.attribute( "y", "0.0" ).toDouble() );
594  }
595 
596  //stop point
597  QDomNodeList stopPointList = itemElem.elementsByTagName( "StopPoint" );
598  if ( stopPointList.size() > 0 )
599  {
600  QDomElement stopPointElem = stopPointList.at( 0 ).toElement();
601  mStopPoint.setX( stopPointElem.attribute( "x", "0.0" ).toDouble() );
602  mStopPoint.setY( stopPointElem.attribute( "y", "0.0" ).toDouble() );
603  }
604 
605  mStartXIdx = mStopPoint.x() < mStartPoint.x();
606  mStartYIdx = mStopPoint.y() < mStartPoint.y();
607 
609  emit itemChanged();
610  return true;
611 }
612 
613 
QgsComposerArrow(QgsComposition *c)
Constructor.
void setForceVectorOutput(bool force)
Added in QGIS v1.5.
int mStartXIdx
Considering the rectangle as spanning [x[0], x[1]] x [y[0], y[1]], these indices specify which index ...
Q_DECL_DEPRECATED void setOutlineWidth(double width)
Sets the pen width for drawing the line and arrow head.
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.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
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 QColor decodeColor(QString str)
virtual void drawFrame(QPainter *p)
Draw black frame around item.
QString mStartMarkerFile
Path to the start marker file.
void init()
Apply default graphics settings.
void setArrowHeadWidth(double width)
Sets the width of the arrow head in mm.
void adaptItemSceneRect()
Adapts the item scene rect to contain the start point, the stop point including the arrow marker and ...
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
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.
static QString encodeColor(QColor color)
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 QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
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.
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
Q_DECL_DEPRECATED QColor arrowColor() const
Returns the color for the line and arrow head.
MarkerMode mMarkerMode
Default marker, no marker or svg marker.
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
QgsLineSymbolV2 * mLineSymbol
double computeMarkerMargin() const
Computes the margin around the line necessary to include the markers.
void drawSVGMarker(QPainter *p, MarkerType type, const QString &markerPath)
Draws a user-defined marker (must be an svg file)
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
#define M_PI
void setPainter(QPainter *p)
void setArrowHeadOutlineColor(const QColor &color)
Sets the color used to draw the outline around the arrow head.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint - draw on canvas.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets state from DOM document.
void drawHardcodedMarker(QPainter *p, MarkerType type)
Draws the default marker at the line end.
void setLineSymbol(QgsLineSymbolV2 *symbol)
Sets the line symbol used for drawing the line portion of the arrow.
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 createDefaultLineSymbol()
Creates the default line symbol.
void setBackgroundEnabled(const bool drawBackground)
Set whether this item has a Background drawn around it or not.
int mBoundsBehaviour
Indicates QGIS version to mimic bounding box behaviour for.
void setArrowHeadFillColor(const QColor &color)
Sets the color used to fill the arrow head.
QRectF evalItemRect(const QRectF &newRect)
Update an item rect to consider data defined position and size of item.
Graphics scene for map printing.
void drawLine(QPainter *painter)
Draws the arrow line.
void setSceneRect(const QRectF &rectangle)
Modifies position of start and endpoint and calls QgsComposerItem::setSceneRect.
QgsComposition * mComposition
Contains information about the context of a rendering operation.
double mArrowHeadWidth
Width of the arrow marker in mm.
void stopRender(QgsRenderContext &context)
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
QString mEndMarkerFile
Path to the end marker file.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
virtual void drawBackground(QPainter *p)
Draw background.
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...
static QgsSymbolV2 * loadSymbol(QDomElement &element)
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...
QgsComposition::PlotStyle plotStyle() const
double mStartArrowHeadHeight
Height of the arrow marker in mm.
void setEndMarker(const QString &svgPath)
Sets the marker to draw at the end of the line.
bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores state in DOM element.
QColor color() const