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 
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
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