QGIS API Documentation  2.8.2-Wien
 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 override { 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 
230  bool hasFrame() const {return mFrame;}
231 
239  virtual void setFrameEnabled( const bool drawFrame );
240 
249  virtual void setFrameOutlineColor( const QColor& color );
250 
259  QColor frameOutlineColor() const { return pen().color(); }
260 
269  virtual void setFrameOutlineWidth( const double outlineWidth );
270 
279  double frameOutlineWidth() const { return pen().widthF(); }
280 
289  Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
290 
299  void setFrameJoinStyle( const Qt::PenJoinStyle style );
300 
308  virtual double estimatedFrameBleed() const;
309 
318  virtual QRectF rectWithFrame() const;
319 
325  bool hasBackground() const {return mBackground;}
326 
333  void setBackgroundEnabled( const bool drawBackground ) { mBackground = drawBackground; }
334 
340  QColor backgroundColor() const { return mBackgroundColor; }
341 
348  void setBackgroundColor( const QColor& backgroundColor );
349 
354  QPainter::CompositionMode blendMode() const { return mBlendMode; }
355 
360  void setBlendMode( const QPainter::CompositionMode blendMode );
361 
366  int transparency() const { return mTransparency; }
367 
372  void setTransparency( const int transparency );
373 
380  bool effectsEnabled() const { return mEffectsEnabled; }
381 
388  void setEffectsEnabled( const bool effectsEnabled );
389 
391  virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
392  virtual void removeItems() {}
393 
394  virtual void beginItemCommand( const QString& text ) { beginCommand( text ); }
395 
399  void beginCommand( const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
400 
401  virtual void endItemCommand() { endCommand(); }
403  void endCommand();
404  void cancelCommand();
405 
406  //functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the
407  //painter down by the same factor for drawing
408 
413  Q_DECL_DEPRECATED void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font, const QColor& c = QColor() ) const;
414 
425  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;
426 
430  Q_DECL_DEPRECATED double textWidthMillimeters( const QFont& font, const QString& text ) const;
431 
435  Q_DECL_DEPRECATED double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
436 
440  Q_DECL_DEPRECATED double fontAscentMillimeters( const QFont& font ) const;
441 
445  Q_DECL_DEPRECATED double fontDescentMillimeters( const QFont& font ) const;
446 
452  Q_DECL_DEPRECATED double fontHeightMillimeters( const QFont& font ) const;
453 
457  Q_DECL_DEPRECATED double pixelFontSize( double pointSize ) const;
458 
462  Q_DECL_DEPRECATED QFont scaledFontPixelSize( const QFont& font ) const;
463 
468  void setPositionLock( const bool lock );
469 
474  bool positionLock() const { return mItemPositionLocked; }
475 
484  double itemRotation( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
485 
490  Q_DECL_DEPRECATED double rotation() const { return mEvaluatedItemRotation; }
491 
493  virtual void updateItem() { QGraphicsRectItem::update(); }
494 
499  QString id() const { return mId; }
500 
505  virtual void setId( const QString& id );
506 
513  QString uuid() const { return mUuid; }
514 
522  virtual QString displayName() const;
523 
531  virtual void setVisibility( const bool visible );
532 
540  bool excludeFromExports( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
541 
547  virtual void setExcludeFromExports( const bool exclude );
548 
554  bool isGroupMember() const { return mIsGroupMember; }
555 
561  void setIsGroupMember( const bool isGroupMember );
562 
569  virtual int numberExportLayers() const { return 0; }
570 
576  virtual void setCurrentExportLayer( const int layerIdx = -1 ) { mCurrentExportLayer = layerIdx; }
577 
578  public slots:
582  virtual void setRotation( double r );
583 
591  virtual void setItemRotation( const double r, const bool adjustPosition = false );
592 
593  void repaint() override;
594 
603 
604  protected:
607 
613 
615  QGraphicsRectItem* mBoundingResizeRectangle;
616  QGraphicsLineItem* mHAlignSnapItem;
617  QGraphicsLineItem* mVAlignSnapItem;
618 
620  bool mFrame;
626  Qt::PenJoinStyle mFrameJoinStyle;
627 
631 
634 
641 
643  QPainter::CompositionMode mBlendMode;
646 
649 
652 
656 
659 
662 
667 
671  virtual void drawSelectionBoxes( QPainter* p );
672 
674  virtual void drawFrame( QPainter* p );
675 
677  virtual void drawBackground( QPainter* p );
678 
682  Q_DECL_DEPRECATED void drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const;
683 
685  Q_DECL_DEPRECATED double angle( const QPointF& p1, const QPointF& p2 ) const;
686 
689  double rectHandlerBorderTolerance() const;
690 
694  Q_DECL_DEPRECATED double lockSymbolSize() const;
695 
699  double horizontalViewScaleFactor() const;
700 
701  //some utility functions
702 
706  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height, double rotation ) const;
707 
711  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
712 
720  Q_DECL_DEPRECATED QRectF largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const;
721 
725  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const;
726 
730  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
731 
735  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height, double rotation );
736 
740  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
741 
748  Q_DECL_DEPRECATED void rotate( double angle, double& x, double& y ) const;
749 
751  QGraphicsLineItem* hAlignSnapItem();
752  void deleteHAlignSnapItem();
754  QGraphicsLineItem* vAlignSnapItem();
755  void deleteVAlignSnapItem();
756  void deleteAlignItems();
757 
768  QRectF evalItemRect( const QRectF &newRect, const bool resizeOnly = false );
769 
774  bool shouldDrawItem() const;
775 
776  signals:
778  void itemRotationChanged( double newRotation );
780  void sizeChanged();
784  void frameChanged();
788  void lockChanged();
789 
790  private:
791  // id (not unique)
792  QString mId;
793  // name (unique)
794  QString mUuid;
795  // name (temporary when loaded from template)
796  QString mTemplateUuid;
797  // true if composition manages the z value for this item
798  bool mCompositionManagesZValue;
799 
806  void refreshRotation( const bool updateItem = true, const bool rotateAroundCenter = false );
807 
813  void refreshTransparency( const bool updateItem = true );
814 
818  void refreshBlendMode();
819 
820  void init( const bool manageZValue );
821 
822  friend class QgsComposerItemGroup; // to access mTemplateUuid
823 };
824 
825 #endif