QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerpicture.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerpicture.cpp
3  -------------------
4  begin : September 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : radim.blazek@gmail.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscomposerpicture.h"
19 #include "qgscomposerutils.h"
20 #include "qgscomposermap.h"
21 #include "qgscomposition.h"
22 #include "qgsatlascomposition.h"
23 #include "qgsproject.h"
24 #include "qgsexpression.h"
25 #include "qgsvectorlayer.h"
26 #include "qgsmessagelog.h"
27 #include "qgsdatadefined.h"
28 #include <QDomDocument>
29 #include <QDomElement>
30 #include <QFileInfo>
31 #include <QImageReader>
32 #include <QPainter>
33 #include <QSvgRenderer>
34 
35 
37  QgsComposerItem( composition ),
38  mMode( Unknown ),
39  mPictureRotation( 0 ),
40  mRotationMap( 0 ),
41  mResizeMode( QgsComposerPicture::Zoom ),
42  mPictureAnchor( UpperLeft ),
43  mHasExpressionError( false )
44 {
45  mPictureWidth = rect().width();
46  init();
47 }
48 
50  mMode( Unknown ),
51  mPictureRotation( 0 ),
52  mRotationMap( 0 ),
53  mResizeMode( QgsComposerPicture::Zoom ),
54  mPictureAnchor( UpperLeft ),
55  mHasExpressionError( false )
56 {
57  mPictureHeight = rect().height();
58  init();
59 }
60 
62 {
63  //default to no background
64  setBackgroundEnabled( false );
65 
66  //data defined strings
67  mDataDefinedNames.insert( QgsComposerObject::PictureSource, QString( "dataDefinedSource" ) );
68 
69  //insert PictureSource data defined property (only required due to deprecated API elements,
70  //remove after 3.0
71  setDataDefinedProperty( QgsComposerObject::PictureSource, false, true, QString(), QString() );
72 
73  //connect some signals
74 
75  //connect to atlas feature changing
76  //to update the picture source expression
77  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshPicture() ) );
78 
79  //connect to composer print resolution changing
80  connect( mComposition, SIGNAL( printResolutionChanged() ), this, SLOT( recalculateSize() ) );
81 }
82 
84 {
85 
86 }
87 
88 void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
89 {
90  Q_UNUSED( itemStyle );
91  Q_UNUSED( pWidget );
92  if ( !painter )
93  {
94  return;
95  }
96 
97  drawBackground( painter );
98 
99  //int newDpi = ( painter->device()->logicalDpiX() + painter->device()->logicalDpiY() ) / 2;
100 
101  //picture resizing
102  if ( mMode != Unknown )
103  {
104  double boundRectWidthMM;
105  double boundRectHeightMM;
106  QRect imageRect;
108  {
109  boundRectWidthMM = mPictureWidth;
110  boundRectHeightMM = mPictureHeight;
111  imageRect = QRect( 0, 0, mImage.width(), mImage.height() );
112  }
114  {
115  boundRectWidthMM = rect().width();
116  boundRectHeightMM = rect().height();
117  imageRect = QRect( 0, 0, mImage.width(), mImage.height() );
118  }
120  {
121  boundRectWidthMM = rect().width();
122  boundRectHeightMM = rect().height();
123  int imageRectWidthPixels = mImage.width();
124  int imageRectHeightPixels = mImage.height();
125  imageRect = clippedImageRect( boundRectWidthMM, boundRectHeightMM ,
126  QSize( imageRectWidthPixels, imageRectHeightPixels ) );
127  }
128  else
129  {
130  boundRectWidthMM = rect().width();
131  boundRectHeightMM = rect().height();
132  imageRect = QRect( 0, 0, rect().width() * mComposition->printResolution() / 25.4,
133  rect().height() * mComposition->printResolution() / 25.4 );
134  }
135  painter->save();
136  //antialiasing on
137  painter->setRenderHint( QPainter::Antialiasing, true );
138 
139  //zoom mode - calculate anchor point and rotation
140  if ( mResizeMode == Zoom )
141  {
142  //TODO - allow placement modes with rotation set. for now, setting a rotation
143  //always places picture in center of frame
144  if ( mPictureRotation != 0 )
145  {
146  painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
147  painter->rotate( mPictureRotation );
148  painter->translate( -boundRectWidthMM / 2.0, -boundRectHeightMM / 2.0 );
149  }
150  else
151  {
152  //shift painter to edge/middle of frame depending on placement
153  double diffX = rect().width() - boundRectWidthMM;
154  double diffY = rect().height() - boundRectHeightMM;
155 
156  double dX = 0;
157  double dY = 0;
158  switch ( mPictureAnchor )
159  {
160  case UpperLeft:
161  case MiddleLeft:
162  case LowerLeft:
163  //nothing to do
164  break;
165  case UpperMiddle:
166  case Middle:
167  case LowerMiddle:
168  dX = diffX / 2.0;
169  break;
170  case UpperRight:
171  case MiddleRight:
172  case LowerRight:
173  dX = diffX;
174  break;
175  }
176  switch ( mPictureAnchor )
177  {
178  case UpperLeft:
179  case UpperMiddle:
180  case UpperRight:
181  //nothing to do
182  break;
183  case MiddleLeft:
184  case Middle:
185  case MiddleRight:
186  dY = diffY / 2.0;
187  break;
188  case LowerLeft:
189  case LowerMiddle:
190  case LowerRight:
191  dY = diffY;
192  break;
193  }
194  painter->translate( dX, dY );
195  }
196  }
197 
198  if ( mMode == SVG )
199  {
200  mSVG.render( painter, QRectF( 0, 0, boundRectWidthMM, boundRectHeightMM ) );
201  }
202  else if ( mMode == RASTER )
203  {
204  painter->drawImage( QRectF( 0, 0, boundRectWidthMM, boundRectHeightMM ), mImage, imageRect );
205  }
206 
207  painter->restore();
208  }
209 
210  //frame and selection boxes
211  drawFrame( painter );
212  if ( isSelected() )
213  {
214  drawSelectionBoxes( painter );
215  }
216 }
217 
218 QRect QgsComposerPicture::clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels )
219 {
220  int boundRectWidthPixels = boundRectWidthMM * mComposition->printResolution() / 25.4;
221  int boundRectHeightPixels = boundRectHeightMM * mComposition->printResolution() / 25.4;
222 
223  //update boundRectWidth/Height so that they exactly match pixel bounds
224  boundRectWidthMM = boundRectWidthPixels * 25.4 / mComposition->printResolution();
225  boundRectHeightMM = boundRectHeightPixels * 25.4 / mComposition->printResolution();
226 
227  //calculate part of image which fits in bounds
228  int leftClip = 0;
229  int topClip = 0;
230 
231  //calculate left crop
232  switch ( mPictureAnchor )
233  {
234  case UpperLeft:
235  case MiddleLeft:
236  case LowerLeft:
237  leftClip = 0;
238  break;
239  case UpperMiddle:
240  case Middle:
241  case LowerMiddle:
242  leftClip = ( imageRectPixels.width() - boundRectWidthPixels ) / 2;
243  break;
244  case UpperRight:
245  case MiddleRight:
246  case LowerRight:
247  leftClip = imageRectPixels.width() - boundRectWidthPixels;
248  break;
249  }
250 
251  //calculate top crop
252  switch ( mPictureAnchor )
253  {
254  case UpperLeft:
255  case UpperMiddle:
256  case UpperRight:
257  topClip = 0;
258  break;
259  case MiddleLeft:
260  case Middle:
261  case MiddleRight:
262  topClip = ( imageRectPixels.height() - boundRectHeightPixels ) / 2;
263  break;
264  case LowerLeft:
265  case LowerMiddle:
266  case LowerRight:
267  topClip = imageRectPixels.height() - boundRectHeightPixels;
268  break;
269  }
270 
271 
272  return QRect( leftClip, topClip, boundRectWidthPixels, boundRectHeightPixels );
273 
274 }
275 
276 void QgsComposerPicture::setPictureFile( const QString& path )
277 {
278  mSourceFile.setFileName( path );
279  refreshPicture();
280 }
281 
283 {
284  QString source = mSourceFile.fileName();
285 
286  //data defined source set?
287  mHasExpressionError = false;
288  QVariant exprVal;
290  {
292  {
293  source = exprVal.toString().trimmed();
294  QgsDebugMsg( QString( "exprVal PictureSource:%1" ).arg( source ) );
295  }
296  else
297  {
298  mHasExpressionError = true;
299  source = QString();
300  QgsMessageLog::logMessage( tr( "Picture expression eval error" ) );
301  }
302  }
303 
304  QFile path;
305  path.setFileName( source );
306  loadPicture( path );
307 }
308 
310 {
311  if ( !file.exists() )
312  {
313  mMode = Unknown;
314  }
315  else
316  {
317  QFileInfo sourceFileInfo( file );
318  QString sourceFileSuffix = sourceFileInfo.suffix();
319  if ( sourceFileSuffix.compare( "svg", Qt::CaseInsensitive ) == 0 )
320  {
321  //try to open svg
322  mSVG.load( file.fileName() );
323  if ( mSVG.isValid() )
324  {
325  mMode = SVG;
326  QRect viewBox = mSVG.viewBox(); //take width/height ratio from view box instead of default size
327  mDefaultSvgSize.setWidth( viewBox.width() );
328  mDefaultSvgSize.setHeight( viewBox.height() );
329  }
330  else
331  {
332  mMode = Unknown;
333  }
334  }
335  else
336  {
337  //try to open raster with QImageReader
338  QImageReader imageReader( file.fileName() );
339  if ( imageReader.read( &mImage ) )
340  {
341  mMode = RASTER;
342  }
343  else
344  {
345  mMode = Unknown;
346  }
347  }
348  }
349 
350  if ( mMode != Unknown ) //make sure we start with a new QImage
351  {
352  recalculateSize();
353  }
354  else if ( mHasExpressionError || !( file.fileName().isEmpty() ) )
355  {
356  //trying to load an invalid file or bad expression, show cross picture
357  mMode = SVG;
358  QString badFile = QString( ":/images/composer/missing_image.svg" );
359  mSVG.load( badFile );
360  if ( mSVG.isValid() )
361  {
362  mMode = SVG;
363  QRect viewBox = mSVG.viewBox(); //take width/height ratio from view box instead of default size
364  mDefaultSvgSize.setWidth( viewBox.width() );
365  mDefaultSvgSize.setHeight( viewBox.height() );
366  recalculateSize();
367  }
368  }
369 
370  emit itemChanged();
371 }
372 
373 QRectF QgsComposerPicture::boundedImageRect( double deviceWidth, double deviceHeight )
374 {
375  double imageToDeviceRatio;
376  if ( mImage.width() / deviceWidth > mImage.height() / deviceHeight )
377  {
378  imageToDeviceRatio = deviceWidth / mImage.width();
379  double height = imageToDeviceRatio * mImage.height();
380  return QRectF( 0, 0, deviceWidth, height );
381  }
382  else
383  {
384  imageToDeviceRatio = deviceHeight / mImage.height();
385  double width = imageToDeviceRatio * mImage.width();
386  return QRectF( 0, 0, width, deviceHeight );
387  }
388 }
389 
390 QRectF QgsComposerPicture::boundedSVGRect( double deviceWidth, double deviceHeight )
391 {
392  double imageToSvgRatio;
393  if ( deviceWidth / mDefaultSvgSize.width() > deviceHeight / mDefaultSvgSize.height() )
394  {
395  imageToSvgRatio = deviceHeight / mDefaultSvgSize.height();
396  double width = mDefaultSvgSize.width() * imageToSvgRatio;
397  return QRectF( 0, 0, width, deviceHeight );
398  }
399  else
400  {
401  imageToSvgRatio = deviceWidth / mDefaultSvgSize.width();
402  double height = mDefaultSvgSize.height() * imageToSvgRatio;
403  return QRectF( 0, 0, deviceWidth, height );
404  }
405 }
406 
408 {
409  if ( mMode == SVG )
410  {
411  return mDefaultSvgSize;
412  }
413  else if ( mMode == RASTER )
414  {
415  return QSizeF( mImage.width(), mImage.height() );
416  }
417  else
418  {
419  return QSizeF( 0, 0 );
420  }
421 }
422 
423 #if 0
424 QRectF QgsComposerPicture::boundedSVGRect( double deviceWidth, double deviceHeight )
425 {
426  double imageToSvgRatio;
427  if ( deviceWidth / mDefaultSvgSize.width() < deviceHeight / mDefaultSvgSize.height() )
428  {
429  imageToSvgRatio = deviceWidth / mDefaultSvgSize.width();
430  double height = mDefaultSvgSize.height() * imageToSvgRatio;
431  return QRectF( 0, 0, deviceWidth, height );
432  }
433  else
434  {
435  imageToSvgRatio = deviceHeight / mDefaultSvgSize.height();
436  double width = mDefaultSvgSize.width() * imageToSvgRatio;
437  return QRectF( 0, 0, width, deviceHeight );
438  }
439 }
440 #endif //0
441 
442 void QgsComposerPicture::setSceneRect( const QRectF& rectangle )
443 {
444 
445  QSizeF currentPictureSize = pictureSize();
446 
448  {
449  QgsComposerItem::setSceneRect( rectangle );
450  mPictureWidth = rectangle.width();
451  mPictureHeight = rectangle.height();
452  return;
453  }
454 
455  QRectF newRect = rectangle;
456 
457  if ( mResizeMode == ZoomResizeFrame && !rect().isEmpty() && !( currentPictureSize.isEmpty() ) )
458  {
459  //if width has changed less than height, then fix width and set height correspondingly
460  //else, do the opposite
461  if ( qAbs( rect().width() - rectangle.width() ) <
462  qAbs( rect().height() - rectangle.height() ) )
463  {
464  newRect.setHeight( currentPictureSize.height() * newRect.width() / currentPictureSize.width() );
465  }
466  else
467  {
468  newRect.setWidth( currentPictureSize.width() * newRect.height() / currentPictureSize.height() );
469  }
470  }
471  else if ( mResizeMode == FrameToImageSize )
472  {
473  if ( !( currentPictureSize.isEmpty() ) )
474  {
475  newRect.setWidth( currentPictureSize.width() * 25.4 / mComposition->printResolution() );
476  newRect.setHeight( currentPictureSize.height() * 25.4 / mComposition->printResolution() );
477  }
478  }
479 
480  //find largest scaling of picture with this rotation which fits in item
481  if ( mResizeMode == Zoom )
482  {
483  QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), newRect, mPictureRotation );
484  mPictureWidth = rotatedImageRect.width();
485  mPictureHeight = rotatedImageRect.height();
486  }
487  else
488  {
489  mPictureWidth = newRect.width();
490  mPictureHeight = newRect.height();
491  }
492 
494  emit itemChanged();
495 }
496 
498 {
499  //kept for compatibility for QGIS2.0 api
500  setPictureRotation( r );
501 }
502 
504 {
505  mPictureRotation = r;
506 
507  if ( mResizeMode == Zoom )
508  {
509  //find largest scaling of picture with this rotation which fits in item
510  QSizeF currentPictureSize = pictureSize();
511  QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), mPictureRotation );
512  mPictureWidth = rotatedImageRect.width();
513  mPictureHeight = rotatedImageRect.height();
514  update();
515  }
516 
518 }
519 
520 void QgsComposerPicture::setRotationMap( int composerMapId )
521 {
522  if ( !mComposition )
523  {
524  return;
525  }
526 
527  if ( composerMapId == -1 ) //disable rotation from map
528  {
529  QObject::disconnect( mRotationMap, SIGNAL( mapRotationChanged( double ) ), this, SLOT( setPictureRotation( double ) ) );
530  mRotationMap = 0;
531  }
532 
533  const QgsComposerMap* map = mComposition->getComposerMapById( composerMapId );
534  if ( !map )
535  {
536  return;
537  }
538  if ( mRotationMap )
539  {
540  QObject::disconnect( mRotationMap, SIGNAL( mapRotationChanged( double ) ), this, SLOT( setPictureRotation( double ) ) );
541  }
542  mPictureRotation = map->mapRotation();
543  QObject::connect( map, SIGNAL( mapRotationChanged( double ) ), this, SLOT( setPictureRotation( double ) ) );
544  mRotationMap = map;
545  update();
547 }
548 
550 {
551  mResizeMode = mode;
553  || ( mode == QgsComposerPicture::Zoom && mPictureRotation != 0 ) )
554  {
555  //call set scene rect to force item to resize to fit picture
556  recalculateSize();
557  }
558  update();
559 }
560 
562 {
563  //call set scene rect with current position/size, as this will trigger the
564  //picture item to recalculate its frame and image size
565  setSceneRect( QRectF( pos().x(), pos().y(), rect().width(), rect().height() ) );
566 }
567 
569 {
571  {
572  refreshPicture();
573  }
574 
576 }
577 
579 {
581  refreshPicture();
582 }
583 
585 {
587  refreshPicture();
588 }
589 
591 {
592  return mSourceFile.fileName();
593 }
594 
595 bool QgsComposerPicture::writeXML( QDomElement& elem, QDomDocument & doc ) const
596 {
597  if ( elem.isNull() )
598  {
599  return false;
600  }
601  QDomElement composerPictureElem = doc.createElement( "ComposerPicture" );
602  composerPictureElem.setAttribute( "file", QgsProject::instance()->writePath( mSourceFile.fileName() ) );
603  composerPictureElem.setAttribute( "pictureWidth", QString::number( mPictureWidth ) );
604  composerPictureElem.setAttribute( "pictureHeight", QString::number( mPictureHeight ) );
605  composerPictureElem.setAttribute( "resizeMode", QString::number(( int )mResizeMode ) );
606  composerPictureElem.setAttribute( "anchorPoint", QString::number(( int )mPictureAnchor ) );
607 
608  //rotation
609  composerPictureElem.setAttribute( "pictureRotation", QString::number( mPictureRotation ) );
610  if ( !mRotationMap )
611  {
612  composerPictureElem.setAttribute( "mapId", -1 );
613  }
614  else
615  {
616  composerPictureElem.setAttribute( "mapId", mRotationMap->id() );
617  }
618 
619  _writeXML( composerPictureElem, doc );
620  elem.appendChild( composerPictureElem );
621  return true;
622 }
623 
624 bool QgsComposerPicture::readXML( const QDomElement& itemElem, const QDomDocument& doc )
625 {
626  if ( itemElem.isNull() )
627  {
628  return false;
629  }
630 
631  mPictureWidth = itemElem.attribute( "pictureWidth", "10" ).toDouble();
632  mPictureHeight = itemElem.attribute( "pictureHeight", "10" ).toDouble();
633  mResizeMode = QgsComposerPicture::ResizeMode( itemElem.attribute( "resizeMode", "0" ).toInt() );
634  //when loading from xml, default to anchor point of middle to match pre 2.4 behaviour
635  mPictureAnchor = ( QgsComposerItem::ItemPositionMode ) itemElem.attribute( "anchorPoint", QString::number( QgsComposerItem::Middle ) ).toInt();
636 
637  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
638  if ( composerItemList.size() > 0 )
639  {
640  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
641 
642  if ( composerItemElem.attribute( "rotation", "0" ).toDouble() != 0 )
643  {
644  //in versions prior to 2.1 picture rotation was stored in the rotation attribute
645  mPictureRotation = composerItemElem.attribute( "rotation", "0" ).toDouble();
646  }
647 
648  _readXML( composerItemElem, doc );
649  }
650 
651  mDefaultSvgSize = QSize( 0, 0 );
652 
653  if ( itemElem.hasAttribute( "sourceExpression" ) )
654  {
655  //update pre 2.5 picture expression to use data defined expression
656  QString sourceExpression = itemElem.attribute( "sourceExpression", "" );
657  QString useExpression = itemElem.attribute( "useExpression" );
658  bool expressionActive;
659  if ( useExpression.compare( "true", Qt::CaseInsensitive ) == 0 )
660  {
661  expressionActive = true;
662  }
663  else
664  {
665  expressionActive = false;
666  }
667 
668  setDataDefinedProperty( QgsComposerObject::PictureSource, expressionActive, true, sourceExpression, QString() );
669  }
670 
671  QString fileName = QgsProject::instance()->readPath( itemElem.attribute( "file" ) );
672  mSourceFile.setFileName( fileName );
673 
674  //picture rotation
675  if ( itemElem.attribute( "pictureRotation", "0" ).toDouble() != 0 )
676  {
677  mPictureRotation = itemElem.attribute( "pictureRotation", "0" ).toDouble();
678  }
679 
680  //rotation map
681  int rotationMapId = itemElem.attribute( "mapId", "-1" ).toInt();
682  if ( rotationMapId == -1 )
683  {
684  mRotationMap = 0;
685  }
686  else if ( mComposition )
687  {
688 
689  if ( mRotationMap )
690  {
691  QObject::disconnect( mRotationMap, SIGNAL( mapRotationChanged( double ) ), this, SLOT( setRotation( double ) ) );
692  }
693  mRotationMap = mComposition->getComposerMapById( rotationMapId );
694  QObject::connect( mRotationMap, SIGNAL( mapRotationChanged( double ) ), this, SLOT( setRotation( double ) ) );
695  }
696 
697  refreshPicture();
698 
699  emit itemChanged();
700  return true;
701 }
702 
704 {
705  if ( !mRotationMap )
706  {
707  return -1;
708  }
709  else
710  {
711  return mRotationMap->id();
712  }
713 }
714 
716 {
717  mPictureAnchor = anchor;
718  update();
719 }
720 
722 {
724 }
725 
727 {
729 }
730 
731 bool QgsComposerPicture::imageSizeConsideringRotation( double& width, double& height ) const
732 {
733  //kept for api compatibility with QGIS 2.0 - use mPictureRotation
737 }
738 
739 bool QgsComposerPicture::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const
740 {
741  //kept for api compatibility with QGIS 2.0 - use mPictureRotation
745 }
746 
747 void QgsComposerPicture::sizeChangedByRotation( double& width, double& height )
748 {
749  //kept for api compatibility with QGIS 2.0 - use mPictureRotation
753 }
void setActive(bool active)
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...
void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets state from Dom document.
QSizeF pictureSize()
Returns size of current raster or svg picture.
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
void itemChanged()
Emitted when the item changes.
Q_DECL_DEPRECATED bool imageSizeConsideringRotation(double &width, double &height) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
Mode mode() const
Returns the current picture mode (image format).
QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames
Map of data defined properties for the item to string name to use when exporting item to xml...
A item that forms part of a map composition.
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:439
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.
virtual void setRotation(double r)
Sets the picture rotation within the item bounds.
QString expressionString() const
QgsComposerItem::ItemPositionMode mPictureAnchor
virtual void drawFrame(QPainter *p)
Draw black frame around item.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QString readPath(QString filename) const
turn filename read from the project file to an absolute path
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.
A composer class that displays svg files or raster format (jpg, png, ...)
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
void recalculateSize()
Forces a recalculation of the picture's frame size.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
QgsDataDefined * dataDefinedProperty(const DataDefinedProperty property) const
Returns a reference to the data defined settings for one of the item's data defined properties...
QRectF boundedSVGRect(double deviceWidth, double deviceHeight)
Calculates bounding rect for svg file (mSourcefile) such that aspect ratio is correct.
void setPictureAnchor(QgsComposerItem::ItemPositionMode anchor)
Sets the picture's anchor point, which controls how it is placed within the picture item's frame...
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
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...
const QgsComposerMap * mRotationMap
Map that sets the rotation (or 0 if this picture uses map independent rotation)
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
double mPictureHeight
Height of the picture (in mm)
int printResolution() const
virtual void setResizeMode(ResizeMode mode)
Sets the resize mode used for drawing the picture within the item bounds.
virtual void setUsePictureExpression(bool useExpression)
Sets whether the picture should use an expression based image source path.
QRect clippedImageRect(double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels)
Returns part of a raster image which will be shown, given current picture anchor settings.
double mapRotation(QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the composer item.
void setBackgroundEnabled(const bool drawBackground)
Set whether this item has a Background drawn around it or not.
Graphics scene for map printing.
Object representing map window.
QString pictureFile() const
Returns the path of the source image file.
bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores state in Dom element.
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height) const
Calculates corner point after rotation and scaling.
void pictureRotationChanged(double newRotation)
Is emitted on picture rotation change.
QString file
Definition: qgssvgcache.cpp:76
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:440
int id() const
Get identification number.
void setPictureFile(const QString &path)
Sets the source file of the image (may be svg or a raster format).
QgsComposition * mComposition
void refreshPicture()
Recalculates the source image (if using an expression for picture's source) and reloads and redraws t...
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties)
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
virtual void drawBackground(QPainter *p)
Draw background.
Q_DECL_DEPRECATED QString pictureExpression() const
Returns the expression the item is using for the picture source.
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
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...
void setDataDefinedProperty(const DataDefinedProperty property, const bool active, const bool useExpression, const QString &expression, const QString &field)
Sets parameters for a data defined property for the item.
double mPictureWidth
Width of the picture (in mm)
void loadPicture(const QFile &file)
loads an image file into the picture item and redraws the item
QgsAtlasComposition & atlasComposition()
void setRotationMap(int composerMapId)
Sets the map object for rotation (by id).
virtual void setPictureRotation(double r)
Sets the picture rotation within the item bounds.
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
double mPictureRotation
Image rotation.
int rotationMap() const
Returns the id of the rotation map.
QRectF boundedImageRect(double deviceWidth, double deviceHeight)
Calculates bounding rect for image such that aspect ratio is correct.
void init()
sets up the picture item and connects to relevant signals
void setExpressionString(const QString &expr)
bool isActive() const
virtual void setPictureExpression(QString expression)
Sets an expression to use for the picture source.
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
Q_DECL_DEPRECATED bool usePictureExpression() const
Returns whether the picture item is using an expression for the image source.
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height)
Calculates width / height of the bounding box of a rotated rectangle.
#define tr(sourceText)