QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgscomposeritem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposeritem.h
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 #ifndef QGSCOMPOSERITEM_H
18 #define QGSCOMPOSERITEM_H
19 
20 #include "qgscomposeritemcommand.h"
21 #include "qgscomposereffect.h"
22 #include "qgscomposerobject.h"
23 #include "qgsmaprenderer.h" // for blend mode functions & enums
24 #include <QGraphicsRectItem>
25 #include <QObject>
26 
27 class QWidget;
28 class QDomDocument;
29 class QDomElement;
30 class QGraphicsLineItem;
32 class QgsDataDefined;
33 class QgsComposition;
34 
38 class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRectItem
39 {
40  Q_OBJECT
41  public:
42 
43  enum ItemType
44  {
45  // base class for the items
46  ComposerItem = UserType + 100,
47 
48  // derived classes
54  ComposerPaper, // QgsPaperItem
61  ComposerFrame
62  };
63 
66  {
76  NoAction
77  };
78 
80  {
89  LowerRight
90  };
91 
92  //note - must sync with QgsMapCanvas::WheelAction.
93  //TODO - QGIS 3.0 move QgsMapCanvas::WheelAction from GUI->CORE and remove this enum
96  enum ZoomMode
97  {
98  Zoom = 0, /*< Zoom to center of content */
99  ZoomRecenter, /*< Zoom and recenter content to point */
100  ZoomToPoint, /*< Zoom while maintaining relative position of point */
101  NoZoom /*< No zoom */
102  };
103 
107  QgsComposerItem( QgsComposition* composition, bool manageZValue = true );
115  QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
116  virtual ~QgsComposerItem();
117 
119  virtual int type() const { return ComposerItem; }
120 
128  virtual bool isRemoved() const { return mRemovedFromComposition; }
129 
137  void setIsRemoved( const bool removed ) { mRemovedFromComposition = removed; }
138 
140  virtual void setSelected( bool s );
141 
143  virtual bool selected() const { return QGraphicsRectItem::isSelected(); }
144 
146  void move( double dx, double dy );
147 
151  virtual void moveContent( double dx, double dy ) { Q_UNUSED( dx ); Q_UNUSED( dy ); }
152 
159  Q_DECL_DEPRECATED virtual void zoomContent( int delta, double x, double y ) { Q_UNUSED( delta ); Q_UNUSED( x ); Q_UNUSED( y ); }
160 
167  virtual void zoomContent( const double factor, const QPointF point, const ZoomMode mode = QgsComposerItem::Zoom ) { Q_UNUSED( factor ); Q_UNUSED( point ); Q_UNUSED( mode ); }
168 
175  int page() const;
176 
183  QPointF pagePos() const;
184 
193  void updatePagePos( double newPageWidth, double newPageHeight );
194 
196  void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft, int page = -1 );
197 
207  void setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint = UpperLeft, bool posIncludesFrame = false, int page = -1 );
208 
212  ItemPositionMode lastUsedPositionMode() { return mLastUsedPositionMode; }
213 
216  virtual void setSceneRect( const QRectF& rectangle );
217 
219  bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const;
220 
222  bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
223 
231  bool hasFrame() const {return mFrame;}
232 
241  void setFrameEnabled( const bool drawFrame );
242 
251  virtual void setFrameOutlineWidth( const double outlineWidth );
252 
260  double frameOutlineWidth() const { return pen().widthF(); }
261 
269  Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
270 
279  void setFrameJoinStyle( const Qt::PenJoinStyle style );
280 
288  virtual double estimatedFrameBleed() const;
289 
298  virtual QRectF rectWithFrame() const;
299 
306  bool hasBackground() const {return mBackground;}
307 
315  void setBackgroundEnabled( const bool drawBackground ) { mBackground = drawBackground; }
316 
323  QColor backgroundColor() const { return mBackgroundColor; }
324 
332  void setBackgroundColor( const QColor& backgroundColor );
333 
338  QPainter::CompositionMode blendMode() const { return mBlendMode; }
339 
344  void setBlendMode( const QPainter::CompositionMode blendMode );
345 
350  int transparency() const { return mTransparency; }
351 
356  void setTransparency( const int transparency );
357 
365  bool effectsEnabled() const { return mEffectsEnabled; }
366 
374  void setEffectsEnabled( const bool effectsEnabled );
375 
377  virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
378  virtual void removeItems() {}
379 
380  virtual void beginItemCommand( const QString& text ) { beginCommand( text ); }
381 
385  void beginCommand( const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
386 
387  virtual void endItemCommand() { endCommand(); }
389  void endCommand();
390  void cancelCommand();
391 
392  //functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the
393  //painter down by the same factor for drawing
394 
399  Q_DECL_DEPRECATED void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font, const QColor& c = QColor() ) const;
400 
411  Q_DECL_DEPRECATED void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap ) const;
412 
416  Q_DECL_DEPRECATED double textWidthMillimeters( const QFont& font, const QString& text ) const;
417 
422  Q_DECL_DEPRECATED double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
423 
427  Q_DECL_DEPRECATED double fontAscentMillimeters( const QFont& font ) const;
428 
432  Q_DECL_DEPRECATED double fontDescentMillimeters( const QFont& font ) const;
433 
439  Q_DECL_DEPRECATED double fontHeightMillimeters( const QFont& font ) const;
440 
444  Q_DECL_DEPRECATED double pixelFontSize( double pointSize ) const;
445 
449  Q_DECL_DEPRECATED QFont scaledFontPixelSize( const QFont& font ) const;
450 
456  void setPositionLock( const bool lock );
457 
463  bool positionLock() const { return mItemPositionLocked; }
464 
473  double itemRotation( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
474 
479  Q_DECL_DEPRECATED double rotation() const { return mEvaluatedItemRotation; }
480 
482  virtual void updateItem() { QGraphicsRectItem::update(); }
483 
489  QString id() const { return mId; }
490 
496  virtual void setId( const QString& id );
497 
505  QString uuid() const { return mUuid; }
506 
514  virtual QString displayName() const;
515 
523  virtual void setVisibility( const bool visible );
524 
532  bool excludeFromExports( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
533 
539  virtual void setExcludeFromExports( const bool exclude );
540 
546  bool isGroupMember() const { return mIsGroupMember; }
547 
553  void setIsGroupMember( const bool isGroupMember );
554 
561  virtual int numberExportLayers() const { return 0; }
562 
568  virtual void setCurrentExportLayer( const int layerIdx = -1 ) { mCurrentExportLayer = layerIdx; }
569 
570  public slots:
574  virtual void setRotation( double r );
575 
583  virtual void setItemRotation( const double r, const bool adjustPosition = false );
584 
585  void repaint();
586 
595 
596  protected:
599 
605 
607  QGraphicsRectItem* mBoundingResizeRectangle;
608  QGraphicsLineItem* mHAlignSnapItem;
609  QGraphicsLineItem* mVAlignSnapItem;
610 
612  bool mFrame;
618  Qt::PenJoinStyle mFrameJoinStyle;
619 
623 
626 
633 
635  QPainter::CompositionMode mBlendMode;
638 
641 
644 
648 
652 
655 
660 
664  virtual void drawSelectionBoxes( QPainter* p );
665 
667  virtual void drawFrame( QPainter* p );
668 
670  virtual void drawBackground( QPainter* p );
671 
675  Q_DECL_DEPRECATED void drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const;
676 
680  Q_DECL_DEPRECATED double angle( const QPointF& p1, const QPointF& p2 ) const;
681 
684  double rectHandlerBorderTolerance() const;
685 
690  Q_DECL_DEPRECATED double lockSymbolSize() const;
691 
695  double horizontalViewScaleFactor() const;
696 
697  //some utility functions
698 
702  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height, double rotation ) const;
703 
707  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
708 
716  Q_DECL_DEPRECATED QRectF largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const;
717 
721  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const;
722 
726  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
727 
731  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height, double rotation );
732 
736  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
737 
744  Q_DECL_DEPRECATED void rotate( double angle, double& x, double& y ) const;
745 
747  QGraphicsLineItem* hAlignSnapItem();
748  void deleteHAlignSnapItem();
750  QGraphicsLineItem* vAlignSnapItem();
751  void deleteVAlignSnapItem();
752  void deleteAlignItems();
753 
755  QRectF evalItemRect( const QRectF &newRect );
756 
761  bool shouldDrawItem() const;
762 
763  signals:
765  void itemRotationChanged( double newRotation );
767  void sizeChanged();
771  void frameChanged();
775  void lockChanged();
776 
777  private:
778  // id (not unique)
779  QString mId;
780  // name (unique)
781  QString mUuid;
782  // name (temporary when loaded from template)
783  QString mTemplateUuid;
784  // true if composition manages the z value for this item
785  bool mCompositionManagesZValue;
786 
793  void refreshRotation( const bool updateItem = true, const bool rotateAroundCenter = false );
794 
800  void refreshTransparency( const bool updateItem = true );
801 
805  void refreshBlendMode();
806 
807  void init( const bool manageZValue );
808 
809  friend class QgsComposerItemGroup; // to access mTemplateUuid
810 };
811 
812 #endif
bool positionLock() const
Returns whether position lock for mouse drags is enabled returns true if item is locked for mouse mov...
Definition: qgscomposeritem.h:463
bool mExcludeFromExports
Whether item should be excluded in exports.
Definition: qgscomposeritem.h:643
Definition: qgscomposeritem.h:86
Definition: qgscomposereffect.h:24
bool effectsEnabled() const
Returns whether effects (eg blend modes) are enabled for the item.
Definition: qgscomposeritem.h:365
double outlineWidth
Definition: qgssvgcache.cpp:78
Definition: qgscomposeritem.h:85
Definition: qgscomposeritem.h:71
int mTransparency
Item transparency.
Definition: qgscomposeritem.h:640
A base class for objects which belong to a map composition.
Definition: qgscomposerobject.h:33
Definition: qgscomposeritem.h:82
A container class for data source field mapping or expression.
Definition: qgsdatadefined.h:32
Definition: qgscomposeritem.h:56
Definition: qgscomposeritem.h:55
QPointF mLastMouseEventPos
Position of the last mouse move event (in scene coordinates)
Definition: qgscomposeritem.h:604
virtual void beginItemCommand(const QString &text)
Definition: qgscomposeritem.h:380
ItemPositionMode lastUsedPositionMode()
Returns item's last used position mode.
Definition: qgscomposeritem.h:212
virtual bool selected() const
Is selected.
Definition: qgscomposeritem.h:143
Definition: qgscomposeritem.h:99
virtual void removeItems()
Definition: qgscomposeritem.h:378
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
Definition: qgscomposeritem.h:269
ItemPositionMode
Definition: qgscomposeritem.h:79
bool mEffectsEnabled
Definition: qgscomposeritem.h:636
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
QgsComposerItem::MouseMoveAction mCurrentMouseMoveAction
Definition: qgscomposeritem.h:600
Definition: qgscomposeritem.h:100
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
Definition: qgscomposeritem.h:625
ItemPositionMode mLastUsedPositionMode
The item's position mode.
Definition: qgscomposeritem.h:651
Definition: qgscomposeritem.h:51
A container for grouping several QgsComposerItems.
Definition: qgscomposeritemgroup.h:24
Definition: qgscomposeritem.h:84
Definition: qgscomposeritemcommand.h:73
virtual void zoomContent(const double factor, const QPointF point, const ZoomMode mode=QgsComposerItem::Zoom)
Zoom content of item.
Definition: qgscomposeritem.h:167
DataDefinedProperty
Data defined properties for different item types.
Definition: qgscomposerobject.h:40
QColor backgroundColor() const
Gets the background color for this item.
Definition: qgscomposeritem.h:323
QPainter::CompositionMode mBlendMode
Composition blend mode for item.
Definition: qgscomposeritem.h:635
Definition: qgscomposeritem.h:67
Definition: qgscomposerobject.h:43
Context
Definition: qgscomposeritemcommand.h:71
Definition: qgscomposerobject.h:81
ItemType
Definition: qgscomposeritem.h:43
Definition: qgscomposeritem.h:70
double frameOutlineWidth() const
Returns the frame's outline width.
Definition: qgscomposeritem.h:260
virtual int type() const
return correct graphics item type.
Definition: qgscomposeritem.h:119
virtual void moveContent(double dx, double dy)
Move Content of item.
Definition: qgscomposeritem.h:151
Definition: qgscomposeritem.h:81
QString uuid() const
Get item identification name.
Definition: qgscomposeritem.h:505
Definition: qgscomposeritem.h:69
Definition: qgscomposeritem.h:87
Definition: qgscomposeritem.h:73
virtual void setCurrentExportLayer(const int layerIdx=-1)
Sets the current layer to draw for exporting.
Definition: qgscomposeritem.h:568
void setIsRemoved(const bool removed)
Sets whether this item has been removed from the composition.
Definition: qgscomposeritem.h:137
int transparency() const
Returns the item's transparency.
Definition: qgscomposeritem.h:350
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
Definition: qgscomposeritem.h:482
Definition: qgscomposeritem.h:83
QGraphicsRectItem * mBoundingResizeRectangle
Rectangle used during move and resize actions.
Definition: qgscomposeritem.h:607
bool mFrame
True if item fram needs to be painted.
Definition: qgscomposeritem.h:612
double mEvaluatedItemRotation
Temporary evaluated item rotation in degrees, clockwise.
Definition: qgscomposeritem.h:632
virtual void repaint()
Triggers a redraw for the item.
Definition: qgscomposerobject.cpp:136
bool mRemovedFromComposition
True if item has been removed from the composition.
Definition: qgscomposeritem.h:598
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
Definition: qgscomposerobject.h:79
virtual int numberExportLayers() const
Get the number of layers that this item requires for exporting as layers.
Definition: qgscomposeritem.h:561
QPointF mMouseMoveStartPos
Start point of the last mouse move action (in scene coordinates)
Definition: qgscomposeritem.h:602
void setBackgroundEnabled(const bool drawBackground)
Set whether this item has a Background drawn around it or not.
Definition: qgscomposeritem.h:315
Definition: qgscomposeritem.h:75
Graphics scene for map printing.
Definition: qgscomposition.h:72
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)
Definition: qgscomposeritem.h:52
virtual bool isRemoved() const
Returns whether this item has been removed from the composition.
Definition: qgscomposeritem.h:128
Q_DECL_DEPRECATED double rotation() const
Returns the rotation for the composer item.
Definition: qgscomposeritem.h:479
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
Definition: qgscomposeritem.h:618
QColor mBackgroundColor
Background color.
Definition: qgscomposeritem.h:616
Definition: qgscomposeritem.h:58
QGraphicsLineItem * mVAlignSnapItem
Definition: qgscomposeritem.h:609
Definition: qgscomposeritem.h:53
virtual Q_DECL_DEPRECATED void zoomContent(int delta, double x, double y)
Zoom content of item.
Definition: qgscomposeritem.h:159
Definition: qgscomposeritem.h:49
QGraphicsLineItem * mHAlignSnapItem
Definition: qgscomposeritem.h:608
Definition: qgscomposeritem.h:68
int mCurrentExportLayer
The layer that needs to be exported.
Definition: qgscomposeritem.h:659
virtual void endItemCommand()
Definition: qgscomposeritem.h:387
virtual void addItem(QgsComposerItem *item)
Composite operations for item groups do nothing per default.
Definition: qgscomposeritem.h:377
bool mItemPositionLocked
True if item position and size cannot be changed with mouse move.
Definition: qgscomposeritem.h:622
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
Definition: qgscomposeritem.h:338
Definition: qgscomposeritem.h:72
bool hasFrame() const
Whether this item has a frame or not.
Definition: qgscomposeritem.h:231
bool hasBackground() const
Whether this item has a Background or not.
Definition: qgscomposeritem.h:306
Definition: qgscomposeritem.h:74
Definition: qgscomposeritem.h:50
Definition: qgscomposeritem.h:54
Definition: qgscomposeritem.h:88
Definition: qgscomposeritem.h:98
QgsComposerEffect * mEffect
Definition: qgscomposeritem.h:637
MouseMoveAction
Describes the action (move or resize in different directon) to be done during mouse move...
Definition: qgscomposeritem.h:65
Definition: qgscomposeritem.h:59
bool mBackground
True if item background needs to be painted.
Definition: qgscomposeritem.h:614
bool isGroupMember() const
Returns whether this item is part of a group.
Definition: qgscomposeritem.h:546
ZoomMode
Modes for zooming item content.
Definition: qgscomposeritem.h:96
bool mIsGroupMember
Whether or not this item is part of a group.
Definition: qgscomposeritem.h:654
virtual void refreshDataDefinedProperty(const DataDefinedProperty property=AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Definition: qgscomposerobject.cpp:141
double mItemRotation
Item rotation in degrees, clockwise.
Definition: qgscomposeritem.h:628
Definition: qgscomposeritem.h:60
bool mEvaluatedExcludeFromExports
Temporary evaluated item exclusion.
Definition: qgscomposeritem.h:647
Definition: qgscomposeritem.h:57
QString id() const
Get item's id (which is not necessarly unique)
Definition: qgscomposeritem.h:489