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 
95  QgsComposerItem( QgsComposition* composition, bool manageZValue = true );
103  QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
104  virtual ~QgsComposerItem();
105 
107  virtual int type() const { return ComposerItem; }
108 
116  virtual bool isRemoved() const { return mRemovedFromComposition; }
117 
125  void setIsRemoved( const bool removed ) { mRemovedFromComposition = removed; }
126 
128  virtual void setSelected( bool s );
129 
131  virtual bool selected() const { return QGraphicsRectItem::isSelected(); }
132 
134  void move( double dx, double dy );
135 
139  virtual void moveContent( double dx, double dy ) { Q_UNUSED( dx ); Q_UNUSED( dy ); }
140 
145  virtual void zoomContent( int delta, double x, double y ) { Q_UNUSED( delta ); Q_UNUSED( x ); Q_UNUSED( y ); }
146 
153  int page() const;
154 
161  QPointF pagePos() const;
162 
171  void updatePagePos( double newPageWidth, double newPageHeight );
172 
174  void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft, int page = -1 );
175 
185  void setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint = UpperLeft, bool posIncludesFrame = false, int page = -1 );
186 
190  ItemPositionMode lastUsedPositionMode() { return mLastUsedPositionMode; }
191 
194  virtual void setSceneRect( const QRectF& rectangle );
195 
197  bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const;
198 
200  bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
201 
209  bool hasFrame() const {return mFrame;}
210 
219  void setFrameEnabled( const bool drawFrame );
220 
229  virtual void setFrameOutlineWidth( const double outlineWidth );
230 
238  double frameOutlineWidth() const { return pen().widthF(); }
239 
247  Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
248 
257  void setFrameJoinStyle( const Qt::PenJoinStyle style );
258 
266  virtual double estimatedFrameBleed() const;
267 
276  virtual QRectF rectWithFrame() const;
277 
284  bool hasBackground() const {return mBackground;}
285 
293  void setBackgroundEnabled( const bool drawBackground ) { mBackground = drawBackground; }
294 
301  QColor backgroundColor() const { return mBackgroundColor; }
302 
310  void setBackgroundColor( const QColor& backgroundColor );
311 
316  QPainter::CompositionMode blendMode() const { return mBlendMode; }
317 
322  void setBlendMode( const QPainter::CompositionMode blendMode );
323 
328  int transparency() const { return mTransparency; }
329 
334  void setTransparency( const int transparency );
335 
343  bool effectsEnabled() const { return mEffectsEnabled; }
344 
352  void setEffectsEnabled( const bool effectsEnabled );
353 
355  virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
356  virtual void removeItems() {}
357 
358  virtual void beginItemCommand( const QString& text ) { beginCommand( text ); }
359 
363  void beginCommand( const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
364 
365  virtual void endItemCommand() { endCommand(); }
367  void endCommand();
368  void cancelCommand();
369 
370  //functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the
371  //painter down by the same factor for drawing
372 
377  Q_DECL_DEPRECATED void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font, const QColor& c = QColor() ) const;
378 
389  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;
390 
394  Q_DECL_DEPRECATED double textWidthMillimeters( const QFont& font, const QString& text ) const;
395 
400  Q_DECL_DEPRECATED double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
401 
405  Q_DECL_DEPRECATED double fontAscentMillimeters( const QFont& font ) const;
406 
410  Q_DECL_DEPRECATED double fontDescentMillimeters( const QFont& font ) const;
411 
417  Q_DECL_DEPRECATED double fontHeightMillimeters( const QFont& font ) const;
418 
422  Q_DECL_DEPRECATED double pixelFontSize( double pointSize ) const;
423 
427  Q_DECL_DEPRECATED QFont scaledFontPixelSize( const QFont& font ) const;
428 
434  void setPositionLock( const bool lock );
435 
441  bool positionLock() const { return mItemPositionLocked; }
442 
451  double itemRotation( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
452 
457  Q_DECL_DEPRECATED double rotation() const { return mEvaluatedItemRotation; }
458 
460  virtual void updateItem() { QGraphicsRectItem::update(); }
461 
467  QString id() const { return mId; }
468 
474  virtual void setId( const QString& id );
475 
483  QString uuid() const { return mUuid; }
484 
492  virtual QString displayName() const;
493 
501  virtual void setVisibility( const bool visible );
502 
508  bool isGroupMember() const { return mIsGroupMember; }
509 
515  void setIsGroupMember( const bool isGroupMember );
516 
523  virtual int numberExportLayers() const { return 0; }
524 
530  virtual void setCurrentExportLayer( const int layerIdx = -1 ) { mCurrentExportLayer = layerIdx; }
531 
532  public slots:
536  virtual void setRotation( double r );
537 
545  virtual void setItemRotation( const double r, const bool adjustPosition = false );
546 
547  void repaint();
548 
557 
558  protected:
561 
567 
569  QGraphicsRectItem* mBoundingResizeRectangle;
570  QGraphicsLineItem* mHAlignSnapItem;
571  QGraphicsLineItem* mVAlignSnapItem;
572 
574  bool mFrame;
580  Qt::PenJoinStyle mFrameJoinStyle;
581 
585 
588 
595 
597  QPainter::CompositionMode mBlendMode;
600 
603 
607 
610 
615 
619  virtual void drawSelectionBoxes( QPainter* p );
620 
622  virtual void drawFrame( QPainter* p );
623 
625  virtual void drawBackground( QPainter* p );
626 
630  Q_DECL_DEPRECATED void drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const;
631 
635  Q_DECL_DEPRECATED double angle( const QPointF& p1, const QPointF& p2 ) const;
636 
639  double rectHandlerBorderTolerance() const;
640 
645  Q_DECL_DEPRECATED double lockSymbolSize() const;
646 
650  double horizontalViewScaleFactor() const;
651 
652  //some utility functions
653 
657  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height, double rotation ) const;
658 
662  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
663 
671  Q_DECL_DEPRECATED QRectF largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const;
672 
676  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const;
677 
681  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
682 
686  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height, double rotation );
687 
691  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
692 
699  Q_DECL_DEPRECATED void rotate( double angle, double& x, double& y ) const;
700 
702  QGraphicsLineItem* hAlignSnapItem();
703  void deleteHAlignSnapItem();
705  QGraphicsLineItem* vAlignSnapItem();
706  void deleteVAlignSnapItem();
707  void deleteAlignItems();
708 
710  QRectF evalItemRect( const QRectF &newRect );
711 
712  signals:
714  void itemRotationChanged( double newRotation );
716  void sizeChanged();
720  void frameChanged();
724  void lockChanged();
725 
726  private:
727  // id (not unique)
728  QString mId;
729  // name (unique)
730  QString mUuid;
731  // name (temporary when loaded from template)
732  QString mTemplateUuid;
733  // true if composition manages the z value for this item
734  bool mCompositionManagesZValue;
735 
742  void refreshRotation( const bool updateItem = true, const bool rotateAroundCenter = false );
743 
749  void refreshTransparency( const bool updateItem = true );
750 
754  void refreshBlendMode();
755 
756  void init( const bool manageZValue );
757 
758  friend class QgsComposerItemGroup; // to access mTemplateUuid
759 };
760 
761 #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:441
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:343
double outlineWidth
Definition: qgssvgcache.cpp:78
Definition: qgscomposeritem.h:85
Definition: qgscomposeritem.h:71
int mTransparency
Item transparency.
Definition: qgscomposeritem.h:602
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:566
virtual void beginItemCommand(const QString &text)
Definition: qgscomposeritem.h:358
ItemPositionMode lastUsedPositionMode()
Returns item's last used position mode.
Definition: qgscomposeritem.h:190
virtual bool selected() const
Is selected.
Definition: qgscomposeritem.h:131
virtual void removeItems()
Definition: qgscomposeritem.h:356
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
Definition: qgscomposeritem.h:247
ItemPositionMode
Definition: qgscomposeritem.h:79
bool mEffectsEnabled
Definition: qgscomposeritem.h:598
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
QgsComposerItem::MouseMoveAction mCurrentMouseMoveAction
Definition: qgscomposeritem.h:562
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
Definition: qgscomposeritem.h:587
ItemPositionMode mLastUsedPositionMode
The item's position mode.
Definition: qgscomposeritem.h:606
Definition: qgscomposeritem.h:51
A container for grouping several QgsComposerItems.
Definition: qgscomposeritemgroup.h:24
Definition: qgscomposeritem.h:84
Definition: qgscomposeritemcommand.h:73
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:301
QPainter::CompositionMode mBlendMode
Composition blend mode for item.
Definition: qgscomposeritem.h:597
Definition: qgscomposeritem.h:67
Definition: qgscomposerobject.h:43
Context
Definition: qgscomposeritemcommand.h:71
Definition: qgscomposerobject.h:79
ItemType
Definition: qgscomposeritem.h:43
Definition: qgscomposeritem.h:70
double frameOutlineWidth() const
Returns the frame's outline width.
Definition: qgscomposeritem.h:238
virtual int type() const
return correct graphics item type.
Definition: qgscomposeritem.h:107
virtual void moveContent(double dx, double dy)
Move Content of item.
Definition: qgscomposeritem.h:139
Definition: qgscomposeritem.h:81
QString uuid() const
Get item identification name.
Definition: qgscomposeritem.h:483
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:530
void setIsRemoved(const bool removed)
Sets whether this item has been removed from the composition.
Definition: qgscomposeritem.h:125
int transparency() const
Returns the item's transparency.
Definition: qgscomposeritem.h:328
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
Definition: qgscomposeritem.h:460
Definition: qgscomposeritem.h:83
QGraphicsRectItem * mBoundingResizeRectangle
Rectangle used during move and resize actions.
Definition: qgscomposeritem.h:569
bool mFrame
True if item fram needs to be painted.
Definition: qgscomposeritem.h:574
double mEvaluatedItemRotation
Temporary evaluated item rotation in degrees, clockwise.
Definition: qgscomposeritem.h:594
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:560
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
Definition: qgscomposerobject.h:77
virtual int numberExportLayers() const
Get the number of layers that this item requires for exporting as layers.
Definition: qgscomposeritem.h:523
QPointF mMouseMoveStartPos
Start point of the last mouse move action (in scene coordinates)
Definition: qgscomposeritem.h:564
void setBackgroundEnabled(const bool drawBackground)
Set whether this item has a Background drawn around it or not.
Definition: qgscomposeritem.h:293
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:116
virtual void zoomContent(int delta, double x, double y)
Zoom content of item.
Definition: qgscomposeritem.h:145
Q_DECL_DEPRECATED double rotation() const
Returns the rotation for the composer item.
Definition: qgscomposeritem.h:457
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
Definition: qgscomposeritem.h:580
QColor mBackgroundColor
Background color.
Definition: qgscomposeritem.h:578
Definition: qgscomposeritem.h:58
QGraphicsLineItem * mVAlignSnapItem
Definition: qgscomposeritem.h:571
Definition: qgscomposeritem.h:53
Definition: qgscomposeritem.h:49
QGraphicsLineItem * mHAlignSnapItem
Definition: qgscomposeritem.h:570
Definition: qgscomposeritem.h:68
int mCurrentExportLayer
The layer that needs to be exported.
Definition: qgscomposeritem.h:614
virtual void endItemCommand()
Definition: qgscomposeritem.h:365
virtual void addItem(QgsComposerItem *item)
Composite operations for item groups do nothing per default.
Definition: qgscomposeritem.h:355
bool mItemPositionLocked
True if item position and size cannot be changed with mouse move.
Definition: qgscomposeritem.h:584
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
Definition: qgscomposeritem.h:316
Definition: qgscomposeritem.h:72
bool hasFrame() const
Whether this item has a frame or not.
Definition: qgscomposeritem.h:209
bool hasBackground() const
Whether this item has a Background or not.
Definition: qgscomposeritem.h:284
Definition: qgscomposeritem.h:74
Definition: qgscomposeritem.h:50
Definition: qgscomposeritem.h:54
Definition: qgscomposeritem.h:88
QgsComposerEffect * mEffect
Definition: qgscomposeritem.h:599
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:576
bool isGroupMember() const
Returns whether this item is part of a group.
Definition: qgscomposeritem.h:508
bool mIsGroupMember
Whether or not this item is part of a group.
Definition: qgscomposeritem.h:609
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:590
Definition: qgscomposeritem.h:60
Definition: qgscomposeritem.h:57
QString id() const
Get item's id (which is not necessarly unique)
Definition: qgscomposeritem.h:467