QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposeritem.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposeritem.cpp
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : blazek@itc.it
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 #include <QWidget>
18 #include <QDomNode>
19 #include <QFile>
20 #include <QGraphicsLineItem>
21 #include <QGraphicsScene>
22 #include <QGraphicsSceneMouseEvent>
23 #include <QGraphicsView>
24 #include <QPainter>
25 #include <QUuid>
26 #include <QGraphicsEffect>
27 
28 #include "qgsproject.h"
29 
30 #include "qgscomposition.h"
31 #include "qgscomposeritem.h"
32 #include "qgscomposerframe.h"
33 #include "qgsdatadefined.h"
34 #include "qgscomposerutils.h"
35 
36 #include <limits>
37 #include "qgsapplication.h"
38 #include "qgsrectangle.h" //just for debugging
39 #include "qgslogger.h"
40 #include "qgssymbollayerv2utils.h" //for pointOnLineWithDistance
41 #include "qgsmaprenderer.h" //for getCompositionMode
42 
43 #include <cmath>
44 
45 #define FONT_WORKAROUND_SCALE 10 //scale factor for upscaling fontsize and downscaling painter
46 
47 #ifndef M_DEG2RAD
48 #define M_DEG2RAD 0.0174532925
49 #endif
50 
51 QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue )
52  : QgsComposerObject( composition )
53  , QGraphicsRectItem( 0 )
54  , mBoundingResizeRectangle( 0 )
55  , mHAlignSnapItem( 0 )
56  , mVAlignSnapItem( 0 )
57  , mFrame( false )
58  , mBackground( true )
59  , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
60  , mFrameJoinStyle( Qt::MiterJoin )
61  , mItemPositionLocked( false )
62  , mLastValidViewScaleFactor( -1 )
63  , mItemRotation( 0 )
64  , mEvaluatedItemRotation( 0 )
65  , mBlendMode( QPainter::CompositionMode_SourceOver )
66  , mEffectsEnabled( true )
67  , mTransparency( 0 )
68  , mLastUsedPositionMode( UpperLeft )
69  , mIsGroupMember( false )
70  , mCurrentExportLayer( -1 )
71  , mId( "" )
72  , mUuid( QUuid::createUuid().toString() )
73 {
74  init( manageZValue );
75 }
76 
77 QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue )
78  : QgsComposerObject( composition )
79  , QGraphicsRectItem( 0, 0, width, height, 0 )
80  , mBoundingResizeRectangle( 0 )
81  , mHAlignSnapItem( 0 )
82  , mVAlignSnapItem( 0 )
83  , mFrame( false )
84  , mBackground( true )
85  , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
86  , mFrameJoinStyle( Qt::MiterJoin )
87  , mItemPositionLocked( false )
88  , mLastValidViewScaleFactor( -1 )
89  , mItemRotation( 0 )
90  , mEvaluatedItemRotation( 0 )
91  , mBlendMode( QPainter::CompositionMode_SourceOver )
92  , mEffectsEnabled( true )
93  , mTransparency( 0 )
94  , mLastUsedPositionMode( UpperLeft )
95  , mIsGroupMember( false )
96  , mCurrentExportLayer( -1 )
97  , mId( "" )
98  , mUuid( QUuid::createUuid().toString() )
99 {
100  init( manageZValue );
101  setPos( x, y );
102 }
103 
104 void QgsComposerItem::init( const bool manageZValue )
105 {
106  setFlag( QGraphicsItem::ItemIsSelectable, true );
107  //set default pen and brush
108  setBrush( QBrush( QColor( 255, 255, 255, 255 ) ) );
109  QPen defaultPen( QColor( 0, 0, 0 ) );
110  defaultPen.setWidthF( 0.3 );
111  defaultPen.setJoinStyle( mFrameJoinStyle );
112  setPen( defaultPen );
113  //let z-Value be managed by composition
114  if ( mComposition && manageZValue )
115  {
116  mComposition->addItemToZList( this );
117  }
118 
119  // Setup composer effect
120  mEffect = new QgsComposerEffect();
121  setGraphicsEffect( mEffect );
122 
123  // data defined strings
124  mDataDefinedNames.insert( QgsComposerObject::PageNumber, QString( "dataDefinedPageNumber" ) );
125  mDataDefinedNames.insert( QgsComposerObject::PositionX, QString( "dataDefinedPositionX" ) );
126  mDataDefinedNames.insert( QgsComposerObject::PositionY, QString( "dataDefinedPositionY" ) );
127  mDataDefinedNames.insert( QgsComposerObject::ItemWidth, QString( "dataDefinedWidth" ) );
128  mDataDefinedNames.insert( QgsComposerObject::ItemHeight, QString( "dataDefinedHeight" ) );
129  mDataDefinedNames.insert( QgsComposerObject::ItemRotation, QString( "dataDefinedRotation" ) );
130  mDataDefinedNames.insert( QgsComposerObject::Transparency, QString( "dataDefinedTransparency" ) );
131  mDataDefinedNames.insert( QgsComposerObject::BlendMode, QString( "dataDefinedBlendMode" ) );
132 
133  if ( mComposition )
134  {
135  //connect to atlas toggling on/off and coverage layer and feature changes
136  //to update data defined values
137  connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( refreshDataDefinedProperty() ) );
138  connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( refreshDataDefinedProperty() ) );
139  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshDataDefinedProperty() ) );
140  //also, refreshing composition triggers a recalculation of data defined properties
141  connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshDataDefinedProperty() ) );
142 
143  //toggling atlas or changing coverage layer requires data defined expressions to be reprepared
144  connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( prepareDataDefinedExpressions() ) );
145  connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( prepareDataDefinedExpressions() ) );
146  }
147 }
148 
150 {
151  if ( mComposition )
152  {
154  }
155 
157  delete mEffect;
158 
160 }
161 
163 {
164  QgsDebugMsg( "entered." );
165  QGraphicsRectItem::setSelected( s );
166  update(); //to draw selection boxes
167 }
168 
169 bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) const
170 {
171  if ( itemElem.isNull() )
172  {
173  return false;
174  }
175 
176  QDomElement composerItemElem = doc.createElement( "ComposerItem" );
177 
178  //frame
179  if ( mFrame )
180  {
181  composerItemElem.setAttribute( "frame", "true" );
182  }
183  else
184  {
185  composerItemElem.setAttribute( "frame", "false" );
186  }
187 
188  //frame
189  if ( mBackground )
190  {
191  composerItemElem.setAttribute( "background", "true" );
192  }
193  else
194  {
195  composerItemElem.setAttribute( "background", "false" );
196  }
197 
198  //scene rect
199  QPointF pagepos = pagePos();
200  composerItemElem.setAttribute( "x", QString::number( pos().x() ) );
201  composerItemElem.setAttribute( "y", QString::number( pos().y() ) );
202  composerItemElem.setAttribute( "page", page() );
203  composerItemElem.setAttribute( "pagex", QString::number( pagepos.x() ) );
204  composerItemElem.setAttribute( "pagey", QString::number( pagepos.y() ) );
205  composerItemElem.setAttribute( "width", QString::number( rect().width() ) );
206  composerItemElem.setAttribute( "height", QString::number( rect().height() ) );
207  composerItemElem.setAttribute( "positionMode", QString::number(( int ) mLastUsedPositionMode ) );
208  composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
209  composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
210  composerItemElem.setAttribute( "frameJoinStyle", QgsSymbolLayerV2Utils::encodePenJoinStyle( mFrameJoinStyle ) );
211  composerItemElem.setAttribute( "itemRotation", QString::number( mItemRotation ) );
212  composerItemElem.setAttribute( "uuid", mUuid );
213  composerItemElem.setAttribute( "id", mId );
214  //position lock for mouse moves/resizes
215  if ( mItemPositionLocked )
216  {
217  composerItemElem.setAttribute( "positionLock", "true" );
218  }
219  else
220  {
221  composerItemElem.setAttribute( "positionLock", "false" );
222  }
223 
224  composerItemElem.setAttribute( "lastValidViewScaleFactor", QString::number( mLastValidViewScaleFactor ) );
225 
226 
227  //frame color
228  QDomElement frameColorElem = doc.createElement( "FrameColor" );
229  QColor frameColor = pen().color();
230  frameColorElem.setAttribute( "red", QString::number( frameColor.red() ) );
231  frameColorElem.setAttribute( "green", QString::number( frameColor.green() ) );
232  frameColorElem.setAttribute( "blue", QString::number( frameColor.blue() ) );
233  frameColorElem.setAttribute( "alpha", QString::number( frameColor.alpha() ) );
234  composerItemElem.appendChild( frameColorElem );
235 
236  //background color
237  QDomElement bgColorElem = doc.createElement( "BackgroundColor" );
238  QColor bgColor = brush().color();
239  bgColorElem.setAttribute( "red", QString::number( bgColor.red() ) );
240  bgColorElem.setAttribute( "green", QString::number( bgColor.green() ) );
241  bgColorElem.setAttribute( "blue", QString::number( bgColor.blue() ) );
242  bgColorElem.setAttribute( "alpha", QString::number( bgColor.alpha() ) );
243  composerItemElem.appendChild( bgColorElem );
244 
245  //blend mode
246  composerItemElem.setAttribute( "blendMode", QgsMapRenderer::getBlendModeEnum( mBlendMode ) );
247 
248  //transparency
249  composerItemElem.setAttribute( "transparency", QString::number( mTransparency ) );
250 
251  QgsComposerObject::writeXML( composerItemElem, doc );
252  itemElem.appendChild( composerItemElem );
253 
254  return true;
255 }
256 
257 bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& doc )
258 {
259  Q_UNUSED( doc );
260  if ( itemElem.isNull() )
261  {
262  return false;
263  }
264 
265  QgsComposerObject::readXML( itemElem, doc );
266 
267  //rotation
268  setItemRotation( itemElem.attribute( "itemRotation", "0" ).toDouble() );
269 
270  //uuid
271  mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() );
272 
273  // temporary for groups imported from templates
274  mTemplateUuid = itemElem.attribute( "templateUuid" );
275 
276  //id
277  QString id = itemElem.attribute( "id", "" );
278  setId( id );
279 
280  //frame
281  QString frame = itemElem.attribute( "frame" );
282  if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 )
283  {
284  mFrame = true;
285  }
286  else
287  {
288  mFrame = false;
289  }
290 
291  //frame
292  QString background = itemElem.attribute( "background" );
293  if ( background.compare( "true", Qt::CaseInsensitive ) == 0 )
294  {
295  mBackground = true;
296  }
297  else
298  {
299  mBackground = false;
300  }
301 
302  //position lock for mouse moves/resizes
303  QString positionLock = itemElem.attribute( "positionLock" );
304  if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 )
305  {
306  setPositionLock( true );
307  }
308  else
309  {
310  setPositionLock( false );
311  }
312 
313  //position
314  int page;
315  double x, y, pagex, pagey, width, height;
316  bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK;
317 
318  x = itemElem.attribute( "x" ).toDouble( &xOk );
319  y = itemElem.attribute( "y" ).toDouble( &yOk );
320  page = itemElem.attribute( "page" ).toInt( &pageOk );
321  pagex = itemElem.attribute( "pagex" ).toDouble( &pagexOk );
322  pagey = itemElem.attribute( "pagey" ).toDouble( &pageyOk );
323  width = itemElem.attribute( "width" ).toDouble( &widthOk );
324  height = itemElem.attribute( "height" ).toDouble( &heightOk );
325  mLastUsedPositionMode = ( ItemPositionMode )itemElem.attribute( "positionMode" ).toInt( &positionModeOK );
326  if ( !positionModeOK )
327  {
329  }
330  if ( pageOk && pagexOk && pageyOk )
331  {
332  xOk = true;
333  yOk = true;
334  x = pagex;
335  y = ( page - 1 ) * ( mComposition->paperHeight() + composition()->spaceBetweenPages() ) + pagey;
336  }
337 
338  if ( !xOk || !yOk || !widthOk || !heightOk )
339  {
340  return false;
341  }
342 
343  mLastValidViewScaleFactor = itemElem.attribute( "lastValidViewScaleFactor", "-1" ).toDouble();
344 
345  setZValue( itemElem.attribute( "zValue" ).toDouble() );
346 
347  //pen
348  QDomNodeList frameColorList = itemElem.elementsByTagName( "FrameColor" );
349  if ( frameColorList.size() > 0 )
350  {
351  QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
352  bool redOk, greenOk, blueOk, alphaOk, widthOk;
353  int penRed, penGreen, penBlue, penAlpha;
354  double penWidth;
355 
356  penWidth = itemElem.attribute( "outlineWidth" ).toDouble( &widthOk );
357  penRed = frameColorElem.attribute( "red" ).toDouble( &redOk );
358  penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk );
359  penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk );
360  penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk );
361  mFrameJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "frameJoinStyle", "miter" ) );
362 
363  if ( redOk && greenOk && blueOk && alphaOk && widthOk )
364  {
365  QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) );
366  framePen.setWidthF( penWidth );
367  framePen.setJoinStyle( mFrameJoinStyle );
368  setPen( framePen );
369  }
370  }
371 
372  //brush
373  QDomNodeList bgColorList = itemElem.elementsByTagName( "BackgroundColor" );
374  if ( bgColorList.size() > 0 )
375  {
376  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
377  bool redOk, greenOk, blueOk, alphaOk;
378  int bgRed, bgGreen, bgBlue, bgAlpha;
379  bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk );
380  bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk );
381  bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk );
382  bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk );
383  if ( redOk && greenOk && blueOk && alphaOk )
384  {
385  QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha );
386  setBackgroundColor( brushColor );
387  }
388  }
389 
390  //blend mode
391  setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "blendMode", "0" ).toUInt() ) );
392 
393  //transparency
394  setTransparency( itemElem.attribute( "transparency" , "0" ).toInt() );
395 
396  QRectF evaluatedRect = evalItemRect( QRectF( x, y, width, height ) );
397  setSceneRect( evaluatedRect );
398 
399  return true;
400 }
401 
402 void QgsComposerItem::setFrameEnabled( const bool drawFrame )
403 {
404  if ( drawFrame == mFrame )
405  {
406  //no change
407  return;
408  }
409 
410  mFrame = drawFrame;
411  emit frameChanged();
412 }
413 
415 {
416  QPen itemPen = pen();
417  if ( itemPen.widthF() == outlineWidth )
418  {
419  //no change
420  return;
421  }
422  itemPen.setWidthF( outlineWidth );
423  setPen( itemPen );
424  emit frameChanged();
425 }
426 
427 void QgsComposerItem::setFrameJoinStyle( const Qt::PenJoinStyle style )
428 {
429  if ( mFrameJoinStyle == style )
430  {
431  //no change
432  return;
433  }
434  mFrameJoinStyle = style;
435 
436  QPen itemPen = pen();
437  itemPen.setJoinStyle( mFrameJoinStyle );
438  setPen( itemPen );
439  emit frameChanged();
440 }
441 
443 {
444  if ( !hasFrame() )
445  {
446  return 0;
447  }
448 
449  return pen().widthF() / 2.0;
450 }
451 
453 {
454  double frameBleed = estimatedFrameBleed();
455  return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
456 }
457 
459 {
460  if ( mComposition )
461  {
462  mComposition->beginCommand( this, commandText, c );
463  }
464 }
465 
467 {
468  if ( mComposition )
469  {
471  }
472 }
473 
475 {
476  if ( mComposition )
477  {
479  }
480 }
481 
483 {
484 
485  if ( !mComposition )
486  {
487  return;
488  }
489 
491  {
492  double sizeLockSymbol = lockSymbolSize();
493 
494  if ( mItemPositionLocked )
495  {
496  //draw lock symbol at upper left edge. Use QImage to be independent of the graphic system
497  QString lockIconPath = QgsApplication::activeThemePath() + "/mIconLock.png";
498  if ( !QFile::exists( lockIconPath ) )
499  {
500  lockIconPath = QgsApplication::defaultThemePath() + "/mIconLock.png";
501  }
502 
503  QImage lockImage( lockIconPath );
504  if ( !lockImage.isNull() )
505  {
506  p->drawImage( QRectF( 0, 0, sizeLockSymbol, sizeLockSymbol ), lockImage, QRectF( 0, 0, lockImage.width(), lockImage.height() ) );
507  }
508  }
509  }
510 }
511 
512 void QgsComposerItem::drawFrame( QPainter* p )
513 {
514  if ( mFrame && p )
515  {
516  p->save();
517  p->setPen( pen() );
518  p->setBrush( Qt::NoBrush );
519  p->setRenderHint( QPainter::Antialiasing, true );
520  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
521  p->restore();
522  }
523 }
524 
525 void QgsComposerItem::setPositionLock( const bool lock )
526 {
527  mItemPositionLocked = lock;
528 }
529 
530 double QgsComposerItem::itemRotation( const PropertyValueType valueType ) const
531 {
533 }
534 
535 void QgsComposerItem::move( double dx, double dy )
536 {
537  QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
538  setSceneRect( evalItemRect( newSceneRect ) );
539 }
540 
542 {
543  double y = pos().y();
544  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
545  int page = 1;
546  while ( y - h >= 0. )
547  {
548  y -= h;
549  ++page;
550  }
551  return page;
552 }
553 
555 {
556  QPointF p = pos();
557  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
558  p.ry() -= ( page() - 1 ) * h;
559  return p;
560 }
561 
562 void QgsComposerItem::updatePagePos( double newPageWidth, double newPageHeight )
563 {
564  Q_UNUSED( newPageWidth )
565  QPointF curPagePos = pagePos();
566  int curPage = page() - 1;
567 
568  double y = curPage * ( newPageHeight + composition()->spaceBetweenPages() ) + curPagePos.y();
569  QRectF newSceneRect( pos().x(), y, rect().width(), rect().height() );
570 
571  setSceneRect( evalItemRect( newSceneRect ) );
572  emit sizeChanged();
573 }
574 
575 void QgsComposerItem::setItemPosition( double x, double y, ItemPositionMode itemPoint, int page )
576 {
577  double width = rect().width();
578  double height = rect().height();
579  setItemPosition( x, y, width, height, itemPoint, false, page );
580 }
581 
582 void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint, bool posIncludesFrame, int page )
583 {
584  double upperLeftX = x;
585  double upperLeftY = y;
586 
587  if ( page > 0 )
588  {
589  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
590  upperLeftY += ( page - 1 ) * h;
591  }
592 
593  //store the item position mode
594  mLastUsedPositionMode = itemPoint;
595 
596  //adjust x-coordinate if placement is not done to a left point
597  if ( itemPoint == UpperMiddle || itemPoint == Middle || itemPoint == LowerMiddle )
598  {
599  upperLeftX -= width / 2.0;
600  }
601  else if ( itemPoint == UpperRight || itemPoint == MiddleRight || itemPoint == LowerRight )
602  {
603  upperLeftX -= width;
604  }
605 
606  //adjust y-coordinate if placement is not done to an upper point
607  if ( itemPoint == MiddleLeft || itemPoint == Middle || itemPoint == MiddleRight )
608  {
609  upperLeftY -= height / 2.0;
610  }
611  else if ( itemPoint == LowerLeft || itemPoint == LowerMiddle || itemPoint == LowerRight )
612  {
613  upperLeftY -= height;
614  }
615 
616  if ( posIncludesFrame )
617  {
618  //adjust position to account for frame size
619 
620  if ( mEvaluatedItemRotation == 0 )
621  {
622  upperLeftX += estimatedFrameBleed();
623  upperLeftY += estimatedFrameBleed();
624  }
625  else
626  {
627  //adjust position for item rotation
628  QLineF lineToItemOrigin = QLineF( 0, 0, estimatedFrameBleed(), estimatedFrameBleed() );
629  lineToItemOrigin.setAngle( -45 - mEvaluatedItemRotation );
630  upperLeftX += lineToItemOrigin.x2();
631  upperLeftY += lineToItemOrigin.y2();
632  }
633 
634  width -= 2 * estimatedFrameBleed();
635  height -= 2 * estimatedFrameBleed();
636  }
637 
638  //consider data defined item size and position before finalising rect
639  QRectF newRect = evalItemRect( QRectF( upperLeftX, upperLeftY, width, height ) );
640 
641  setSceneRect( newRect );
642 }
643 
644 void QgsComposerItem::setSceneRect( const QRectF& rectangle )
645 {
646  //setRect in item coordinates
647  double newWidth = rectangle.width();
648  double newHeight = rectangle.height();
649  double xTranslation = rectangle.x();
650  double yTranslation = rectangle.y();
651 
652  //correction if width and/or height are negative
653  if ( rectangle.width() < 0 )
654  {
655  newWidth = - rectangle.width();
656  xTranslation -= newWidth;
657  }
658 
659  if ( rectangle.height() < 0 )
660  {
661  newHeight = - rectangle.height();
662  yTranslation -= newHeight;
663  }
664 
665  QGraphicsRectItem::setRect( QRectF( 0, 0, newWidth, newHeight ) );
666  setPos( QPointF( xTranslation, yTranslation ) );
667 
668  emit sizeChanged();
669 }
670 
671 QRectF QgsComposerItem::evalItemRect( const QRectF &newRect )
672 {
673  QRectF result = newRect;
674 
675  //data defined position or size set? if so, update rect with data defined values
676  QVariant exprVal;
677  //evaulate width and height first, since they may affect position if non-top-left reference point set
679  {
680  bool ok;
681  double width = exprVal.toDouble( &ok );
682  QgsDebugMsg( QString( "exprVal Width:%1" ).arg( width ) );
683  if ( ok )
684  {
685  result.setWidth( width );
686  }
687  }
689  {
690  bool ok;
691  double height = exprVal.toDouble( &ok );
692  QgsDebugMsg( QString( "exprVal Height:%1" ).arg( height ) );
693  if ( ok )
694  {
695  result.setHeight( height );
696  }
697  }
698 
699  double x = result.left();
700  //initially adjust for position mode to get top-left coordinate
702  {
703  x += newRect.width() / 2.0;
704  }
706  {
707  x += newRect.width();
708  }
710  {
711  bool ok;
712  double positionX = exprVal.toDouble( &ok );
713  QgsDebugMsg( QString( "exprVal Position X:%1" ).arg( positionX ) );
714  if ( ok )
715  {
716  x = positionX;
717  }
718  }
719 
720  double y = result.top();
721  //adjust y-coordinate if placement is not done to an upper point
723  {
724  y += newRect.height() / 2.0;
725  }
727  {
728  y += newRect.height();
729  }
730 
732  {
733  bool ok;
734  double positionY = exprVal.toDouble( &ok );
735  QgsDebugMsg( QString( "exprVal Position Y:%1" ).arg( positionY ) );
736  if ( ok )
737  {
738  y = positionY;
739  }
740  }
741 
742  //adjust x-coordinate if placement is not done to a left point
744  {
745  x -= result.width() / 2.0;
746  }
748  {
749  x -= result.width();
750  }
751 
752  //adjust y-coordinate if placement is not done to an upper point
754  {
755  y -= result.height() / 2.0;
756  }
758  {
759  y -= result.height();
760  }
761 
762  result.moveLeft( x );
763  result.moveTop( y );
764 
765  return result;
766 }
767 
769 {
770  if ( mBackground && p )
771  {
772  p->save();
773  p->setBrush( brush() );//this causes a problem in atlas generation
774  p->setPen( Qt::NoPen );
775  p->setRenderHint( QPainter::Antialiasing, true );
776  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
777  p->restore();
778  }
779 }
780 
781 void QgsComposerItem::drawArrowHead( QPainter *p, double x, double y, double angle, double arrowHeadWidth ) const
782 {
783  QgsComposerUtils::drawArrowHead( p, x, y, angle, arrowHeadWidth );
784 }
785 
786 double QgsComposerItem::angle( const QPointF &p1, const QPointF &p2 ) const
787 {
788  return QgsComposerUtils::angle( p1, p2 );
789 }
790 
791 void QgsComposerItem::setBackgroundColor( const QColor& backgroundColor )
792 {
794  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
795 }
796 
797 void QgsComposerItem::setBlendMode( const QPainter::CompositionMode blendMode )
798 {
800  // Update the composer effect to use the new blend mode
802 }
803 
805 {
806  QPainter::CompositionMode blendMode = mBlendMode;
807 
808  //data defined blend mode set?
809  QVariant exprVal;
811  {
812  QString blendstr = exprVal.toString().trimmed();
813  QPainter::CompositionMode blendModeD = QgsSymbolLayerV2Utils::decodeBlendMode( blendstr );
814 
815  QgsDebugMsg( QString( "exprVal BlendMode:%1" ).arg( blendModeD ) );
816  blendMode = blendModeD;
817  }
818 
819  // Update the composer effect to use the new blend mode
820  mEffect->setCompositionMode( blendMode );
821 }
822 
823 void QgsComposerItem::setTransparency( const int transparency )
824 {
826  refreshTransparency( true );
827 }
828 
829 void QgsComposerItem::refreshTransparency( const bool updateItem )
830 {
832 
833  //data defined transparency set?
834  QVariant exprVal;
836  {
837  bool ok;
838  int transparencyD = exprVal.toInt( &ok );
839  QgsDebugMsg( QString( "exprVal Transparency:%1" ).arg( transparencyD ) );
840  if ( ok )
841  {
842  transparency = transparencyD;
843  }
844  }
845 
846  // Set the QGraphicItem's opacity
847  setOpacity( 1. - ( transparency / 100. ) );
848 
849  if ( updateItem )
850  {
851  update();
852  }
853 }
854 
855 void QgsComposerItem::setEffectsEnabled( const bool effectsEnabled )
856 {
857  //enable or disable the QgsComposerEffect applied to this item
859  mEffect->setEnabled( effectsEnabled );
860 }
861 
862 void QgsComposerItem::drawText( QPainter* p, double x, double y, const QString& text, const QFont& font, const QColor& c ) const
863 {
864  QgsComposerUtils::drawText( p, QPointF( x, y ), text, font, c );
865 }
866 
867 void QgsComposerItem::drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment, Qt::AlignmentFlag valignment, int flags ) const
868 {
869  QgsComposerUtils::drawText( p, rect, text, font, QColor(), halignment, valignment, flags );
870 }
871 double QgsComposerItem::textWidthMillimeters( const QFont& font, const QString& text ) const
872 {
873  return QgsComposerUtils::textWidthMM( font, text );
874 }
875 
876 double QgsComposerItem::fontHeightCharacterMM( const QFont& font, const QChar& c ) const
877 {
878  return QgsComposerUtils::fontHeightCharacterMM( font, c );
879 }
880 
881 double QgsComposerItem::fontAscentMillimeters( const QFont& font ) const
882 {
883  return QgsComposerUtils::fontAscentMM( font );
884 }
885 
886 double QgsComposerItem::fontDescentMillimeters( const QFont& font ) const
887 {
888  return QgsComposerUtils::fontDescentMM( font );
889 }
890 
891 double QgsComposerItem::fontHeightMillimeters( const QFont& font ) const
892 {
893  return QgsComposerUtils::fontHeightMM( font );
894 }
895 
896 double QgsComposerItem::pixelFontSize( double pointSize ) const
897 {
898  return QgsComposerUtils::pointsToMM( pointSize );
899 }
900 
901 QFont QgsComposerItem::scaledFontPixelSize( const QFont& font ) const
902 {
904 }
905 
907 {
908  double result = -1;
909  if ( scene() )
910  {
911  QList<QGraphicsView*> viewList = scene()->views();
912  if ( viewList.size() > 0 ) //if not, probably this function was called from non-gui code
913  {
914  QGraphicsView* currentView = viewList.at( 0 );
915  if ( currentView->isVisible() )
916  {
917  result = currentView->transform().m11();
918  mLastValidViewScaleFactor = result;
919  }
920  }
921  }
922  return result;
923 }
924 
926 {
927  //size of symbol boxes depends on zoom level in composer view
928  double viewScaleFactor = horizontalViewScaleFactor();
929  double rectHandlerSize = 10.0 / viewScaleFactor;
930 
931  //make sure the boxes don't get too large
932  if ( rectHandlerSize > ( rect().width() / 3 ) )
933  {
934  rectHandlerSize = rect().width() / 3;
935  }
936  if ( rectHandlerSize > ( rect().height() / 3 ) )
937  {
938  rectHandlerSize = rect().height() / 3;
939  }
940  return rectHandlerSize;
941 }
942 
944 {
945  double lockSymbolSize = 20.0 / horizontalViewScaleFactor();
946 
947  if ( lockSymbolSize > ( rect().width() / 3 ) )
948  {
949  lockSymbolSize = rect().width() / 3;
950  }
951  if ( lockSymbolSize > ( rect().height() / 3 ) )
952  {
953  lockSymbolSize = rect().height() / 3;
954  }
955  return lockSymbolSize;
956 }
957 
958 void QgsComposerItem::setRotation( const double r )
959 {
960  //kept for api compatibility with QGIS 2.0
961  //remove after 2.0 series
962  setItemRotation( r, true );
963 }
964 
965 void QgsComposerItem::setItemRotation( const double r, const bool adjustPosition )
966 {
967  if ( r >= 360 )
968  {
969  mItemRotation = (( int )r ) % 360;
970  }
971  else
972  {
973  mItemRotation = r;
974  }
975 
976  refreshRotation( true, adjustPosition );
977 }
978 
979 void QgsComposerItem::refreshRotation( const bool updateItem , const bool adjustPosition )
980 {
981  double rotation = mItemRotation;
982 
983  //data defined rotation set?
984  QVariant exprVal;
986  {
987  bool ok;
988  double rotD = exprVal.toDouble( &ok );
989  QgsDebugMsg( QString( "exprVal Rotation:%1" ).arg( rotD ) );
990  if ( ok )
991  {
992  rotation = rotD;
993  }
994  }
995 
996  if ( adjustPosition )
997  {
998  //adjustPosition set, so shift the position of the item so that rotation occurs around item center
999  //create a line from the centrepoint of the rect() to its origin, in scene coordinates
1000  QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ) , mapToScene( QPointF( 0 , 0 ) ) );
1001  //rotate this line by the current rotation angle
1002  refLine.setAngle( refLine.angle() - rotation + mEvaluatedItemRotation );
1003  //get new end point of line - this is the new item position
1004  QPointF rotatedReferencePoint = refLine.p2();
1005  setPos( rotatedReferencePoint );
1006  emit sizeChanged();
1007  }
1008 
1009  setTransformOriginPoint( 0, 0 );
1010  QGraphicsItem::setRotation( rotation );
1011 
1013 
1014  emit itemRotationChanged( rotation );
1015 
1016  //update bounds of scene, since rotation may affect this
1018 
1019  if ( updateItem )
1020  {
1021  update();
1022  }
1023 }
1024 
1025 bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& height ) const
1026 {
1027  //kept for api compatibility with QGIS 2.0, use item rotation
1029  return imageSizeConsideringRotation( width, height, mEvaluatedItemRotation );
1031 }
1032 
1033 bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& height, double rotation ) const
1034 {
1035  if ( qAbs( rotation ) <= 0.0 ) //width and height stays the same if there is no rotation
1036  {
1037  return true;
1038  }
1039 
1040  if ( qgsDoubleNear( qAbs( rotation ), 90 ) || qgsDoubleNear( qAbs( rotation ), 270 ) )
1041  {
1042  double tmp = width;
1043  width = height;
1044  height = tmp;
1045  return true;
1046  }
1047 
1048  double x1 = 0;
1049  double y1 = 0;
1050  double x2 = width;
1051  double y2 = 0;
1052  double x3 = width;
1053  double y3 = height;
1054  double x4 = 0;
1055  double y4 = height;
1056  double midX = width / 2.0;
1057  double midY = height / 2.0;
1058 
1060  if ( !cornerPointOnRotatedAndScaledRect( x1, y1, width, height, rotation ) )
1061  {
1062  return false;
1063  }
1064  if ( !cornerPointOnRotatedAndScaledRect( x2, y2, width, height, rotation ) )
1065  {
1066  return false;
1067  }
1068  if ( !cornerPointOnRotatedAndScaledRect( x3, y3, width, height, rotation ) )
1069  {
1070  return false;
1071  }
1072  if ( !cornerPointOnRotatedAndScaledRect( x4, y4, width, height, rotation ) )
1073  {
1074  return false;
1075  }
1077 
1078 
1079  //assume points 1 and 3 are on the rectangle boundaries. Calculate 2 and 4.
1080  double distM1 = sqrt(( x1 - midX ) * ( x1 - midX ) + ( y1 - midY ) * ( y1 - midY ) );
1081  QPointF p2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( QPointF( midX, midY ), QPointF( x2, y2 ), distM1 );
1082 
1083  if ( p2.x() < width && p2.x() > 0 && p2.y() < height && p2.y() > 0 )
1084  {
1085  width = sqrt(( p2.x() - x1 ) * ( p2.x() - x1 ) + ( p2.y() - y1 ) * ( p2.y() - y1 ) );
1086  height = sqrt(( x3 - p2.x() ) * ( x3 - p2.x() ) + ( y3 - p2.y() ) * ( y3 - p2.y() ) );
1087  return true;
1088  }
1089 
1090  //else assume that points 2 and 4 are on the rectangle boundaries. Calculate 1 and 3
1091  double distM2 = sqrt(( x2 - midX ) * ( x2 - midX ) + ( y2 - midY ) * ( y2 - midY ) );
1092  QPointF p1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( QPointF( midX, midY ), QPointF( x1, y1 ), distM2 );
1093  QPointF p3 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( QPointF( midX, midY ), QPointF( x3, y3 ), distM2 );
1094  width = sqrt(( x2 - p1.x() ) * ( x2 - p1.x() ) + ( y2 - p1.y() ) * ( y2 - p1.y() ) );
1095  height = sqrt(( p3.x() - x2 ) * ( p3.x() - x2 ) + ( p3.y() - y2 ) * ( p3.y() - y2 ) );
1096  return true;
1097 }
1098 
1099 QRectF QgsComposerItem::largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const
1100 {
1101  return QgsComposerUtils::largestRotatedRectWithinBounds( originalRect, boundsRect, rotation );
1102 }
1103 
1104 bool QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const
1105 {
1106  //kept for api compatibility with QGIS 2.0, use item rotation
1108  return cornerPointOnRotatedAndScaledRect( x, y, width, height, mEvaluatedItemRotation );
1110 }
1111 
1112 bool QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const
1113 {
1114  //first rotate point clockwise
1115  double rotToRad = rotation * M_PI / 180.0;
1116  QPointF midpoint( width / 2.0, height / 2.0 );
1117  double xVector = x - midpoint.x();
1118  double yVector = y - midpoint.y();
1119  //double xRotated = cos(rotToRad) * xVector + sin(rotToRad) * yVector;
1120  //double yRotated = -sin(rotToRad) * xVector + cos(rotToRad) * yVector;
1121  double xRotated = cos( rotToRad ) * xVector - sin( rotToRad ) * yVector;
1122  double yRotated = sin( rotToRad ) * xVector + cos( rotToRad ) * yVector;
1123 
1124  //create line from midpoint to rotated point
1125  QLineF line( midpoint.x(), midpoint.y(), midpoint.x() + xRotated, midpoint.y() + yRotated );
1126 
1127  //intersect with all four borders and return result
1128  QList<QLineF> borders;
1129  borders << QLineF( 0, 0, width, 0 );
1130  borders << QLineF( width, 0, width, height );
1131  borders << QLineF( width, height, 0, height );
1132  borders << QLineF( 0, height, 0, 0 );
1133 
1134  QList<QLineF>::const_iterator it = borders.constBegin();
1135  QPointF intersectionPoint;
1136 
1137  for ( ; it != borders.constEnd(); ++it )
1138  {
1139  if ( line.intersect( *it, &intersectionPoint ) == QLineF::BoundedIntersection )
1140  {
1141  x = intersectionPoint.x();
1142  y = intersectionPoint.y();
1143  return true;
1144  }
1145  }
1146  return false;
1147 }
1148 
1149 void QgsComposerItem::sizeChangedByRotation( double& width, double& height )
1150 {
1151  //kept for api compatibility with QGIS 2.0, use item rotation
1153  return sizeChangedByRotation( width, height, mEvaluatedItemRotation );
1155 }
1156 
1157 void QgsComposerItem::sizeChangedByRotation( double& width, double& height, double rotation )
1158 {
1159  if ( rotation == 0.0 )
1160  {
1161  return;
1162  }
1163 
1164  //vector to p1
1165  double x1 = -width / 2.0;
1166  double y1 = -height / 2.0;
1167  QgsComposerUtils::rotate( rotation, x1, y1 );
1168  //vector to p2
1169  double x2 = width / 2.0;
1170  double y2 = -height / 2.0;
1171  QgsComposerUtils::rotate( rotation, x2, y2 );
1172  //vector to p3
1173  double x3 = width / 2.0;
1174  double y3 = height / 2.0;
1175  QgsComposerUtils::rotate( rotation, x3, y3 );
1176  //vector to p4
1177  double x4 = -width / 2.0;
1178  double y4 = height / 2.0;
1179  QgsComposerUtils::rotate( rotation, x4, y4 );
1180 
1181  //double midpoint
1182  QPointF midpoint( width / 2.0, height / 2.0 );
1183 
1184  QPolygonF rotatedRectPoly;
1185  rotatedRectPoly << QPointF( midpoint.x() + x1, midpoint.y() + y1 );
1186  rotatedRectPoly << QPointF( midpoint.x() + x2, midpoint.y() + y2 );
1187  rotatedRectPoly << QPointF( midpoint.x() + x3, midpoint.y() + y3 );
1188  rotatedRectPoly << QPointF( midpoint.x() + x4, midpoint.y() + y4 );
1189  QRectF boundingRect = rotatedRectPoly.boundingRect();
1190  width = boundingRect.width();
1191  height = boundingRect.height();
1192 }
1193 
1194 void QgsComposerItem::rotate( double angle, double& x, double& y ) const
1195 {
1196  QgsComposerUtils::rotate( angle, x, y );
1197 }
1198 
1200 {
1201  if ( !mHAlignSnapItem )
1202  {
1203  mHAlignSnapItem = new QGraphicsLineItem( 0 );
1204  mHAlignSnapItem->setPen( QPen( QColor( Qt::red ) ) );
1205  scene()->addItem( mHAlignSnapItem );
1206  mHAlignSnapItem->setZValue( 90 );
1207  }
1208  return mHAlignSnapItem;
1209 }
1210 
1212 {
1213  if ( !mVAlignSnapItem )
1214  {
1215  mVAlignSnapItem = new QGraphicsLineItem( 0 );
1216  mVAlignSnapItem->setPen( QPen( QColor( Qt::red ) ) );
1217  scene()->addItem( mVAlignSnapItem );
1218  mVAlignSnapItem->setZValue( 90 );
1219  }
1220  return mVAlignSnapItem;
1221 }
1222 
1224 {
1225  if ( mHAlignSnapItem )
1226  {
1227  scene()->removeItem( mHAlignSnapItem );
1228  delete mHAlignSnapItem;
1229  mHAlignSnapItem = 0;
1230  }
1231 }
1232 
1234 {
1235  if ( mVAlignSnapItem )
1236  {
1237  scene()->removeItem( mVAlignSnapItem );
1238  delete mVAlignSnapItem;
1239  mVAlignSnapItem = 0;
1240  }
1241 }
1242 
1244 {
1247 }
1248 
1250 {
1251  update();
1252 }
1253 
1255 {
1256  //update data defined properties and redraw item to match
1257  if ( property == QgsComposerObject::PositionX || property == QgsComposerObject::PositionY ||
1258  property == QgsComposerObject::ItemWidth || property == QgsComposerObject::ItemHeight ||
1259  property == QgsComposerObject::AllProperties )
1260  {
1261  QRectF evaluatedRect = evalItemRect( QRectF( pos().x(), pos().y(), rect().width(), rect().height() ) );
1262  setSceneRect( evaluatedRect );
1263  }
1264  if ( property == QgsComposerObject::ItemRotation || property == QgsComposerObject::AllProperties )
1265  {
1266  refreshRotation( false, true );
1267  }
1268  if ( property == QgsComposerObject::Transparency || property == QgsComposerObject::AllProperties )
1269  {
1270  refreshTransparency( false );
1271  }
1272  if ( property == QgsComposerObject::BlendMode || property == QgsComposerObject::AllProperties )
1273  {
1274  refreshBlendMode();
1275  }
1276 
1277  update();
1278 }
1279 
1280 void QgsComposerItem::setId( const QString& id )
1281 {
1282  setToolTip( id );
1283  mId = id;
1284 }
1285 
1286 void QgsComposerItem::setIsGroupMember( const bool isGroupMember )
1287 {
1289  setFlag( QGraphicsItem::ItemIsSelectable, !isGroupMember ); //item in groups cannot be selected
1290 }
bool positionLock() const
Returns whether position lock for mouse drags is enabled returns true if item is locked for mouse mov...
bool effectsEnabled() const
Returns whether effects (eg blend modes) are enabled for the item.
Q_DECL_DEPRECATED bool imageSizeConsideringRotation(double &width, double &height, double rotation) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
double outlineWidth
Definition: qgssvgcache.cpp:78
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
int mTransparency
Item transparency.
A base class for objects which belong to a map composition.
Q_DECL_DEPRECATED double fontHeightCharacterMM(const QFont &font, const QChar &c) const
Returns the font height of a character in millimeters.
void itemRotationChanged(double newRotation)
Is emitted on item rotation change.
static const QString activeThemePath()
Returns the path to the currently active theme directory.
Q_DECL_DEPRECATED double pixelFontSize(double pointSize) const
Calculates font size in mm from a font point size.
void addItemToZList(QgsComposerItem *item)
Adds item to z list.
virtual void setRotation(double r)
Sets the item rotation.
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
void refreshTransparency(const bool updateItem=true)
Refresh item's transparency, considering data defined transparency.
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
double lockSymbolSize() const
Returns the size of the lock symbol depending on the composer zoom level and the item size...
QPointF pagePos() const
Returns the item's position relative to its current page.
QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames
Map of data defined properties for the item to string name to use when exporting item to xml...
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:439
void removeItemFromZList(QgsComposerItem *item)
Removes item from z list.
static QRectF largestRotatedRectWithinBounds(const QRectF originalRect, const QRectF boundsRect, const double rotation)
Calculates the largest scaled version of originalRect which fits within boundsRect, when it is rotated by a specified amount.
static void drawText(QPainter *painter, const QPointF &pos, const QString &text, const QFont &font, const QColor &color=QColor())
Draws text on a painter at a specific position, taking care of composer specific issues (calculation ...
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
ItemPositionMode mLastUsedPositionMode
The item's position mode.
void updateBounds()
Updates the scene bounds of the composition.
virtual void setSelected(bool s)
Set selected, selected item should be highlighted.
static double fontAscentMM(const QFont &font)
Calculate font ascent in millimeters, including workarounds for QT font rendering issues...
virtual void drawFrame(QPainter *p)
Draw black frame around item.
void setFrameEnabled(const bool drawFrame)
Set whether this item has a frame drawn around it or not.
static QFont scaledFontPixelSize(const QFont &font)
Returns a font where size is set in pixels and the size has been upscaled with FONT_WORKAROUND_SCALE ...
QColor backgroundColor() const
Gets the background color for this item.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QPainter::CompositionMode mBlendMode
Composition blend mode for item.
void setCompositionMode(const QPainter::CompositionMode &compositionMode)
double spaceBetweenPages() const
static double fontDescentMM(const QFont &font)
Calculate font descent in millimeters, including workarounds for QT font rendering issues...
double itemRotation(const QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the current rotation for the composer item.
void setBlendMode(const QPainter::CompositionMode blendMode)
Sets the item's composition blending mode.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:324
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
DataDefinedProperty
Data defined properties for different item types.
bool dataDefinedEvaluate(const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue)
Evaluate a data defined property and return the calculated value.
void setItemPosition(double x, double y, ItemPositionMode itemPoint=UpperLeft, int page=-1)
Moves the item to a new position (in canvas coordinates)
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
Q_DECL_DEPRECATED double fontDescentMillimeters(const QFont &font) const
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCA...
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.
void frameChanged()
Emitted if the item's frame style changes.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
void setFrameJoinStyle(const Qt::PenJoinStyle style)
Sets join style used when drawing the item's frame.
void cancelCommand()
Deletes current command.
Q_DECL_DEPRECATED QFont scaledFontPixelSize(const QFont &font) const
Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE.
int transparency() const
Returns the item's transparency.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
static double fontHeightCharacterMM(const QFont &font, const QChar &character)
Calculate font height in millimeters of a single character, including workarounds for QT font renderi...
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
Q_DECL_DEPRECATED double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
Q_DECL_DEPRECATED void rotate(double angle, double &x, double &y) const
Rotates a point / vector.
void endCommand()
Saves end state of item and pushes command to the undo history.
QGraphicsRectItem * mBoundingResizeRectangle
Rectangle used during move and resize actions.
Q_DECL_DEPRECATED QRectF largestRotatedRectWithinBounds(QRectF originalRect, QRectF boundsRect, double rotation) const
Calculates the largest scaled version of originalRect which fits within boundsRect, when it is rotated by a specified amount.
void updatePagePos(double newPageWidth, double newPageHeight)
Moves the item so that it retains its relative position on the page when the paper size changes...
bool mFrame
True if item fram needs to be painted.
const QgsComposition * composition() const
Returns the composition the item is attached to.
void endCommand()
Finish current command and push it onto the undo stack.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
#define M_PI
static const QString defaultThemePath()
Returns the path to the default theme directory.
double mEvaluatedItemRotation
Temporary evaluated item rotation in degrees, clockwise.
void prepareDataDefinedExpressions() const
Prepares all composer item data defined expressions using the current atlas coverage layer if set...
virtual ~QgsComposerItem()
void beginCommand(const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Starts new composer undo command.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
QRectF evalItemRect(const QRectF &newRect)
Update an item rect to consider data defined position and size of item.
Graphics scene for map printing.
static void rotate(const double angle, double &x, double &y)
Rotates a point / vector around the origin.
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
virtual QRectF rectWithFrame() const
Returns the item's rectangular bounds, including any bleed caused by the item's frame.
QGraphicsLineItem * hAlignSnapItem()
Return horizontal align snap item.
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode Added in 1.9.
void setPositionLock(const bool lock)
Locks / unlocks the item position for mouse drags.
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
Q_DECL_DEPRECATED double rotation() const
Returns the rotation for the composer item.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:440
static double textWidthMM(const QFont &font, const QString &text)
Calculate font width in millimeters for a string, including workarounds for QT font rendering issues...
QgsComposition * mComposition
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
QColor mBackgroundColor
Background color.
QGraphicsLineItem * mVAlignSnapItem
static double fontHeightMM(const QFont &font)
Calculate font height in millimeters, including workarounds for QT font rendering issues The font hei...
void init(const bool manageZValue)
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
QGraphicsLineItem * mHAlignSnapItem
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color for this item.
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
bool mItemPositionLocked
True if item position and size cannot be changed with mouse move.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
virtual void setItemRotation(const double r, const bool adjustPosition=false)
Sets the item rotation.
virtual void drawBackground(QPainter *p)
Draw background.
bool hasFrame() const
Whether this item has a frame or not.
virtual void setId(const QString &id)
Set item's id (which is not necessarly unique)
Q_DECL_DEPRECATED double fontHeightMillimeters(const QFont &font) const
Returns the font height in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
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...
Q_DECL_DEPRECATED double angle(const QPointF &p1, const QPointF &p2) const
Returns angle of the line from p1 to p2 (clockwise, starting at N)
void sizeChanged()
Emitted if the rectangle changes.
double paperHeight() const
Returns height of paper item.
void setIsGroupMember(const bool isGroupMember)
Sets whether this item is part of a group.
static double pointsToMM(const double pointSize)
Returns the size in mm corresponding to a font point size.
int page() const
Gets the page the item is currently on.
static Qt::PenJoinStyle decodePenJoinStyle(QString str)
void setEffectsEnabled(const bool effectsEnabled)
Sets whether effects (eg blend modes) are enabled for the item.
QgsAtlasComposition & atlasComposition()
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode Added in 1.9.
QgsComposerEffect * mEffect
Q_DECL_DEPRECATED void drawArrowHead(QPainter *p, double x, double y, double angle, double arrowHeadWidth) const
Draws arrowhead.
QgsComposerItem(QgsComposition *composition, bool manageZValue=true)
Constructor.
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 rectHandlerBorderTolerance() const
Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to t...
static QPointF pointOnLineWithDistance(const QPointF &startPoint, const QPointF &directionPoint, double distance)
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
Represents a vector layer which manages a vector based data sets.
bool mBackground
True if item background needs to be painted.
void move(double dx, double dy)
Moves item in canvas coordinates.
bool isGroupMember() const
Returns whether this item is part of a group.
void refreshBlendMode()
Refresh item's blend mode, considering data defined blend mode.
bool mIsGroupMember
Whether or not this item is part of a group.
Q_DECL_DEPRECATED void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font, const QColor &c=QColor()) const
Draws Text.
double mItemRotation
Item rotation in degrees, clockwise.
void refreshRotation(const bool updateItem=true, const bool rotateAroundCenter=false)
Refresh item's rotation, considering data defined rotation setting.
QGraphicsLineItem * vAlignSnapItem()
Return vertical align snap item.
Q_DECL_DEPRECATED double fontAscentMillimeters(const QFont &font) const
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
void setTransparency(const int transparency)
Sets the item's transparency.
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
void beginCommand(QgsComposerItem *item, const QString &commandText, const QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Allocates new item command and saves initial state in it.
QString id() const
Get item's id (which is not necessarly unique)