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 #include "qgscomposermodel.h"
36 
37 #include <limits>
38 #include "qgsapplication.h"
39 #include "qgsrectangle.h" //just for debugging
40 #include "qgslogger.h"
41 #include "qgssymbollayerv2utils.h" //for pointOnLineWithDistance
42 #include "qgsmaprenderer.h" //for getCompositionMode
43 
44 #include <cmath>
45 
46 #define FONT_WORKAROUND_SCALE 10 //scale factor for upscaling fontsize and downscaling painter
47 
48 #ifndef M_DEG2RAD
49 #define M_DEG2RAD 0.0174532925
50 #endif
51 
52 QgsComposerItem::QgsComposerItem( QgsComposition* composition, bool manageZValue )
53  : QgsComposerObject( composition )
54  , QGraphicsRectItem( 0 )
55  , mRemovedFromComposition( false )
56  , mBoundingResizeRectangle( 0 )
57  , mHAlignSnapItem( 0 )
58  , mVAlignSnapItem( 0 )
59  , mFrame( false )
60  , mBackground( true )
61  , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
62  , mFrameJoinStyle( Qt::MiterJoin )
63  , mItemPositionLocked( false )
64  , mLastValidViewScaleFactor( -1 )
65  , mItemRotation( 0 )
66  , mEvaluatedItemRotation( 0 )
67  , mBlendMode( QPainter::CompositionMode_SourceOver )
68  , mEffectsEnabled( true )
69  , mTransparency( 0 )
70  , mLastUsedPositionMode( UpperLeft )
71  , mIsGroupMember( false )
72  , mCurrentExportLayer( -1 )
73  , mId( "" )
74  , mUuid( QUuid::createUuid().toString() )
75 {
76  init( manageZValue );
77 }
78 
79 QgsComposerItem::QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue )
80  : QgsComposerObject( composition )
81  , QGraphicsRectItem( 0, 0, width, height, 0 )
82  , mRemovedFromComposition( false )
83  , mBoundingResizeRectangle( 0 )
84  , mHAlignSnapItem( 0 )
85  , mVAlignSnapItem( 0 )
86  , mFrame( false )
87  , mBackground( true )
88  , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
89  , mFrameJoinStyle( Qt::MiterJoin )
90  , mItemPositionLocked( false )
91  , mLastValidViewScaleFactor( -1 )
92  , mItemRotation( 0 )
93  , mEvaluatedItemRotation( 0 )
94  , mBlendMode( QPainter::CompositionMode_SourceOver )
95  , mEffectsEnabled( true )
96  , mTransparency( 0 )
97  , mLastUsedPositionMode( UpperLeft )
98  , mIsGroupMember( false )
99  , mCurrentExportLayer( -1 )
100  , mId( "" )
101  , mUuid( QUuid::createUuid().toString() )
102 {
103  init( manageZValue );
104  setPos( x, y );
105 }
106 
107 void QgsComposerItem::init( const bool manageZValue )
108 {
109  setFlag( QGraphicsItem::ItemIsSelectable, true );
110  //set default pen and brush
111  setBrush( QBrush( QColor( 255, 255, 255, 255 ) ) );
112  QPen defaultPen( QColor( 0, 0, 0 ) );
113  defaultPen.setWidthF( 0.3 );
114  defaultPen.setJoinStyle( mFrameJoinStyle );
115  setPen( defaultPen );
116  //let z-Value be managed by composition
117  if ( mComposition && manageZValue )
118  {
120  mComposition->addItemToZList( this );
121  }
122  else
123  {
125  }
126 
127  // Setup composer effect
128  mEffect = new QgsComposerEffect();
129  setGraphicsEffect( mEffect );
130 
131  // data defined strings
132  mDataDefinedNames.insert( QgsComposerObject::PageNumber, QString( "dataDefinedPageNumber" ) );
133  mDataDefinedNames.insert( QgsComposerObject::PositionX, QString( "dataDefinedPositionX" ) );
134  mDataDefinedNames.insert( QgsComposerObject::PositionY, QString( "dataDefinedPositionY" ) );
135  mDataDefinedNames.insert( QgsComposerObject::ItemWidth, QString( "dataDefinedWidth" ) );
136  mDataDefinedNames.insert( QgsComposerObject::ItemHeight, QString( "dataDefinedHeight" ) );
137  mDataDefinedNames.insert( QgsComposerObject::ItemRotation, QString( "dataDefinedRotation" ) );
138  mDataDefinedNames.insert( QgsComposerObject::Transparency, QString( "dataDefinedTransparency" ) );
139  mDataDefinedNames.insert( QgsComposerObject::BlendMode, QString( "dataDefinedBlendMode" ) );
140 
141  if ( mComposition )
142  {
143  //connect to atlas toggling on/off and coverage layer and feature changes
144  //to update data defined values
145  connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( refreshDataDefinedProperty() ) );
146  connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( refreshDataDefinedProperty() ) );
147  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshDataDefinedProperty() ) );
148  //also, refreshing composition triggers a recalculation of data defined properties
149  connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshDataDefinedProperty() ) );
150 
151  //toggling atlas or changing coverage layer requires data defined expressions to be reprepared
152  connect( &mComposition->atlasComposition(), SIGNAL( toggled( bool ) ), this, SLOT( prepareDataDefinedExpressions() ) );
153  connect( &mComposition->atlasComposition(), SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ), this, SLOT( prepareDataDefinedExpressions() ) );
154  }
155 }
156 
158 {
160  {
162  }
163 
165  delete mEffect;
166 
168 }
169 
171 {
172  QgsDebugMsg( "entered." );
173  QGraphicsRectItem::setSelected( s );
174  update(); //to draw selection boxes
175 }
176 
177 bool QgsComposerItem::_writeXML( QDomElement& itemElem, QDomDocument& doc ) const
178 {
179  if ( itemElem.isNull() )
180  {
181  return false;
182  }
183 
184  QDomElement composerItemElem = doc.createElement( "ComposerItem" );
185 
186  //frame
187  if ( mFrame )
188  {
189  composerItemElem.setAttribute( "frame", "true" );
190  }
191  else
192  {
193  composerItemElem.setAttribute( "frame", "false" );
194  }
195 
196  //background
197  if ( mBackground )
198  {
199  composerItemElem.setAttribute( "background", "true" );
200  }
201  else
202  {
203  composerItemElem.setAttribute( "background", "false" );
204  }
205 
206  //scene rect
207  QPointF pagepos = pagePos();
208  composerItemElem.setAttribute( "x", QString::number( pos().x() ) );
209  composerItemElem.setAttribute( "y", QString::number( pos().y() ) );
210  composerItemElem.setAttribute( "page", page() );
211  composerItemElem.setAttribute( "pagex", QString::number( pagepos.x() ) );
212  composerItemElem.setAttribute( "pagey", QString::number( pagepos.y() ) );
213  composerItemElem.setAttribute( "width", QString::number( rect().width() ) );
214  composerItemElem.setAttribute( "height", QString::number( rect().height() ) );
215  composerItemElem.setAttribute( "positionMode", QString::number(( int ) mLastUsedPositionMode ) );
216  composerItemElem.setAttribute( "zValue", QString::number( zValue() ) );
217  composerItemElem.setAttribute( "outlineWidth", QString::number( pen().widthF() ) );
218  composerItemElem.setAttribute( "frameJoinStyle", QgsSymbolLayerV2Utils::encodePenJoinStyle( mFrameJoinStyle ) );
219  composerItemElem.setAttribute( "itemRotation", QString::number( mItemRotation ) );
220  composerItemElem.setAttribute( "uuid", mUuid );
221  composerItemElem.setAttribute( "id", mId );
222  composerItemElem.setAttribute( "visibility", isVisible() );
223  //position lock for mouse moves/resizes
224  if ( mItemPositionLocked )
225  {
226  composerItemElem.setAttribute( "positionLock", "true" );
227  }
228  else
229  {
230  composerItemElem.setAttribute( "positionLock", "false" );
231  }
232 
233  composerItemElem.setAttribute( "lastValidViewScaleFactor", QString::number( mLastValidViewScaleFactor ) );
234 
235  //frame color
236  QDomElement frameColorElem = doc.createElement( "FrameColor" );
237  QColor frameColor = pen().color();
238  frameColorElem.setAttribute( "red", QString::number( frameColor.red() ) );
239  frameColorElem.setAttribute( "green", QString::number( frameColor.green() ) );
240  frameColorElem.setAttribute( "blue", QString::number( frameColor.blue() ) );
241  frameColorElem.setAttribute( "alpha", QString::number( frameColor.alpha() ) );
242  composerItemElem.appendChild( frameColorElem );
243 
244  //background color
245  QDomElement bgColorElem = doc.createElement( "BackgroundColor" );
246  QColor bgColor = brush().color();
247  bgColorElem.setAttribute( "red", QString::number( bgColor.red() ) );
248  bgColorElem.setAttribute( "green", QString::number( bgColor.green() ) );
249  bgColorElem.setAttribute( "blue", QString::number( bgColor.blue() ) );
250  bgColorElem.setAttribute( "alpha", QString::number( bgColor.alpha() ) );
251  composerItemElem.appendChild( bgColorElem );
252 
253  //blend mode
254  composerItemElem.setAttribute( "blendMode", QgsMapRenderer::getBlendModeEnum( mBlendMode ) );
255 
256  //transparency
257  composerItemElem.setAttribute( "transparency", QString::number( mTransparency ) );
258 
259  QgsComposerObject::writeXML( composerItemElem, doc );
260  itemElem.appendChild( composerItemElem );
261 
262  return true;
263 }
264 
265 bool QgsComposerItem::_readXML( const QDomElement& itemElem, const QDomDocument& doc )
266 {
267  Q_UNUSED( doc );
268  if ( itemElem.isNull() )
269  {
270  return false;
271  }
272 
273  QgsComposerObject::readXML( itemElem, doc );
274 
275  //rotation
276  setItemRotation( itemElem.attribute( "itemRotation", "0" ).toDouble() );
277 
278  //uuid
279  mUuid = itemElem.attribute( "uuid", QUuid::createUuid().toString() );
280 
281  // temporary for groups imported from templates
282  mTemplateUuid = itemElem.attribute( "templateUuid" );
283 
284  //id
285  QString id = itemElem.attribute( "id", "" );
286  setId( id );
287 
288  //frame
289  QString frame = itemElem.attribute( "frame" );
290  if ( frame.compare( "true", Qt::CaseInsensitive ) == 0 )
291  {
292  mFrame = true;
293  }
294  else
295  {
296  mFrame = false;
297  }
298 
299  //frame
300  QString background = itemElem.attribute( "background" );
301  if ( background.compare( "true", Qt::CaseInsensitive ) == 0 )
302  {
303  mBackground = true;
304  }
305  else
306  {
307  mBackground = false;
308  }
309 
310  //position lock for mouse moves/resizes
311  QString positionLock = itemElem.attribute( "positionLock" );
312  if ( positionLock.compare( "true", Qt::CaseInsensitive ) == 0 )
313  {
314  setPositionLock( true );
315  }
316  else
317  {
318  setPositionLock( false );
319  }
320 
321  //visibility
322  setVisibility( itemElem.attribute( "visibility", "1" ) != "0" );
323 
324  //position
325  int page;
326  double x, y, pagex, pagey, width, height;
327  bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK;
328 
329  x = itemElem.attribute( "x" ).toDouble( &xOk );
330  y = itemElem.attribute( "y" ).toDouble( &yOk );
331  page = itemElem.attribute( "page" ).toInt( &pageOk );
332  pagex = itemElem.attribute( "pagex" ).toDouble( &pagexOk );
333  pagey = itemElem.attribute( "pagey" ).toDouble( &pageyOk );
334  width = itemElem.attribute( "width" ).toDouble( &widthOk );
335  height = itemElem.attribute( "height" ).toDouble( &heightOk );
336  mLastUsedPositionMode = ( ItemPositionMode )itemElem.attribute( "positionMode" ).toInt( &positionModeOK );
337  if ( !positionModeOK )
338  {
340  }
341  if ( pageOk && pagexOk && pageyOk )
342  {
343  xOk = true;
344  yOk = true;
345  x = pagex;
346  y = ( page - 1 ) * ( mComposition->paperHeight() + composition()->spaceBetweenPages() ) + pagey;
347  }
348 
349  if ( !xOk || !yOk || !widthOk || !heightOk )
350  {
351  return false;
352  }
353 
354  mLastValidViewScaleFactor = itemElem.attribute( "lastValidViewScaleFactor", "-1" ).toDouble();
355 
356  setZValue( itemElem.attribute( "zValue" ).toDouble() );
357 
358  //pen
359  QDomNodeList frameColorList = itemElem.elementsByTagName( "FrameColor" );
360  if ( frameColorList.size() > 0 )
361  {
362  QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
363  bool redOk, greenOk, blueOk, alphaOk, widthOk;
364  int penRed, penGreen, penBlue, penAlpha;
365  double penWidth;
366 
367  penWidth = itemElem.attribute( "outlineWidth" ).toDouble( &widthOk );
368  penRed = frameColorElem.attribute( "red" ).toDouble( &redOk );
369  penGreen = frameColorElem.attribute( "green" ).toDouble( &greenOk );
370  penBlue = frameColorElem.attribute( "blue" ).toDouble( &blueOk );
371  penAlpha = frameColorElem.attribute( "alpha" ).toDouble( &alphaOk );
372  mFrameJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( itemElem.attribute( "frameJoinStyle", "miter" ) );
373 
374  if ( redOk && greenOk && blueOk && alphaOk && widthOk )
375  {
376  QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) );
377  framePen.setWidthF( penWidth );
378  framePen.setJoinStyle( mFrameJoinStyle );
379  setPen( framePen );
380  }
381  }
382 
383  //brush
384  QDomNodeList bgColorList = itemElem.elementsByTagName( "BackgroundColor" );
385  if ( bgColorList.size() > 0 )
386  {
387  QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
388  bool redOk, greenOk, blueOk, alphaOk;
389  int bgRed, bgGreen, bgBlue, bgAlpha;
390  bgRed = bgColorElem.attribute( "red" ).toDouble( &redOk );
391  bgGreen = bgColorElem.attribute( "green" ).toDouble( &greenOk );
392  bgBlue = bgColorElem.attribute( "blue" ).toDouble( &blueOk );
393  bgAlpha = bgColorElem.attribute( "alpha" ).toDouble( &alphaOk );
394  if ( redOk && greenOk && blueOk && alphaOk )
395  {
396  QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha );
397  setBackgroundColor( brushColor );
398  }
399  }
400 
401  //blend mode
402  setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "blendMode", "0" ).toUInt() ) );
403 
404  //transparency
405  setTransparency( itemElem.attribute( "transparency" , "0" ).toInt() );
406 
407  QRectF evaluatedRect = evalItemRect( QRectF( x, y, width, height ) );
408  setSceneRect( evaluatedRect );
409 
410  return true;
411 }
412 
413 void QgsComposerItem::setFrameEnabled( const bool drawFrame )
414 {
415  if ( drawFrame == mFrame )
416  {
417  //no change
418  return;
419  }
420 
421  mFrame = drawFrame;
422  emit frameChanged();
423 }
424 
426 {
427  QPen itemPen = pen();
428  if ( itemPen.widthF() == outlineWidth )
429  {
430  //no change
431  return;
432  }
433  itemPen.setWidthF( outlineWidth );
434  setPen( itemPen );
435  emit frameChanged();
436 }
437 
438 void QgsComposerItem::setFrameJoinStyle( const Qt::PenJoinStyle style )
439 {
440  if ( mFrameJoinStyle == style )
441  {
442  //no change
443  return;
444  }
445  mFrameJoinStyle = style;
446 
447  QPen itemPen = pen();
448  itemPen.setJoinStyle( mFrameJoinStyle );
449  setPen( itemPen );
450  emit frameChanged();
451 }
452 
454 {
455  if ( !hasFrame() )
456  {
457  return 0;
458  }
459 
460  return pen().widthF() / 2.0;
461 }
462 
464 {
465  double frameBleed = estimatedFrameBleed();
466  return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
467 }
468 
470 {
471  if ( mComposition )
472  {
473  mComposition->beginCommand( this, commandText, c );
474  }
475 }
476 
478 {
479  if ( mComposition )
480  {
482  }
483 }
484 
486 {
487  if ( mComposition )
488  {
490  }
491 }
492 
494 {
495 
496  if ( !mComposition )
497  {
498  return;
499  }
500 
502  {
503  double sizeLockSymbol = lockSymbolSize();
504 
505  if ( mItemPositionLocked )
506  {
507  //draw lock symbol at upper left edge. Use QImage to be independent of the graphic system
508  QString lockIconPath = QgsApplication::activeThemePath() + "/mIconLock.png";
509  if ( !QFile::exists( lockIconPath ) )
510  {
511  lockIconPath = QgsApplication::defaultThemePath() + "/mIconLock.png";
512  }
513 
514  QImage lockImage( lockIconPath );
515  if ( !lockImage.isNull() )
516  {
517  p->drawImage( QRectF( 0, 0, sizeLockSymbol, sizeLockSymbol ), lockImage, QRectF( 0, 0, lockImage.width(), lockImage.height() ) );
518  }
519  }
520  }
521 }
522 
523 void QgsComposerItem::drawFrame( QPainter* p )
524 {
525  if ( mFrame && p )
526  {
527  p->save();
528  p->setPen( pen() );
529  p->setBrush( Qt::NoBrush );
530  p->setRenderHint( QPainter::Antialiasing, true );
531  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
532  p->restore();
533  }
534 }
535 
536 void QgsComposerItem::setPositionLock( const bool lock )
537 {
538  if ( lock == mItemPositionLocked )
539  {
540  return;
541  }
542 
543  mItemPositionLocked = lock;
544 
545  //inform model that id data has changed
546  if ( mComposition )
547  {
549  }
550 }
551 
552 double QgsComposerItem::itemRotation( const PropertyValueType valueType ) const
553 {
555 }
556 
557 void QgsComposerItem::move( double dx, double dy )
558 {
559  QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
560  setSceneRect( evalItemRect( newSceneRect ) );
561 }
562 
564 {
565  double y = pos().y();
566  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
567  int page = 1;
568  while ( y - h >= 0. )
569  {
570  y -= h;
571  ++page;
572  }
573  return page;
574 }
575 
577 {
578  QPointF p = pos();
579  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
580  p.ry() -= ( page() - 1 ) * h;
581  return p;
582 }
583 
584 void QgsComposerItem::updatePagePos( double newPageWidth, double newPageHeight )
585 {
586  Q_UNUSED( newPageWidth )
587  QPointF curPagePos = pagePos();
588  int curPage = page() - 1;
589 
590  double y = curPage * ( newPageHeight + composition()->spaceBetweenPages() ) + curPagePos.y();
591  QRectF newSceneRect( pos().x(), y, rect().width(), rect().height() );
592 
593  setSceneRect( evalItemRect( newSceneRect ) );
594  emit sizeChanged();
595 }
596 
597 void QgsComposerItem::setItemPosition( double x, double y, ItemPositionMode itemPoint, int page )
598 {
599  double width = rect().width();
600  double height = rect().height();
601  setItemPosition( x, y, width, height, itemPoint, false, page );
602 }
603 
604 void QgsComposerItem::setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint, bool posIncludesFrame, int page )
605 {
606  double upperLeftX = x;
607  double upperLeftY = y;
608 
609  if ( page > 0 )
610  {
611  double h = composition()->paperHeight() + composition()->spaceBetweenPages();
612  upperLeftY += ( page - 1 ) * h;
613  }
614 
615  //store the item position mode
616  mLastUsedPositionMode = itemPoint;
617 
618  //adjust x-coordinate if placement is not done to a left point
619  if ( itemPoint == UpperMiddle || itemPoint == Middle || itemPoint == LowerMiddle )
620  {
621  upperLeftX -= width / 2.0;
622  }
623  else if ( itemPoint == UpperRight || itemPoint == MiddleRight || itemPoint == LowerRight )
624  {
625  upperLeftX -= width;
626  }
627 
628  //adjust y-coordinate if placement is not done to an upper point
629  if ( itemPoint == MiddleLeft || itemPoint == Middle || itemPoint == MiddleRight )
630  {
631  upperLeftY -= height / 2.0;
632  }
633  else if ( itemPoint == LowerLeft || itemPoint == LowerMiddle || itemPoint == LowerRight )
634  {
635  upperLeftY -= height;
636  }
637 
638  if ( posIncludesFrame )
639  {
640  //adjust position to account for frame size
641 
642  if ( mEvaluatedItemRotation == 0 )
643  {
644  upperLeftX += estimatedFrameBleed();
645  upperLeftY += estimatedFrameBleed();
646  }
647  else
648  {
649  //adjust position for item rotation
650  QLineF lineToItemOrigin = QLineF( 0, 0, estimatedFrameBleed(), estimatedFrameBleed() );
651  lineToItemOrigin.setAngle( -45 - mEvaluatedItemRotation );
652  upperLeftX += lineToItemOrigin.x2();
653  upperLeftY += lineToItemOrigin.y2();
654  }
655 
656  width -= 2 * estimatedFrameBleed();
657  height -= 2 * estimatedFrameBleed();
658  }
659 
660  //consider data defined item size and position before finalising rect
661  QRectF newRect = evalItemRect( QRectF( upperLeftX, upperLeftY, width, height ) );
662 
663  setSceneRect( newRect );
664 }
665 
666 void QgsComposerItem::setSceneRect( const QRectF& rectangle )
667 {
668  //setRect in item coordinates
669  double newWidth = rectangle.width();
670  double newHeight = rectangle.height();
671  double xTranslation = rectangle.x();
672  double yTranslation = rectangle.y();
673 
674  //correction if width and/or height are negative
675  if ( rectangle.width() < 0 )
676  {
677  newWidth = - rectangle.width();
678  xTranslation -= newWidth;
679  }
680 
681  if ( rectangle.height() < 0 )
682  {
683  newHeight = - rectangle.height();
684  yTranslation -= newHeight;
685  }
686 
687  QGraphicsRectItem::setRect( QRectF( 0, 0, newWidth, newHeight ) );
688  setPos( QPointF( xTranslation, yTranslation ) );
689 
690  emit sizeChanged();
691 }
692 
693 QRectF QgsComposerItem::evalItemRect( const QRectF &newRect )
694 {
695  QRectF result = newRect;
696 
697  //data defined position or size set? if so, update rect with data defined values
698  QVariant exprVal;
699  //evaulate width and height first, since they may affect position if non-top-left reference point set
701  {
702  bool ok;
703  double width = exprVal.toDouble( &ok );
704  QgsDebugMsg( QString( "exprVal Width:%1" ).arg( width ) );
705  if ( ok )
706  {
707  result.setWidth( width );
708  }
709  }
711  {
712  bool ok;
713  double height = exprVal.toDouble( &ok );
714  QgsDebugMsg( QString( "exprVal Height:%1" ).arg( height ) );
715  if ( ok )
716  {
717  result.setHeight( height );
718  }
719  }
720 
721  double x = result.left();
722  //initially adjust for position mode to get top-left coordinate
724  {
725  x += newRect.width() / 2.0;
726  }
728  {
729  x += newRect.width();
730  }
732  {
733  bool ok;
734  double positionX = exprVal.toDouble( &ok );
735  QgsDebugMsg( QString( "exprVal Position X:%1" ).arg( positionX ) );
736  if ( ok )
737  {
738  x = positionX;
739  }
740  }
741 
742  double y = result.top();
743  //adjust y-coordinate if placement is not done to an upper point
745  {
746  y += newRect.height() / 2.0;
747  }
749  {
750  y += newRect.height();
751  }
752 
754  {
755  bool ok;
756  double positionY = exprVal.toDouble( &ok );
757  QgsDebugMsg( QString( "exprVal Position Y:%1" ).arg( positionY ) );
758  if ( ok )
759  {
760  y = positionY;
761  }
762  }
763 
764  //adjust x-coordinate if placement is not done to a left point
766  {
767  x -= result.width() / 2.0;
768  }
770  {
771  x -= result.width();
772  }
773 
774  //adjust y-coordinate if placement is not done to an upper point
776  {
777  y -= result.height() / 2.0;
778  }
780  {
781  y -= result.height();
782  }
783 
784  result.moveLeft( x );
785  result.moveTop( y );
786 
787  return result;
788 }
789 
791 {
792  if ( mBackground && p )
793  {
794  p->save();
795  p->setBrush( brush() );//this causes a problem in atlas generation
796  p->setPen( Qt::NoPen );
797  p->setRenderHint( QPainter::Antialiasing, true );
798  p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
799  p->restore();
800  }
801 }
802 
803 void QgsComposerItem::drawArrowHead( QPainter *p, double x, double y, double angle, double arrowHeadWidth ) const
804 {
805  QgsComposerUtils::drawArrowHead( p, x, y, angle, arrowHeadWidth );
806 }
807 
808 double QgsComposerItem::angle( const QPointF &p1, const QPointF &p2 ) const
809 {
810  return QgsComposerUtils::angle( p1, p2 );
811 }
812 
813 void QgsComposerItem::setBackgroundColor( const QColor& backgroundColor )
814 {
816  setBrush( QBrush( mBackgroundColor, Qt::SolidPattern ) );
817 }
818 
819 void QgsComposerItem::setBlendMode( const QPainter::CompositionMode blendMode )
820 {
822  // Update the composer effect to use the new blend mode
824 }
825 
827 {
828  QPainter::CompositionMode blendMode = mBlendMode;
829 
830  //data defined blend mode set?
831  QVariant exprVal;
833  {
834  QString blendstr = exprVal.toString().trimmed();
835  QPainter::CompositionMode blendModeD = QgsSymbolLayerV2Utils::decodeBlendMode( blendstr );
836 
837  QgsDebugMsg( QString( "exprVal BlendMode:%1" ).arg( blendModeD ) );
838  blendMode = blendModeD;
839  }
840 
841  // Update the composer effect to use the new blend mode
842  mEffect->setCompositionMode( blendMode );
843 }
844 
845 void QgsComposerItem::setTransparency( const int transparency )
846 {
848  refreshTransparency( true );
849 }
850 
851 void QgsComposerItem::refreshTransparency( const bool updateItem )
852 {
854 
855  //data defined transparency set?
856  QVariant exprVal;
858  {
859  bool ok;
860  int transparencyD = exprVal.toInt( &ok );
861  QgsDebugMsg( QString( "exprVal Transparency:%1" ).arg( transparencyD ) );
862  if ( ok )
863  {
864  transparency = transparencyD;
865  }
866  }
867 
868  // Set the QGraphicItem's opacity
869  setOpacity( 1. - ( transparency / 100. ) );
870 
871  if ( updateItem )
872  {
873  update();
874  }
875 }
876 
877 void QgsComposerItem::setEffectsEnabled( const bool effectsEnabled )
878 {
879  //enable or disable the QgsComposerEffect applied to this item
881  mEffect->setEnabled( effectsEnabled );
882 }
883 
884 void QgsComposerItem::drawText( QPainter* p, double x, double y, const QString& text, const QFont& font, const QColor& c ) const
885 {
886  QgsComposerUtils::drawText( p, QPointF( x, y ), text, font, c );
887 }
888 
889 void QgsComposerItem::drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment, Qt::AlignmentFlag valignment, int flags ) const
890 {
891  QgsComposerUtils::drawText( p, rect, text, font, QColor(), halignment, valignment, flags );
892 }
893 double QgsComposerItem::textWidthMillimeters( const QFont& font, const QString& text ) const
894 {
895  return QgsComposerUtils::textWidthMM( font, text );
896 }
897 
898 double QgsComposerItem::fontHeightCharacterMM( const QFont& font, const QChar& c ) const
899 {
900  return QgsComposerUtils::fontHeightCharacterMM( font, c );
901 }
902 
903 double QgsComposerItem::fontAscentMillimeters( const QFont& font ) const
904 {
905  return QgsComposerUtils::fontAscentMM( font );
906 }
907 
908 double QgsComposerItem::fontDescentMillimeters( const QFont& font ) const
909 {
910  return QgsComposerUtils::fontDescentMM( font );
911 }
912 
913 double QgsComposerItem::fontHeightMillimeters( const QFont& font ) const
914 {
915  return QgsComposerUtils::fontHeightMM( font );
916 }
917 
918 double QgsComposerItem::pixelFontSize( double pointSize ) const
919 {
920  return QgsComposerUtils::pointsToMM( pointSize );
921 }
922 
923 QFont QgsComposerItem::scaledFontPixelSize( const QFont& font ) const
924 {
926 }
927 
929 {
930  double result = -1;
931  if ( scene() )
932  {
933  QList<QGraphicsView*> viewList = scene()->views();
934  if ( viewList.size() > 0 ) //if not, probably this function was called from non-gui code
935  {
936  QGraphicsView* currentView = viewList.at( 0 );
937  if ( currentView->isVisible() )
938  {
939  result = currentView->transform().m11();
940  mLastValidViewScaleFactor = result;
941  }
942  }
943  }
944  return result;
945 }
946 
948 {
949  //size of symbol boxes depends on zoom level in composer view
950  double viewScaleFactor = horizontalViewScaleFactor();
951  double rectHandlerSize = 10.0 / viewScaleFactor;
952 
953  //make sure the boxes don't get too large
954  if ( rectHandlerSize > ( rect().width() / 3 ) )
955  {
956  rectHandlerSize = rect().width() / 3;
957  }
958  if ( rectHandlerSize > ( rect().height() / 3 ) )
959  {
960  rectHandlerSize = rect().height() / 3;
961  }
962  return rectHandlerSize;
963 }
964 
966 {
967  double lockSymbolSize = 20.0 / horizontalViewScaleFactor();
968 
969  if ( lockSymbolSize > ( rect().width() / 3 ) )
970  {
971  lockSymbolSize = rect().width() / 3;
972  }
973  if ( lockSymbolSize > ( rect().height() / 3 ) )
974  {
975  lockSymbolSize = rect().height() / 3;
976  }
977  return lockSymbolSize;
978 }
979 
980 void QgsComposerItem::setRotation( const double r )
981 {
982  //kept for api compatibility with QGIS 2.0
983  //remove after 2.0 series
984  setItemRotation( r, true );
985 }
986 
987 void QgsComposerItem::setItemRotation( const double r, const bool adjustPosition )
988 {
989  if ( r >= 360 )
990  {
991  mItemRotation = (( int )r ) % 360;
992  }
993  else
994  {
995  mItemRotation = r;
996  }
997 
998  refreshRotation( true, adjustPosition );
999 }
1000 
1001 void QgsComposerItem::refreshRotation( const bool updateItem , const bool adjustPosition )
1002 {
1003  double rotation = mItemRotation;
1004 
1005  //data defined rotation set?
1006  QVariant exprVal;
1008  {
1009  bool ok;
1010  double rotD = exprVal.toDouble( &ok );
1011  QgsDebugMsg( QString( "exprVal Rotation:%1" ).arg( rotD ) );
1012  if ( ok )
1013  {
1014  rotation = rotD;
1015  }
1016  }
1017 
1018  if ( adjustPosition )
1019  {
1020  //adjustPosition set, so shift the position of the item so that rotation occurs around item center
1021  //create a line from the centrepoint of the rect() to its origin, in scene coordinates
1022  QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ) , mapToScene( QPointF( 0 , 0 ) ) );
1023  //rotate this line by the current rotation angle
1024  refLine.setAngle( refLine.angle() - rotation + mEvaluatedItemRotation );
1025  //get new end point of line - this is the new item position
1026  QPointF rotatedReferencePoint = refLine.p2();
1027  setPos( rotatedReferencePoint );
1028  emit sizeChanged();
1029  }
1030 
1031  setTransformOriginPoint( 0, 0 );
1032  QGraphicsItem::setRotation( rotation );
1033 
1035 
1036  emit itemRotationChanged( rotation );
1037 
1038  //update bounds of scene, since rotation may affect this
1040 
1041  if ( updateItem )
1042  {
1043  update();
1044  }
1045 }
1046 
1047 bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& height ) const
1048 {
1049  //kept for api compatibility with QGIS 2.0, use item rotation
1051  return imageSizeConsideringRotation( width, height, mEvaluatedItemRotation );
1053 }
1054 
1055 bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& height, double rotation ) const
1056 {
1057  if ( qAbs( rotation ) <= 0.0 ) //width and height stays the same if there is no rotation
1058  {
1059  return true;
1060  }
1061 
1062  if ( qgsDoubleNear( qAbs( rotation ), 90 ) || qgsDoubleNear( qAbs( rotation ), 270 ) )
1063  {
1064  double tmp = width;
1065  width = height;
1066  height = tmp;
1067  return true;
1068  }
1069 
1070  double x1 = 0;
1071  double y1 = 0;
1072  double x2 = width;
1073  double y2 = 0;
1074  double x3 = width;
1075  double y3 = height;
1076  double x4 = 0;
1077  double y4 = height;
1078  double midX = width / 2.0;
1079  double midY = height / 2.0;
1080 
1082  if ( !cornerPointOnRotatedAndScaledRect( x1, y1, width, height, rotation ) )
1083  {
1084  return false;
1085  }
1086  if ( !cornerPointOnRotatedAndScaledRect( x2, y2, width, height, rotation ) )
1087  {
1088  return false;
1089  }
1090  if ( !cornerPointOnRotatedAndScaledRect( x3, y3, width, height, rotation ) )
1091  {
1092  return false;
1093  }
1094  if ( !cornerPointOnRotatedAndScaledRect( x4, y4, width, height, rotation ) )
1095  {
1096  return false;
1097  }
1099 
1100 
1101  //assume points 1 and 3 are on the rectangle boundaries. Calculate 2 and 4.
1102  double distM1 = sqrt(( x1 - midX ) * ( x1 - midX ) + ( y1 - midY ) * ( y1 - midY ) );
1103  QPointF p2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( QPointF( midX, midY ), QPointF( x2, y2 ), distM1 );
1104 
1105  if ( p2.x() < width && p2.x() > 0 && p2.y() < height && p2.y() > 0 )
1106  {
1107  width = sqrt(( p2.x() - x1 ) * ( p2.x() - x1 ) + ( p2.y() - y1 ) * ( p2.y() - y1 ) );
1108  height = sqrt(( x3 - p2.x() ) * ( x3 - p2.x() ) + ( y3 - p2.y() ) * ( y3 - p2.y() ) );
1109  return true;
1110  }
1111 
1112  //else assume that points 2 and 4 are on the rectangle boundaries. Calculate 1 and 3
1113  double distM2 = sqrt(( x2 - midX ) * ( x2 - midX ) + ( y2 - midY ) * ( y2 - midY ) );
1114  QPointF p1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( QPointF( midX, midY ), QPointF( x1, y1 ), distM2 );
1115  QPointF p3 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( QPointF( midX, midY ), QPointF( x3, y3 ), distM2 );
1116  width = sqrt(( x2 - p1.x() ) * ( x2 - p1.x() ) + ( y2 - p1.y() ) * ( y2 - p1.y() ) );
1117  height = sqrt(( p3.x() - x2 ) * ( p3.x() - x2 ) + ( p3.y() - y2 ) * ( p3.y() - y2 ) );
1118  return true;
1119 }
1120 
1121 QRectF QgsComposerItem::largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const
1122 {
1123  return QgsComposerUtils::largestRotatedRectWithinBounds( originalRect, boundsRect, rotation );
1124 }
1125 
1126 bool QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const
1127 {
1128  //kept for api compatibility with QGIS 2.0, use item rotation
1130  return cornerPointOnRotatedAndScaledRect( x, y, width, height, mEvaluatedItemRotation );
1132 }
1133 
1134 bool QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const
1135 {
1136  //first rotate point clockwise
1137  double rotToRad = rotation * M_PI / 180.0;
1138  QPointF midpoint( width / 2.0, height / 2.0 );
1139  double xVector = x - midpoint.x();
1140  double yVector = y - midpoint.y();
1141  //double xRotated = cos(rotToRad) * xVector + sin(rotToRad) * yVector;
1142  //double yRotated = -sin(rotToRad) * xVector + cos(rotToRad) * yVector;
1143  double xRotated = cos( rotToRad ) * xVector - sin( rotToRad ) * yVector;
1144  double yRotated = sin( rotToRad ) * xVector + cos( rotToRad ) * yVector;
1145 
1146  //create line from midpoint to rotated point
1147  QLineF line( midpoint.x(), midpoint.y(), midpoint.x() + xRotated, midpoint.y() + yRotated );
1148 
1149  //intersect with all four borders and return result
1150  QList<QLineF> borders;
1151  borders << QLineF( 0, 0, width, 0 );
1152  borders << QLineF( width, 0, width, height );
1153  borders << QLineF( width, height, 0, height );
1154  borders << QLineF( 0, height, 0, 0 );
1155 
1156  QList<QLineF>::const_iterator it = borders.constBegin();
1157  QPointF intersectionPoint;
1158 
1159  for ( ; it != borders.constEnd(); ++it )
1160  {
1161  if ( line.intersect( *it, &intersectionPoint ) == QLineF::BoundedIntersection )
1162  {
1163  x = intersectionPoint.x();
1164  y = intersectionPoint.y();
1165  return true;
1166  }
1167  }
1168  return false;
1169 }
1170 
1171 void QgsComposerItem::sizeChangedByRotation( double& width, double& height )
1172 {
1173  //kept for api compatibility with QGIS 2.0, use item rotation
1175  return sizeChangedByRotation( width, height, mEvaluatedItemRotation );
1177 }
1178 
1179 void QgsComposerItem::sizeChangedByRotation( double& width, double& height, double rotation )
1180 {
1181  if ( rotation == 0.0 )
1182  {
1183  return;
1184  }
1185 
1186  //vector to p1
1187  double x1 = -width / 2.0;
1188  double y1 = -height / 2.0;
1189  QgsComposerUtils::rotate( rotation, x1, y1 );
1190  //vector to p2
1191  double x2 = width / 2.0;
1192  double y2 = -height / 2.0;
1193  QgsComposerUtils::rotate( rotation, x2, y2 );
1194  //vector to p3
1195  double x3 = width / 2.0;
1196  double y3 = height / 2.0;
1197  QgsComposerUtils::rotate( rotation, x3, y3 );
1198  //vector to p4
1199  double x4 = -width / 2.0;
1200  double y4 = height / 2.0;
1201  QgsComposerUtils::rotate( rotation, x4, y4 );
1202 
1203  //double midpoint
1204  QPointF midpoint( width / 2.0, height / 2.0 );
1205 
1206  QPolygonF rotatedRectPoly;
1207  rotatedRectPoly << QPointF( midpoint.x() + x1, midpoint.y() + y1 );
1208  rotatedRectPoly << QPointF( midpoint.x() + x2, midpoint.y() + y2 );
1209  rotatedRectPoly << QPointF( midpoint.x() + x3, midpoint.y() + y3 );
1210  rotatedRectPoly << QPointF( midpoint.x() + x4, midpoint.y() + y4 );
1211  QRectF boundingRect = rotatedRectPoly.boundingRect();
1212  width = boundingRect.width();
1213  height = boundingRect.height();
1214 }
1215 
1216 void QgsComposerItem::rotate( double angle, double& x, double& y ) const
1217 {
1218  QgsComposerUtils::rotate( angle, x, y );
1219 }
1220 
1222 {
1223  if ( !mHAlignSnapItem )
1224  {
1225  mHAlignSnapItem = new QGraphicsLineItem( 0 );
1226  mHAlignSnapItem->setPen( QPen( QColor( Qt::red ) ) );
1227  scene()->addItem( mHAlignSnapItem );
1228  mHAlignSnapItem->setZValue( 90 );
1229  }
1230  return mHAlignSnapItem;
1231 }
1232 
1234 {
1235  if ( !mVAlignSnapItem )
1236  {
1237  mVAlignSnapItem = new QGraphicsLineItem( 0 );
1238  mVAlignSnapItem->setPen( QPen( QColor( Qt::red ) ) );
1239  scene()->addItem( mVAlignSnapItem );
1240  mVAlignSnapItem->setZValue( 90 );
1241  }
1242  return mVAlignSnapItem;
1243 }
1244 
1246 {
1247  if ( mHAlignSnapItem )
1248  {
1249  scene()->removeItem( mHAlignSnapItem );
1250  delete mHAlignSnapItem;
1251  mHAlignSnapItem = 0;
1252  }
1253 }
1254 
1256 {
1257  if ( mVAlignSnapItem )
1258  {
1259  scene()->removeItem( mVAlignSnapItem );
1260  delete mVAlignSnapItem;
1261  mVAlignSnapItem = 0;
1262  }
1263 }
1264 
1266 {
1269 }
1270 
1272 {
1273  update();
1274 }
1275 
1277 {
1278  //update data defined properties and redraw item to match
1279  if ( property == QgsComposerObject::PositionX || property == QgsComposerObject::PositionY ||
1280  property == QgsComposerObject::ItemWidth || property == QgsComposerObject::ItemHeight ||
1281  property == QgsComposerObject::AllProperties )
1282  {
1283  QRectF evaluatedRect = evalItemRect( QRectF( pos().x(), pos().y(), rect().width(), rect().height() ) );
1284  setSceneRect( evaluatedRect );
1285  }
1286  if ( property == QgsComposerObject::ItemRotation || property == QgsComposerObject::AllProperties )
1287  {
1288  refreshRotation( false, true );
1289  }
1290  if ( property == QgsComposerObject::Transparency || property == QgsComposerObject::AllProperties )
1291  {
1292  refreshTransparency( false );
1293  }
1294  if ( property == QgsComposerObject::BlendMode || property == QgsComposerObject::AllProperties )
1295  {
1296  refreshBlendMode();
1297  }
1298 
1299  update();
1300 }
1301 
1302 void QgsComposerItem::setId( const QString& id )
1303 {
1304  if ( id == mId )
1305  {
1306  return;
1307  }
1308 
1309  setToolTip( id );
1310  mId = id;
1311 
1312  //inform model that id data has changed
1313  if ( mComposition )
1314  {
1316  }
1317 
1318  emit itemChanged();
1319 }
1320 
1321 void QgsComposerItem::setIsGroupMember( const bool isGroupMember )
1322 {
1324  setFlag( QGraphicsItem::ItemIsSelectable, !isGroupMember ); //item in groups cannot be selected
1325 }
1326 
1328 {
1329  //return id, if it's not empty
1330  if ( ! id().isEmpty() )
1331  {
1332  return id();
1333  }
1334 
1335  //for unnamed items, default to item type
1336  //(note some item types override this method to provide their own defaults)
1337  switch ( type() )
1338  {
1339  case ComposerArrow:
1340  return tr( "<arrow>" );
1341  case ComposerItemGroup:
1342  return tr( "<group>" );
1343  case ComposerLabel:
1344  return tr( "<label>" );
1345  case ComposerLegend:
1346  return tr( "<legend>" );
1347  case ComposerMap:
1348  return tr( "<map>" );
1349  case ComposerPicture:
1350  return tr( "<picture>" );
1351  case ComposerScaleBar:
1352  return tr( "<scale bar>" );
1353  case ComposerShape:
1354  return tr( "<shape>" );
1355  case ComposerTable:
1356  return tr( "<table>" );
1358  return tr( "<attribute table>" );
1359  case ComposerTextTable:
1360  return tr( "<text table>" );
1361  case ComposerFrame:
1362  return tr( "<frame>" );
1363  }
1364 
1365  return tr( "<item>" );
1366 }
1367 
1368 void QgsComposerItem::setVisibility( const bool visible )
1369 {
1370  if ( visible == isVisible() )
1371  {
1372  //nothing to do
1373  return;
1374  }
1375 
1376  QGraphicsItem::setVisible( visible );
1377 
1378  //inform model that id data has changed
1379  if ( mComposition )
1380  {
1382  }
1383 }
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.
QgsComposerModel * itemsModel()
Returns the items model attached to the composition.
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
void itemChanged()
Emitted when the item changes.
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.
void updateItemVisibility(QgsComposerItem *item)
Must be called when an item's visibility changes.
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
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item's display name is modified.
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)
virtual int type() const
return correct graphics item type.
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...
void updateItemLockStatus(QgsComposerItem *item)
Must be called when an item's lock status changes.
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 QString displayName() const
Get item display name.
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.
bool mCompositionManagesZValue
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.
virtual void setVisibility(const bool visible)
Sets visibility for item.
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.
#define tr(sourceText)
QString id() const
Get item's id (which is not necessarly unique)