QgsComposerItem Class Reference
[MapComposer]

#include <qgscomposeritem.h>

Inheritance diagram for QgsComposerItem:

Inheritance graph
[legend]
Collaboration diagram for QgsComposerItem:

Collaboration graph
[legend]
List of all members.

Detailed Description

A item that forms part of a map composition.

Definition at line 32 of file qgscomposeritem.h.

Public Types

enum  MouseMoveAction {
  MoveItem, ResizeUp, ResizeDown, ResizeLeft,
  ResizeRight, ResizeLeftUp, ResizeRightUp, ResizeLeftDown,
  ResizeRightDown
}
 Describes the action (move or resize in different directon) to be done during mouse move. More...

Public Member Functions

 QgsComposerItem (QgsComposition *composition)
 QgsComposerItem (qreal x, qreal y, qreal width, qreal height, QgsComposition *composition)
virtual ~QgsComposerItem ()
virtual void setSelected (bool s)
 Set selected, selected item should be highlighted.
virtual bool selected (void)
 Is selected.
virtual bool writeSettings (void)
 stores state in project
virtual bool readSettings (void)
 read state from project
virtual bool removeSettings (void)
 delete settings from project file
void move (double dx, double dy)
 Moves item in canvas coordinates.
virtual void moveContent (double dx, double dy)
 Move Content of item.
virtual void zoomContent (int delta, double x, double y)
 Zoom content of item.
virtual void setSceneRect (const QRectF &rectangle)
 Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size unit.
virtual bool writeXML (QDomElement &elem, QDomDocument &doc) const=0
 stores state in Dom node
bool _writeXML (QDomElement &itemElem, QDomDocument &doc) const
 Writes parameter that are not subclass specific in document.
virtual bool readXML (const QDomElement &itemElem, const QDomDocument &doc)=0
 sets state from Dom document
bool _readXML (const QDomElement &itemElem, const QDomDocument &doc)
 Reads parameter that are not subclass specific in document.
bool frame () const
void setFrame (bool drawFrame)
virtual void addItem (QgsComposerItem *item)
 Composite operations for item groups do nothing per default.
virtual void removeItems ()
const QgsCompositioncomposition () const
void drawText (QPainter *p, int x, int y, const QString &text, const QFont &font) const
 Draws Text.
void drawText (QPainter *p, const QRectF &rect, const QString &text, const QFont &font) const
 Like the above, but with a rectangle for multiline text.
double textWidthMillimeters (const QFont &font, const QString &text) const
 Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
double fontAscentMillimeters (const QFont &font) const
 Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
double pixelFontSize (double pointSize) const
 Calculates font to from point size to pixel size.
QFont scaledFontPixelSize (const QFont &font) const
 Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE.

Protected Member Functions

virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
Qt::CursorShape cursorForPosition (const QPointF &itemCoordPos)
 Finds out the appropriate cursor for the current mouse position in the widget (e.g.
QgsComposerItem::MouseMoveAction mouseMoveActionForPosition (const QPointF &itemCoordPos)
 Finds out which mouse move action to choose depending on the cursor position inside the widget.
void rectangleChange (double dx, double dy, double &mx, double &my, double &rx, double &ry) const
 Calculate rectangle changes according to mouse move (dx, dy) and the current mouse move action.
virtual void drawSelectionBoxes (QPainter *p)
 Draw selection boxes around item.
virtual void drawFrame (QPainter *p)
 Draw black frame around item.
virtual void drawBackground (QPainter *p)
 Draw background.

Protected Attributes

QgsCompositionmComposition
QgsComposerItem::MouseMoveAction mCurrentMouseMoveAction
QPointF mMouseMoveStartPos
 Start point of the last mouse move action (in scene coordinates).
QPointF mLastMouseEventPos
 Position of the last mouse move event (in item coordinates).
QGraphicsRectItem * mBoundingResizeRectangle
 Rectangle used during move and resize actions.
bool mFrame
 True if item fram needs to be painted.


Member Enumeration Documentation

enum QgsComposerItem::MouseMoveAction

Describes the action (move or resize in different directon) to be done during mouse move.

Enumerator:
MoveItem 
ResizeUp 
ResizeDown 
ResizeLeft 
ResizeRight 
ResizeLeftUp 
ResizeRightUp 
ResizeLeftDown 
ResizeRightDown 

Definition at line 38 of file qgscomposeritem.h.


Constructor & Destructor Documentation

QgsComposerItem::QgsComposerItem ( QgsComposition composition  ) 

Definition at line 32 of file qgscomposeritem.cpp.

References QgsComposition::addItemToZList(), and mComposition.

QgsComposerItem::QgsComposerItem ( qreal  x,
qreal  y,
qreal  width,
qreal  height,
QgsComposition composition 
)

Definition at line 50 of file qgscomposeritem.cpp.

References QgsComposition::addItemToZList(), and mComposition.

QgsComposerItem::~QgsComposerItem (  )  [virtual]

Definition at line 72 of file qgscomposeritem.cpp.

References mBoundingResizeRectangle, mComposition, and QgsComposition::removeItemFromZList().


Member Function Documentation

void QgsComposerItem::setSelected ( bool  s  )  [virtual]

Set selected, selected item should be highlighted.

Definition at line 82 of file qgscomposeritem.cpp.

References QgsDebugMsg.

Referenced by QgsComposerView::groupItems(), QgsComposerView::mousePressEvent(), and QgsComposerView::mouseReleaseEvent().

virtual bool QgsComposerItem::selected ( void   )  [inline, virtual]

Is selected.

Definition at line 59 of file qgscomposeritem.h.

bool QgsComposerItem::writeSettings ( void   )  [virtual]

stores state in project

Definition at line 89 of file qgscomposeritem.cpp.

bool QgsComposerItem::readSettings ( void   )  [virtual]

read state from project

Definition at line 91 of file qgscomposeritem.cpp.

bool QgsComposerItem::removeSettings ( void   )  [virtual]

delete settings from project file

Definition at line 93 of file qgscomposeritem.cpp.

void QgsComposerItem::move ( double  dx,
double  dy 
)

Moves item in canvas coordinates.

Definition at line 472 of file qgscomposeritem.cpp.

References setSceneRect().

virtual void QgsComposerItem::moveContent ( double  dx,
double  dy 
) [inline, virtual]

Move Content of item.

Does nothing per default (but implemented in composer map)

Parameters:
dx move in x-direction (canvas coordinates)
dy move in y-direction(canvas coordinates)

Reimplemented in QgsComposerMap.

Definition at line 76 of file qgscomposeritem.h.

Referenced by QgsComposerView::mouseReleaseEvent().

virtual void QgsComposerItem::zoomContent ( int  delta,
double  x,
double  y 
) [inline, virtual]

Zoom content of item.

Does nothing per default (but implemented in composer map)

Parameters:
delta value from wheel event that describes magnitude and direction (positive /negative number)
x x-position of mouse cursor (in item coordinates)
y y-position of mouse cursor (in item coordinates)

Reimplemented in QgsComposerMap.

Definition at line 82 of file qgscomposeritem.h.

Referenced by QgsComposerView::wheelEvent().

void QgsComposerItem::setSceneRect ( const QRectF &  rectangle  )  [virtual]

Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size unit.

Reimplemented in QgsComposerItemGroup, QgsComposerMap, and QgsComposerPicture.

Definition at line 479 of file qgscomposeritem.cpp.

Referenced by _readXML(), QgsComposerItemGroup::addItem(), QgsComposerScaleBar::adjustBoxSize(), QgsComposerLegend::adjustBoxSize(), QgsComposerLabel::adjustSizeToText(), QgsComposerView::mousePressEvent(), mouseReleaseEvent(), move(), QgsComposerLegend::paintAndDetermineSize(), QgsComposerPicture::setSceneRect(), QgsComposerMap::setSceneRect(), and QgsComposerItemGroup::setSceneRect().

virtual bool QgsComposerItem::writeXML ( QDomElement &  elem,
QDomDocument &  doc 
) const [pure virtual]

stores state in Dom node

Parameters:
node is Dom node corresponding to 'Composer' tag
temp write template file

Implemented in QgsComposerItemGroup, QgsComposerLabel, QgsComposerLegend, QgsComposerMap, QgsComposerPicture, and QgsComposerScaleBar.

bool QgsComposerItem::_writeXML ( QDomElement &  itemElem,
QDomDocument &  doc 
) const

Writes parameter that are not subclass specific in document.

Usually called from writeXML methods of subclasses

Definition at line 95 of file qgscomposeritem.cpp.

References mFrame.

Referenced by QgsComposerScaleBar::writeXML(), QgsComposerPicture::writeXML(), QgsComposerMap::writeXML(), QgsComposerLegend::writeXML(), and QgsComposerLabel::writeXML().

virtual bool QgsComposerItem::readXML ( const QDomElement &  itemElem,
const QDomDocument &  doc 
) [pure virtual]

sets state from Dom document

Parameters:
itemElem is Dom node corresponding to item tag

Implemented in QgsComposerItemGroup, QgsComposerLabel, QgsComposerLegend, QgsComposerMap, QgsComposerPicture, and QgsComposerScaleBar.

bool QgsComposerItem::_readXML ( const QDomElement &  itemElem,
const QDomDocument &  doc 
)

Reads parameter that are not subclass specific in document.

Usually called from readXML methods of subclasses

Definition at line 145 of file qgscomposeritem.cpp.

References frame(), mFrame, and setSceneRect().

Referenced by QgsComposerScaleBar::readXML(), QgsComposerPicture::readXML(), QgsComposerMap::readXML(), QgsComposerLegend::readXML(), and QgsComposerLabel::readXML().

bool QgsComposerItem::frame (  )  const [inline]

Definition at line 107 of file qgscomposeritem.h.

Referenced by _readXML().

void QgsComposerItem::setFrame ( bool  drawFrame  )  [inline]

Definition at line 108 of file qgscomposeritem.h.

virtual void QgsComposerItem::addItem ( QgsComposerItem item  )  [inline, virtual]

Composite operations for item groups do nothing per default.

Reimplemented in QgsComposerItemGroup.

Definition at line 111 of file qgscomposeritem.h.

virtual void QgsComposerItem::removeItems (  )  [inline, virtual]

Reimplemented in QgsComposerItemGroup.

Definition at line 112 of file qgscomposeritem.h.

const QgsComposition* QgsComposerItem::composition (  )  const [inline]

Definition at line 114 of file qgscomposeritem.h.

Referenced by QgsComposerMap::QgsComposerMap().

void QgsComposerItem::drawText ( QPainter *  p,
int  x,
int  y,
const QString &  text,
const QFont &  font 
) const

Draws Text.

Takes care about all the composer specific issues (calculation to pixel, scaling of font and painter to work arount the Qt font bug)

Definition at line 528 of file qgscomposeritem.cpp.

References FONT_WORKAROUND_SCALE, and scaledFontPixelSize().

Referenced by QgsNumericScaleBarStyle::draw(), QgsScaleBarStyle::drawLabels(), QgsComposerLegend::drawLayerChildItems(), QgsComposerLabel::paint(), and QgsComposerLegend::paintAndDetermineSize().

void QgsComposerItem::drawText ( QPainter *  p,
const QRectF &  rect,
const QString &  text,
const QFont &  font 
) const

Like the above, but with a rectangle for multiline text.

Definition at line 541 of file qgscomposeritem.cpp.

References FONT_WORKAROUND_SCALE, and scaledFontPixelSize().

double QgsComposerItem::textWidthMillimeters ( const QFont &  font,
const QString &  text 
) const

Returns the font width in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.

Definition at line 557 of file qgscomposeritem.cpp.

References FONT_WORKAROUND_SCALE, and scaledFontPixelSize().

Referenced by QgsComposerLabel::adjustSizeToText(), QgsScaleBarStyle::calculateBoxSize(), QgsNumericScaleBarStyle::calculateBoxSize(), QgsScaleBarStyle::drawLabels(), QgsComposerLegend::drawLayerChildItems(), QgsComposerScaleBar::paint(), and QgsComposerLegend::paintAndDetermineSize().

double QgsComposerItem::fontAscentMillimeters ( const QFont &  font  )  const

Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.

Definition at line 564 of file qgscomposeritem.cpp.

References FONT_WORKAROUND_SCALE, and scaledFontPixelSize().

Referenced by QgsComposerLabel::adjustSizeToText(), QgsScaleBarStyle::calculateBoxSize(), QgsNumericScaleBarStyle::calculateBoxSize(), QgsTicksScaleBarStyle::draw(), QgsSingleBoxScaleBarStyle::draw(), QgsNumericScaleBarStyle::draw(), QgsDoubleBoxScaleBarStyle::draw(), QgsScaleBarStyle::drawLabels(), QgsComposerLegend::drawLayerChildItems(), and QgsComposerLegend::paintAndDetermineSize().

double QgsComposerItem::pixelFontSize ( double  pointSize  )  const

Calculates font to from point size to pixel size.

Definition at line 571 of file qgscomposeritem.cpp.

Referenced by scaledFontPixelSize().

QFont QgsComposerItem::scaledFontPixelSize ( const QFont &  font  )  const

Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE.

Definition at line 576 of file qgscomposeritem.cpp.

References FONT_WORKAROUND_SCALE, and pixelFontSize().

Referenced by drawText(), fontAscentMillimeters(), and textWidthMillimeters().

void QgsComposerItem::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event  )  [protected, virtual]

Definition at line 220 of file qgscomposeritem.cpp.

References mBoundingResizeRectangle, mLastMouseEventPos, and rectangleChange().

void QgsComposerItem::mousePressEvent ( QGraphicsSceneMouseEvent *  event  )  [protected, virtual]

Definition at line 248 of file qgscomposeritem.cpp.

References mBoundingResizeRectangle, mCurrentMouseMoveAction, mLastMouseEventPos, mMouseMoveStartPos, and mouseMoveActionForPosition().

void QgsComposerItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event  )  [protected, virtual]

Definition at line 269 of file qgscomposeritem.cpp.

References mBoundingResizeRectangle, mCurrentMouseMoveAction, mMouseMoveStartPos, MoveItem, rectangleChange(), and setSceneRect().

void QgsComposerItem::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event  )  [protected, virtual]

Definition at line 520 of file qgscomposeritem.cpp.

References cursorForPosition().

Qt::CursorShape QgsComposerItem::cursorForPosition ( const QPointF &  itemCoordPos  )  [protected]

Finds out the appropriate cursor for the current mouse position in the widget (e.g.

move in the middle, resize at border)

Definition at line 304 of file qgscomposeritem.cpp.

References mouseMoveActionForPosition(), MoveItem, ResizeDown, ResizeLeftDown, ResizeLeftUp, ResizeRightDown, ResizeRightUp, and ResizeUp.

Referenced by hoverMoveEvent().

QgsComposerItem::MouseMoveAction QgsComposerItem::mouseMoveActionForPosition ( const QPointF &  itemCoordPos  )  [protected]

Finds out which mouse move action to choose depending on the cursor position inside the widget.

Definition at line 330 of file qgscomposeritem.cpp.

References MoveItem, ResizeDown, ResizeLeft, ResizeLeftDown, ResizeLeftUp, ResizeRight, ResizeRightDown, ResizeRightUp, and ResizeUp.

Referenced by cursorForPosition(), and mousePressEvent().

void QgsComposerItem::rectangleChange ( double  dx,
double  dy,
double &  mx,
double &  my,
double &  rx,
double &  ry 
) const [protected]

Calculate rectangle changes according to mouse move (dx, dy) and the current mouse move action.

Parameters:
dx x-coordinate move of cursor
dy y-coordinate move of cursor
mx out: rectangle should be moved by mx in x-direction
my out: rectangle should be moved by my in y-direction
rx out: width of rectangle should be resized by rx
ry out: height of rectangle should be resized by ry

Definition at line 395 of file qgscomposeritem.cpp.

References mCurrentMouseMoveAction, MoveItem, ResizeDown, ResizeLeft, ResizeLeftDown, ResizeLeftUp, ResizeRight, ResizeRightDown, ResizeRightUp, and ResizeUp.

Referenced by mouseMoveEvent(), and mouseReleaseEvent().

void QgsComposerItem::drawSelectionBoxes ( QPainter *  p  )  [protected, virtual]

Draw selection boxes around item.

Definition at line 440 of file qgscomposeritem.cpp.

References mComposition, QgsComposition::plotStyle(), and QgsComposition::Preview.

Referenced by QgsComposerScaleBar::paint(), QgsComposerPicture::paint(), QgsComposerMap::paint(), QgsComposerLabel::paint(), QgsComposerItemGroup::paint(), and QgsComposerLegend::paintAndDetermineSize().

void QgsComposerItem::drawFrame ( QPainter *  p  )  [protected, virtual]

Draw black frame around item.

Reimplemented in QgsComposerItemGroup.

Definition at line 461 of file qgscomposeritem.cpp.

References mFrame.

Referenced by QgsComposerScaleBar::paint(), QgsComposerPicture::paint(), QgsComposerMap::paint(), QgsComposerLabel::paint(), and QgsComposerLegend::paintAndDetermineSize().

void QgsComposerItem::drawBackground ( QPainter *  p  )  [protected, virtual]

Draw background.

Definition at line 509 of file qgscomposeritem.cpp.

Referenced by QgsComposerScaleBar::paint(), QgsComposerPicture::paint(), QgsComposerMap::paint(), QgsComposerLabel::paint(), and QgsComposerLegend::paintAndDetermineSize().


Member Data Documentation

QgsComposition* QgsComposerItem::mComposition [protected]

Definition at line 140 of file qgscomposeritem.h.

Referenced by QgsComposerItemGroup::drawFrame(), drawSelectionBoxes(), QgsComposerMap::paint(), QgsComposerLegend::paintAndDetermineSize(), QgsComposerItem(), QgsComposerMap::QgsComposerMap(), QgsComposerScaleBar::readXML(), and ~QgsComposerItem().

QgsComposerItem::MouseMoveAction QgsComposerItem::mCurrentMouseMoveAction [protected]

Definition at line 142 of file qgscomposeritem.h.

Referenced by mousePressEvent(), mouseReleaseEvent(), and rectangleChange().

QPointF QgsComposerItem::mMouseMoveStartPos [protected]

Start point of the last mouse move action (in scene coordinates).

Definition at line 144 of file qgscomposeritem.h.

Referenced by mousePressEvent(), and mouseReleaseEvent().

QPointF QgsComposerItem::mLastMouseEventPos [protected]

Position of the last mouse move event (in item coordinates).

Definition at line 146 of file qgscomposeritem.h.

Referenced by mouseMoveEvent(), and mousePressEvent().

QGraphicsRectItem* QgsComposerItem::mBoundingResizeRectangle [protected]

Rectangle used during move and resize actions.

Definition at line 149 of file qgscomposeritem.h.

Referenced by mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and ~QgsComposerItem().

bool QgsComposerItem::mFrame [protected]

True if item fram needs to be painted.

Definition at line 152 of file qgscomposeritem.h.

Referenced by _readXML(), _writeXML(), QgsComposerItemGroup::drawFrame(), and drawFrame().


The documentation for this class was generated from the following files:
Generated on Tue Jan 6 16:51:19 2009 for Quantum GIS API Documentation by  doxygen 1.5.1