QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
110  virtual void setSelected( bool s );
111 
113  virtual bool selected() const { return QGraphicsRectItem::isSelected(); }
114 
116  void move( double dx, double dy );
117 
121  virtual void moveContent( double dx, double dy ) { Q_UNUSED( dx ); Q_UNUSED( dy ); }
122 
127  virtual void zoomContent( int delta, double x, double y ) { Q_UNUSED( delta ); Q_UNUSED( x ); Q_UNUSED( y ); }
128 
135  int page() const;
136 
143  QPointF pagePos() const;
144 
153  void updatePagePos( double newPageWidth, double newPageHeight );
154 
156  void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft, int page = -1 );
157 
167  void setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint = UpperLeft, bool posIncludesFrame = false, int page = -1 );
168 
172  ItemPositionMode lastUsedPositionMode() { return mLastUsedPositionMode; }
173 
176  virtual void setSceneRect( const QRectF& rectangle );
177 
179  bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const;
180 
182  bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
183 
191  bool hasFrame() const {return mFrame;}
192 
201  void setFrameEnabled( const bool drawFrame );
202 
211  virtual void setFrameOutlineWidth( const double outlineWidth );
212 
220  double frameOutlineWidth() const { return pen().widthF(); }
221 
229  Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
230 
239  void setFrameJoinStyle( const Qt::PenJoinStyle style );
240 
248  virtual double estimatedFrameBleed() const;
249 
258  virtual QRectF rectWithFrame() const;
259 
266  bool hasBackground() const {return mBackground;}
267 
275  void setBackgroundEnabled( const bool drawBackground ) { mBackground = drawBackground; }
276 
283  QColor backgroundColor() const { return mBackgroundColor; }
284 
292  void setBackgroundColor( const QColor& backgroundColor );
293 
298  QPainter::CompositionMode blendMode() const { return mBlendMode; }
299 
304  void setBlendMode( const QPainter::CompositionMode blendMode );
305 
310  int transparency() const { return mTransparency; }
311 
316  void setTransparency( const int transparency );
317 
325  bool effectsEnabled() const { return mEffectsEnabled; }
326 
334  void setEffectsEnabled( const bool effectsEnabled );
335 
337  virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
338  virtual void removeItems() {}
339 
340  virtual void beginItemCommand( const QString& text ) { beginCommand( text ); }
341 
345  void beginCommand( const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
346 
347  virtual void endItemCommand() { endCommand(); }
349  void endCommand();
350  void cancelCommand();
351 
352  //functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the
353  //painter down by the same factor for drawing
354 
359  Q_DECL_DEPRECATED void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font, const QColor& c = QColor() ) const;
360 
371  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;
372 
376  Q_DECL_DEPRECATED double textWidthMillimeters( const QFont& font, const QString& text ) const;
377 
382  Q_DECL_DEPRECATED double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
383 
387  Q_DECL_DEPRECATED double fontAscentMillimeters( const QFont& font ) const;
388 
392  Q_DECL_DEPRECATED double fontDescentMillimeters( const QFont& font ) const;
393 
399  Q_DECL_DEPRECATED double fontHeightMillimeters( const QFont& font ) const;
400 
404  Q_DECL_DEPRECATED double pixelFontSize( double pointSize ) const;
405 
409  Q_DECL_DEPRECATED QFont scaledFontPixelSize( const QFont& font ) const;
410 
416  void setPositionLock( const bool lock );
417 
423  bool positionLock() const { return mItemPositionLocked; }
424 
433  double itemRotation( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
434 
439  Q_DECL_DEPRECATED double rotation() const { return mEvaluatedItemRotation; }
440 
442  virtual void updateItem() { QGraphicsRectItem::update(); }
443 
449  QString id() const { return mId; }
450 
456  virtual void setId( const QString& id );
457 
465  QString uuid() const { return mUuid; }
466 
472  bool isGroupMember() const { return mIsGroupMember; }
473 
479  void setIsGroupMember( const bool isGroupMember );
480 
487  virtual int numberExportLayers() const { return 0; }
488 
494  virtual void setCurrentExportLayer( const int layerIdx = -1 ) { mCurrentExportLayer = layerIdx; }
495 
496  public slots:
500  virtual void setRotation( double r );
501 
509  virtual void setItemRotation( const double r, const bool adjustPosition = false );
510 
511  void repaint();
512 
521 
522  protected:
523 
529 
531  QGraphicsRectItem* mBoundingResizeRectangle;
532  QGraphicsLineItem* mHAlignSnapItem;
533  QGraphicsLineItem* mVAlignSnapItem;
534 
536  bool mFrame;
542  Qt::PenJoinStyle mFrameJoinStyle;
543 
547 
550 
557 
559  QPainter::CompositionMode mBlendMode;
562 
565 
569 
572 
577 
579  virtual void drawSelectionBoxes( QPainter* p );
580 
582  virtual void drawFrame( QPainter* p );
583 
585  virtual void drawBackground( QPainter* p );
586 
590  Q_DECL_DEPRECATED void drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const;
591 
595  Q_DECL_DEPRECATED double angle( const QPointF& p1, const QPointF& p2 ) const;
596 
599  double rectHandlerBorderTolerance() const;
600 
603  double lockSymbolSize() const;
604 
608  double horizontalViewScaleFactor() const;
609 
610  //some utility functions
611 
615  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height, double rotation ) const;
616 
620  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
621 
629  Q_DECL_DEPRECATED QRectF largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const;
630 
634  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const;
635 
639  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
640 
644  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height, double rotation );
645 
649  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
650 
657  Q_DECL_DEPRECATED void rotate( double angle, double& x, double& y ) const;
658 
660  QGraphicsLineItem* hAlignSnapItem();
661  void deleteHAlignSnapItem();
663  QGraphicsLineItem* vAlignSnapItem();
664  void deleteVAlignSnapItem();
665  void deleteAlignItems();
666 
668  QRectF evalItemRect( const QRectF &newRect );
669 
670  signals:
672  void itemRotationChanged( double newRotation );
674  void sizeChanged();
678  void frameChanged();
679 
680  private:
681  // id (not unique)
682  QString mId;
683  // name (unique)
684  QString mUuid;
685  // name (temporary when loaded from template)
686  QString mTemplateUuid;
687 
694  void refreshRotation( const bool updateItem = true, const bool rotateAroundCenter = false );
695 
701  void refreshTransparency( const bool updateItem = true );
702 
706  void refreshBlendMode();
707 
708  void init( const bool manageZValue );
709 
710  friend class QgsComposerItemGroup; // to access mTemplateUuid
711 };
712 
713 #endif
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.
double outlineWidth
Definition: qgssvgcache.cpp:78
int mTransparency
Item transparency.
A base class for objects which belong to a map composition.
A container class for data source field mapping or expression.
QPointF mLastMouseEventPos
Position of the last mouse move event (in scene coordinates)
virtual void beginItemCommand(const QString &text)
ItemPositionMode lastUsedPositionMode()
Returns item's last used position mode.
virtual bool selected() const
Is selected.
virtual void removeItems()
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
A item that forms part of a map composition.
QgsComposerItem::MouseMoveAction mCurrentMouseMoveAction
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
ItemPositionMode mLastUsedPositionMode
The item's position mode.
A container for grouping several QgsComposerItems.
QColor backgroundColor() const
Gets the background color for this item.
QPainter::CompositionMode mBlendMode
Composition blend mode for item.
DataDefinedProperty
Data defined properties for different item types.
double frameOutlineWidth() const
Returns the frame's outline width.
virtual int type() const
return correct graphics item type.
virtual void moveContent(double dx, double dy)
Move Content of item.
QString uuid() const
Get item identification name.
virtual void setCurrentExportLayer(const int layerIdx=-1)
Sets the current layer to draw for exporting.
int transparency() const
Returns the item's transparency.
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
QGraphicsRectItem * mBoundingResizeRectangle
Rectangle used during move and resize actions.
bool mFrame
True if item fram needs to be painted.
MouseMoveAction
Describes the action (move or resize in different directon) to be done during mouse move...
double mEvaluatedItemRotation
Temporary evaluated item rotation in degrees, clockwise.
virtual void repaint()
Triggers a redraw for the item.
virtual int numberExportLayers() const
Get the number of layers that this item requires for exporting as layers.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
QPointF mMouseMoveStartPos
Start point of the last mouse move action (in scene coordinates)
void setBackgroundEnabled(const bool drawBackground)
Set whether this item has a Background drawn around it or not.
Graphics scene for map printing.
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 void zoomContent(int delta, double x, double y)
Zoom content of item.
Q_DECL_DEPRECATED double rotation() const
Returns the rotation for the composer item.
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
QColor mBackgroundColor
Background color.
QGraphicsLineItem * mVAlignSnapItem
QGraphicsLineItem * mHAlignSnapItem
int mCurrentExportLayer
The layer that needs to be exported.
virtual void endItemCommand()
virtual void addItem(QgsComposerItem *item)
Composite operations for item groups do nothing per default.
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.
bool hasFrame() const
Whether this item has a frame or not.
bool hasBackground() const
Whether this item has a Background or not.
QgsComposerEffect * mEffect
bool mBackground
True if item background needs to be painted.
bool isGroupMember() const
Returns whether this item is part of a group.
bool mIsGroupMember
Whether or not this item is part of a group.
virtual void refreshDataDefinedProperty(const DataDefinedProperty property=AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
double mItemRotation
Item rotation in degrees, clockwise.
QString id() const
Get item's id (which is not necessarly unique)