QGIS API Documentation  2.6.0-Brighton
 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 : [email protected]
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 
211  ItemPositionMode lastUsedPositionMode() { return mLastUsedPositionMode; }
212 
215  virtual void setSceneRect( const QRectF& rectangle );
216 
218  bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const;
219 
221  bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
222 
231  bool hasFrame() const {return mFrame;}
232 
241  void setFrameEnabled( const bool drawFrame );
242 
251  virtual void setFrameOutlineColor( const QColor& color );
252 
261  QColor frameOutlineColor() const { return pen().color(); }
262 
271  virtual void setFrameOutlineWidth( const double outlineWidth );
272 
281  double frameOutlineWidth() const { return pen().widthF(); }
282 
291  Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
292 
301  void setFrameJoinStyle( const Qt::PenJoinStyle style );
302 
310  virtual double estimatedFrameBleed() const;
311 
320  virtual QRectF rectWithFrame() const;
321 
328  bool hasBackground() const {return mBackground;}
329 
337  void setBackgroundEnabled( const bool drawBackground ) { mBackground = drawBackground; }
338 
345  QColor backgroundColor() const { return mBackgroundColor; }
346 
354  void setBackgroundColor( const QColor& backgroundColor );
355 
360  QPainter::CompositionMode blendMode() const { return mBlendMode; }
361 
366  void setBlendMode( const QPainter::CompositionMode blendMode );
367 
372  int transparency() const { return mTransparency; }
373 
378  void setTransparency( const int transparency );
379 
387  bool effectsEnabled() const { return mEffectsEnabled; }
388 
396  void setEffectsEnabled( const bool effectsEnabled );
397 
399  virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
400  virtual void removeItems() {}
401 
402  virtual void beginItemCommand( const QString& text ) { beginCommand( text ); }
403 
407  void beginCommand( const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
408 
409  virtual void endItemCommand() { endCommand(); }
411  void endCommand();
412  void cancelCommand();
413 
414  //functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the
415  //painter down by the same factor for drawing
416 
421  Q_DECL_DEPRECATED void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font, const QColor& c = QColor() ) const;
422 
433  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;
434 
438  Q_DECL_DEPRECATED double textWidthMillimeters( const QFont& font, const QString& text ) const;
439 
443  Q_DECL_DEPRECATED double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
444 
448  Q_DECL_DEPRECATED double fontAscentMillimeters( const QFont& font ) const;
449 
453  Q_DECL_DEPRECATED double fontDescentMillimeters( const QFont& font ) const;
454 
460  Q_DECL_DEPRECATED double fontHeightMillimeters( const QFont& font ) const;
461 
465  Q_DECL_DEPRECATED double pixelFontSize( double pointSize ) const;
466 
470  Q_DECL_DEPRECATED QFont scaledFontPixelSize( const QFont& font ) const;
471 
476  void setPositionLock( const bool lock );
477 
482  bool positionLock() const { return mItemPositionLocked; }
483 
492  double itemRotation( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
493 
498  Q_DECL_DEPRECATED double rotation() const { return mEvaluatedItemRotation; }
499 
501  virtual void updateItem() { QGraphicsRectItem::update(); }
502 
507  QString id() const { return mId; }
508 
513  virtual void setId( const QString& id );
514 
521  QString uuid() const { return mUuid; }
522 
530  virtual QString displayName() const;
531 
539  virtual void setVisibility( const bool visible );
540 
548  bool excludeFromExports( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
549 
555  virtual void setExcludeFromExports( const bool exclude );
556 
562  bool isGroupMember() const { return mIsGroupMember; }
563 
569  void setIsGroupMember( const bool isGroupMember );
570 
577  virtual int numberExportLayers() const { return 0; }
578 
584  virtual void setCurrentExportLayer( const int layerIdx = -1 ) { mCurrentExportLayer = layerIdx; }
585 
586  public slots:
590  virtual void setRotation( double r );
591 
599  virtual void setItemRotation( const double r, const bool adjustPosition = false );
600 
601  void repaint();
602 
611 
612  protected:
615 
621 
623  QGraphicsRectItem* mBoundingResizeRectangle;
624  QGraphicsLineItem* mHAlignSnapItem;
625  QGraphicsLineItem* mVAlignSnapItem;
626 
628  bool mFrame;
634  Qt::PenJoinStyle mFrameJoinStyle;
635 
639 
642 
649 
651  QPainter::CompositionMode mBlendMode;
654 
657 
660 
664 
667 
670 
675 
679  virtual void drawSelectionBoxes( QPainter* p );
680 
682  virtual void drawFrame( QPainter* p );
683 
685  virtual void drawBackground( QPainter* p );
686 
690  Q_DECL_DEPRECATED void drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const;
691 
695  Q_DECL_DEPRECATED double angle( const QPointF& p1, const QPointF& p2 ) const;
696 
699  double rectHandlerBorderTolerance() const;
700 
704  Q_DECL_DEPRECATED double lockSymbolSize() const;
705 
709  double horizontalViewScaleFactor() const;
710 
711  //some utility functions
712 
716  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height, double rotation ) const;
717 
721  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
722 
730  Q_DECL_DEPRECATED QRectF largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const;
731 
735  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const;
736 
740  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
741 
745  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height, double rotation );
746 
750  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
751 
758  Q_DECL_DEPRECATED void rotate( double angle, double& x, double& y ) const;
759 
761  QGraphicsLineItem* hAlignSnapItem();
762  void deleteHAlignSnapItem();
764  QGraphicsLineItem* vAlignSnapItem();
765  void deleteVAlignSnapItem();
766  void deleteAlignItems();
767 
778  QRectF evalItemRect( const QRectF &newRect, const bool resizeOnly = false );
779 
784  bool shouldDrawItem() const;
785 
786  signals:
788  void itemRotationChanged( double newRotation );
790  void sizeChanged();
794  void frameChanged();
798  void lockChanged();
799 
800  private:
801  // id (not unique)
802  QString mId;
803  // name (unique)
804  QString mUuid;
805  // name (temporary when loaded from template)
806  QString mTemplateUuid;
807  // true if composition manages the z value for this item
808  bool mCompositionManagesZValue;
809 
816  void refreshRotation( const bool updateItem = true, const bool rotateAroundCenter = false );
817 
823  void refreshTransparency( const bool updateItem = true );
824 
828  void refreshBlendMode();
829 
830  void init( const bool manageZValue );
831 
832  friend class QgsComposerItemGroup; // to access mTemplateUuid
833 };
834 
835 #endif