QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Slots | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
QgsComposerLabel Class Reference

A label that can be placed onto a map composition. More...

#include <qgscomposerlabel.h>

Inheritance diagram for QgsComposerLabel:
Inheritance graph
[legend]
Collaboration diagram for QgsComposerLabel:
Collaboration graph
[legend]

Public Slots

virtual void setRotation (double r)
- Public Slots inherited from QgsComposerItem
virtual void setRotation (double r)
void repaint ()

Public Member Functions

 QgsComposerLabel (QgsComposition *composition)
 ~QgsComposerLabel ()
virtual int type () const
 return correct graphics item type.
void paint (QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
 Reimplementation of QCanvasItem::paint.
void adjustSizeToText ()
 resizes the widget such that the text fits to the item.
QString text ()
void setText (const QString &text)
int htmlState ()
void setHtmlState (int state)
QString displayText () const
 Returns the text as it appears on screen (with replaced data field)
void setExpressionContext (QgsFeature *feature, QgsVectorLayer *layer, QMap< QString, QVariant > substitutions=(QMap< QString, QVariant >()))
 Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions.
QFont font () const
void setFont (const QFont &f)
Qt::AlignmentFlag vAlign () const
 Accessor for the vertical alignment of the label.
Qt::AlignmentFlag hAlign () const
 Accessor for the horizontal alignment of the label.
void setHAlign (Qt::AlignmentFlag a)
 Mutator for the horizontal alignment of the label.
void setVAlign (Qt::AlignmentFlag a)
 Mutator for the vertical alignment of the label.
double margin ()
 brief Accessor for the margin of the label
void setMargin (double m)
 brief Mutator for the margin of the label
void setFontColor (const QColor &c)
 Sets text color.
QColor fontColor () const
 Get font color.
void setSceneRect (const QRectF &rectangle)
 Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size unit.
bool writeXML (QDomElement &elem, QDomDocument &doc) const
 stores state in Dom element
bool readXML (const QDomElement &itemElem, const QDomDocument &doc)
 sets state from Dom document
- Public Member Functions inherited from QgsComposerItem
 QgsComposerItem (QgsComposition *composition, bool manageZValue=true)
 Constructor.
 QgsComposerItem (qreal x, qreal y, qreal width, qreal height, QgsComposition *composition, bool manageZValue=true)
 Constructor with box position and composer object.
virtual ~QgsComposerItem ()
virtual void setSelected (bool s)
 Set selected, selected item should be highlighted.
virtual bool selected ()
 Is selected.
virtual bool writeSettings ()
 stores state in project
virtual bool readSettings ()
 read state from project
virtual bool removeSettings ()
 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.
void setItemPosition (double x, double y, ItemPositionMode itemPoint=UpperLeft)
 Moves the item to a new position (in canvas coordinates)
void setItemPosition (double x, double y, double width, double height, ItemPositionMode itemPoint=UpperLeft)
 Sets item position and width / height in one go.
ItemPositionMode lastUsedPositionMode ()
 Returns item's last used position mode.
bool _writeXML (QDomElement &itemElem, QDomDocument &doc) const
 Writes parameter that are not subclass specific in document.
bool _readXML (const QDomElement &itemElem, const QDomDocument &doc)
 Reads parameter that are not subclass specific in document.
bool hasFrame () const
 Whether this item has a frame or not.
void setFrameEnabled (bool drawFrame)
 Set whether this item has a frame drawn around it or not.
bool hasBackground () const
 Whether this item has a Background or not.
void setBackgroundEnabled (bool drawBackground)
 Set whether this item has a Background drawn around it or not.
QColor backgroundColor () const
 Gets the background color for this item.
void setBackgroundColor (const QColor &backgroundColor)
 Sets the background color for this item.
QPainter::CompositionMode blendMode () const
 Returns the item's composition blending mode.
void setBlendMode (QPainter::CompositionMode blendMode)
 Sets the item's composition blending mode.
int transparency () const
 Returns the item's transparency.
void setTransparency (int transparency)
 Sets the item's transparency.
bool effectsEnabled () const
 Returns true if effects (eg blend modes) are enabled for the item.
void setEffectsEnabled (bool effectsEnabled)
 Sets whether effects (eg blend modes) are enabled for the item.
virtual void addItem (QgsComposerItem *item)
 Composite operations for item groups do nothing per default.
virtual void removeItems ()
const QgsCompositioncomposition () const
QgsCompositioncomposition ()
virtual void beginItemCommand (const QString &text)
void beginCommand (const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
 Starts new composer undo command.
virtual void endItemCommand ()
void endCommand ()
 Finish current command and push it onto the undo stack.
void cancelCommand ()
void drawText (QPainter *p, double x, double y, const QString &text, const QFont &font) const
 Draws Text.
void drawText (QPainter *p, const QRectF &rect, const QString &text, const QFont &font, Qt::AlignmentFlag halignment=Qt::AlignLeft, Qt::AlignmentFlag valignment=Qt::AlignTop) 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 fontHeightCharacterMM (const QFont &font, const QChar &c) const
 Returns the font height of a character in millimeters.
double fontAscentMillimeters (const QFont &font) const
 Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE.
double fontDescentMillimeters (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.
void setPositionLock (bool lock)
 Locks / unlocks the item position for mouse drags.
bool positionLock () const
 Returns position lock for mouse drags (true means locked)
void updateCursor (const QPointF &itemPos)
 Update mouse cursor at (item) position.
double rotation () const
virtual void updateItem ()
 Updates item, with the possibility to do custom update for subclasses.
QString id () const
 Get item's id (which is not necessarly unique)
virtual void setId (const QString &id)
 Set item's id (which is not necessarly unique)
QString uuid () const
 Get item identification name.

Private Slots

void loadingHtmlFinished (bool)

Private Member Functions

double htmlUnitsToMM ()
void itemShiftAdjustSize (double newWidth, double newHeight, double &xShift, double &yShift) const
 Helper function to calculate x/y shift for adjustSizeToText() depending on rotation, current size and alignment.
void replaceDateText (QString &text) const
 Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g.

Private Attributes

QString mText
int mHtmlState
double mHtmlUnitsToMM
bool mHtmlLoaded
QFont mFont
double mMargin
QColor mFontColor
Qt::AlignmentFlag mHAlignment
Qt::AlignmentFlag mVAlignment
double mTextBoxWidth
 Width of the text box.
double mTextBoxHeight
 Height of the text box.
QgsFeaturemExpressionFeature
QgsVectorLayermExpressionLayer
QMap< QString, QVariant > mSubstitutions

Additional Inherited Members

- Public Types inherited from QgsComposerItem
enum  ItemType {
  ComposerItem = UserType + 100, ComposerArrow, ComposerItemGroup, ComposerLabel,
  ComposerLegend, ComposerMap, ComposerPaper, ComposerPicture,
  ComposerScaleBar, ComposerShape, ComposerTable, ComposerAttributeTable,
  ComposerTextTable, ComposerFrame
}
enum  MouseMoveAction {
  MoveItem, ResizeUp, ResizeDown, ResizeLeft,
  ResizeRight, ResizeLeftUp, ResizeRightUp, ResizeLeftDown,
  ResizeRightDown, NoAction
}
 Describes the action (move or resize in different directon) to be done during mouse move. More...
enum  ItemPositionMode {
  UpperLeft, UpperMiddle, UpperRight, MiddleLeft,
  Middle, MiddleRight, LowerLeft, LowerMiddle,
  LowerRight
}
- Signals inherited from QgsComposerItem
void rotationChanged (double newRotation)
 Is emitted on rotation change to notify north arrow pictures.
void itemChanged ()
 Used e.g.
void sizeChanged ()
 Emitted if the rectangle changes.
- Protected Member Functions inherited from QgsComposerItem
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 changeItemRectangle (const QPointF &currentPosition, const QPointF &mouseMoveStartPos, const QGraphicsRectItem *originalItem, double dx, double dy, QGraphicsRectItem *changeItem)
 Changes the rectangle of an item depending on current mouse action (resize or move)
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.
void drawArrowHead (QPainter *p, double x, double y, double angle, double arrowHeadWidth) const
 Draws arrowhead.
double angle (const QPointF &p1, const QPointF &p2) const
 Returns angle of the line from p1 to p2 (clockwise, starting at N)
double rectHandlerBorderTolerance () const
 Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to the item border for resizing.
double lockSymbolSize () const
 Returns the size of the lock symbol depending on the composer zoom level and the item size.
double horizontalViewScaleFactor () const
 Returns the zoom factor of the graphics view.
bool imageSizeConsideringRotation (double &width, double &height) const
 Calculates width and hight of the picture (in mm) such that it fits into the item frame with the given rotation.
bool cornerPointOnRotatedAndScaledRect (double &x, double &y, double width, double height) const
 Calculates corner point after rotation and scaling.
void sizeChangedByRotation (double &width, double &height)
 Calculates width / height of the bounding box of a rotated rectangle (mRotation)
void rotate (double angle, double &x, double &y) const
 Rotates a point / vector.
QGraphicsLineItem * hAlignSnapItem ()
 Return horizontal align snap item.
void deleteHAlignSnapItem ()
QGraphicsLineItem * vAlignSnapItem ()
 Return vertical align snap item.
void deleteVAlignSnapItem ()
void deleteAlignItems ()
- Protected Attributes inherited from QgsComposerItem
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 scene coordinates)
QGraphicsRectItem * mBoundingResizeRectangle
 Rectangle used during move and resize actions.
QGraphicsLineItem * mHAlignSnapItem
QGraphicsLineItem * mVAlignSnapItem
bool mFrame
 True if item fram needs to be painted.
bool mBackground
 True if item background needs to be painted.
QColor mBackgroundColor
 Background color.
bool mItemPositionLocked
 True if item position and size cannot be changed with mouse move.
double mLastValidViewScaleFactor
 Backup to restore item appearance if no view scale factor is available.
double mRotation
 Item rotation in degrees, clockwise.
QPainter::CompositionMode mBlendMode
 Composition blend mode for item.
bool mEffectsEnabled
QgsComposerEffectmEffect
int mTransparency
 Item transparency.
ItemPositionMode mLastUsedPositionMode
 The item's position mode.

Detailed Description

A label that can be placed onto a map composition.

Definition at line 29 of file qgscomposerlabel.h.

Constructor & Destructor Documentation

QgsComposerLabel::QgsComposerLabel ( QgsComposition composition)

Definition at line 29 of file qgscomposerlabel.cpp.

References htmlUnitsToMM(), mFont, and mHtmlUnitsToMM.

QgsComposerLabel::~QgsComposerLabel ( )

Definition at line 40 of file qgscomposerlabel.cpp.

Member Function Documentation

void QgsComposerLabel::adjustSizeToText ( )
QString QgsComposerLabel::displayText ( ) const

Returns the text as it appears on screen (with replaced data field)

Note
this function was added in version 1.2

Definition at line 173 of file qgscomposerlabel.cpp.

References QgsComposition::itemPageNumber(), QgsComposerItem::mComposition, mExpressionFeature, mExpressionLayer, mSubstitutions, mText, replaceDateText(), and QgsExpression::replaceExpressionText().

Referenced by adjustSizeToText(), and paint().

QFont QgsComposerLabel::font ( ) const

Definition at line 233 of file qgscomposerlabel.cpp.

References mFont.

QColor QgsComposerLabel::fontColor ( ) const
inline

Get font color.

Note
: this function was added in version 1.4

Definition at line 88 of file qgscomposerlabel.h.

Qt::AlignmentFlag QgsComposerLabel::hAlign ( ) const
inline

Accessor for the horizontal alignment of the label.

Returns
Qt::AlignmentFlag

Definition at line 67 of file qgscomposerlabel.h.

int QgsComposerLabel::htmlState ( )
inline

Definition at line 48 of file qgscomposerlabel.h.

double QgsComposerLabel::htmlUnitsToMM ( )
private
void QgsComposerLabel::itemShiftAdjustSize ( double  newWidth,
double  newHeight,
double &  xShift,
double &  yShift 
) const
private

Helper function to calculate x/y shift for adjustSizeToText() depending on rotation, current size and alignment.

Definition at line 358 of file qgscomposerlabel.cpp.

References mHAlignment, QgsComposerItem::mRotation, and mVAlignment.

Referenced by adjustSizeToText().

void QgsComposerLabel::loadingHtmlFinished ( bool  result)
privateslot

Definition at line 141 of file qgscomposerlabel.cpp.

References mHtmlLoaded.

Referenced by paint().

double QgsComposerLabel::margin ( )
inline

brief Accessor for the margin of the label

Definition at line 79 of file qgscomposerlabel.h.

void QgsComposerLabel::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  itemStyle,
QWidget *  pWidget 
)
bool QgsComposerLabel::readXML ( const QDomElement &  itemElem,
const QDomDocument &  doc 
)
virtual

sets state from Dom document

Parameters
itemElemis Dom element corresponding to 'ComposerLabel' tag
docdocument

Implements QgsComposerItem.

Definition at line 298 of file qgscomposerlabel.cpp.

References QgsComposerItem::_readXML(), QgsComposerItem::itemChanged(), mFont, mFontColor, mHAlignment, mHtmlState, mMargin, mText, and mVAlignment.

Referenced by QgsComposition::addItemsFromXML().

void QgsComposerLabel::replaceDateText ( QString &  text) const
private

Replaces replace '$CURRENT_DATE<(FORMAT)>' with the current date (e.g.

$CURRENT_DATE(d 'June' yyyy)

Definition at line 182 of file qgscomposerlabel.cpp.

Referenced by displayText().

void QgsComposerLabel::setExpressionContext ( QgsFeature feature,
QgsVectorLayer layer,
QMap< QString, QVariant >  substitutions = ( QMap<QString, QVariant>() ) 
)

Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions.

Definition at line 164 of file qgscomposerlabel.cpp.

References mExpressionFeature, mExpressionLayer, and mSubstitutions.

void QgsComposerLabel::setFont ( const QFont &  f)

Definition at line 207 of file qgscomposerlabel.cpp.

References mFont.

void QgsComposerLabel::setFontColor ( const QColor &  c)
inline

Sets text color.

Note
: this function was added in version 1.4

Definition at line 85 of file qgscomposerlabel.h.

void QgsComposerLabel::setHAlign ( Qt::AlignmentFlag  a)
inline

Mutator for the horizontal alignment of the label.

Parameters
aalignment
Returns
void

Definition at line 72 of file qgscomposerlabel.h.

void QgsComposerLabel::setHtmlState ( int  state)
inline

Definition at line 49 of file qgscomposerlabel.h.

void QgsComposerLabel::setMargin ( double  m)
inline

brief Mutator for the margin of the label

Definition at line 81 of file qgscomposerlabel.h.

void QgsComposerLabel::setRotation ( double  r)
virtualslot
void QgsComposerLabel::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 from QgsComposerItem.

Definition at line 250 of file qgscomposerlabel.cpp.

References QgsComposerItem::imageSizeConsideringRotation(), mTextBoxHeight, and mTextBoxWidth.

Referenced by adjustSizeToText(), QgsComposerView::mousePressEvent(), and setRotation().

void QgsComposerLabel::setText ( const QString &  text)

Definition at line 158 of file qgscomposerlabel.cpp.

References QgsComposerItem::itemChanged(), mText, and text().

Referenced by QgsComposerView::mousePressEvent().

void QgsComposerLabel::setVAlign ( Qt::AlignmentFlag  a)
inline

Mutator for the vertical alignment of the label.

Parameters
aalignment
Returns
void

Definition at line 77 of file qgscomposerlabel.h.

QString QgsComposerLabel::text ( void  )
inline

Definition at line 45 of file qgscomposerlabel.h.

Referenced by setText().

virtual int QgsComposerLabel::type ( ) const
inlinevirtual

return correct graphics item type.

Added in v1.7

Reimplemented from QgsComposerItem.

Definition at line 37 of file qgscomposerlabel.h.

References QgsComposerItem::ComposerLabel.

Qt::AlignmentFlag QgsComposerLabel::vAlign ( ) const
inline

Accessor for the vertical alignment of the label.

Returns
Qt::AlignmentFlag

Definition at line 63 of file qgscomposerlabel.h.

bool QgsComposerLabel::writeXML ( QDomElement &  elem,
QDomDocument &  doc 
) const
virtual

stores state in Dom element

Parameters
elemis Dom element corresponding to 'Composer' tag
docdocument

Implements QgsComposerItem.

Definition at line 263 of file qgscomposerlabel.cpp.

References QgsComposerItem::_writeXML(), mFont, mFontColor, mHAlignment, mHtmlState, mMargin, mText, and mVAlignment.

Member Data Documentation

QgsFeature* QgsComposerLabel::mExpressionFeature
private

Definition at line 146 of file qgscomposerlabel.h.

Referenced by displayText(), and setExpressionContext().

QgsVectorLayer* QgsComposerLabel::mExpressionLayer
private

Definition at line 147 of file qgscomposerlabel.h.

Referenced by displayText(), and setExpressionContext().

QFont QgsComposerLabel::mFont
private
QColor QgsComposerLabel::mFontColor
private

Definition at line 130 of file qgscomposerlabel.h.

Referenced by paint(), readXML(), and writeXML().

Qt::AlignmentFlag QgsComposerLabel::mHAlignment
private

Definition at line 133 of file qgscomposerlabel.h.

Referenced by itemShiftAdjustSize(), paint(), readXML(), and writeXML().

bool QgsComposerLabel::mHtmlLoaded
private

Definition at line 118 of file qgscomposerlabel.h.

Referenced by loadingHtmlFinished(), and paint().

int QgsComposerLabel::mHtmlState
private

Definition at line 115 of file qgscomposerlabel.h.

Referenced by paint(), readXML(), and writeXML().

double QgsComposerLabel::mHtmlUnitsToMM
private

Definition at line 116 of file qgscomposerlabel.h.

Referenced by paint(), and QgsComposerLabel().

double QgsComposerLabel::mMargin
private

Definition at line 127 of file qgscomposerlabel.h.

Referenced by adjustSizeToText(), paint(), readXML(), and writeXML().

QMap<QString, QVariant> QgsComposerLabel::mSubstitutions
private

Definition at line 148 of file qgscomposerlabel.h.

Referenced by displayText(), and setExpressionContext().

QString QgsComposerLabel::mText
private

Definition at line 112 of file qgscomposerlabel.h.

Referenced by displayText(), readXML(), setText(), and writeXML().

double QgsComposerLabel::mTextBoxHeight
private

Height of the text box.

This is different to rectangle().height() in case there is rotation

Definition at line 144 of file qgscomposerlabel.h.

Referenced by adjustSizeToText(), paint(), setRotation(), and setSceneRect().

double QgsComposerLabel::mTextBoxWidth
private

Width of the text box.

This is different to rectangle().width() in case there is rotation

Definition at line 142 of file qgscomposerlabel.h.

Referenced by adjustSizeToText(), paint(), setRotation(), and setSceneRect().

Qt::AlignmentFlag QgsComposerLabel::mVAlignment
private

Definition at line 136 of file qgscomposerlabel.h.

Referenced by itemShiftAdjustSize(), paint(), readXML(), and writeXML().


The documentation for this class was generated from the following files: