QGIS API Documentation  master-59fd5e0
QgsComposerLegend Class Reference

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

#include <qgscomposerlegend.h>

+ Inheritance diagram for QgsComposerLegend:
+ Collaboration diagram for QgsComposerLegend:

List of all members.

Classes

class  Atom
 Atom is indivisible set (indivisible into more columns). More...
class  Nucleon
 Nucleon is either group title, layer title or layer child item. More...

Public Slots

void invalidateCurrentMap ()
 Sets mCompositionMap to 0 if the map is deleted.
void synchronizeWithModel ()
 Data changed.

Public Member Functions

 QgsComposerLegend (QgsComposition *composition)
 ~QgsComposerLegend ()
void adjustBoxSize ()
 Sets item box to the whole content.
double boxSpace () const
int columnCount () const
double columnSpace () const
const QgsComposerMapcomposerMap () const
int equalColumnWidth () const
QColor fontColor () const
QgsLegendModelmodel ()
 Returns pointer to the legend model.
void paint (QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
 Reimplementation of QCanvasItem::paint.
QSizeF paintAndDetermineSize (QPainter *painter)
 Paints the legend and calculates its size.
bool readXML (const QDomElement &itemElem, const QDomDocument &doc)
 sets state from Dom document
QgsComposerLegendStylerstyle (QgsComposerLegendStyle::Style s)
 Returns reference to modifiable style.
void setBoxSpace (double s)
void setColumnCount (int c)
void setColumnSpace (double s)
void setComposerMap (const QgsComposerMap *map)
void setEqualColumnWidth (bool s)
void setFontColor (const QColor &c)
void setSplitLayer (bool s)
void setStyle (QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style)
void setStyleFont (QgsComposerLegendStyle::Style s, const QFont &f)
 Set style font.
void setStyleMargin (QgsComposerLegendStyle::Style s, double margin)
 Set style margin.
void setStyleMargin (QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin)
void setSymbolHeight (double h)
void setSymbolWidth (double w)
void setTitle (const QString &t)
void setWrapChar (const QString &t)
int splitLayer () const
QgsComposerLegendStyle style (QgsComposerLegendStyle::Style s) const
 Returns style.
QFont styleFont (QgsComposerLegendStyle::Style s) const
double symbolHeight () const
double symbolWidth () const
QString title () const
virtual int type () const
 return correct graphics item type.
void updateLegend ()
 Updates the model and all legend entries.
QString wrapChar () const
bool writeXML (QDomElement &elem, QDomDocument &doc) const
 stores state in Dom node

Protected Attributes

qreal mBoxSpace
 Space between item box and contents.
int mColumnCount
 Number of legend columns.
double mColumnSpace
 Space between columns.
const QgsComposerMapmComposerMap
 Reference to map (because symbols are sometimes in map units)
bool mEqualColumnWidth
 Use the same width (maximum) for all columns.
QColor mFontColor
QgsLegendModel mLegendModel
double mlineSpacing
 Spacing between lines when wrapped.
bool mSplitLayer
 Allow splitting layers into multiple columns.
double mSymbolHeight
 Height of symbol icon.
double mSymbolWidth
 Width of symbol icon.
QString mTitle
QString mWrapChar

Private Member Functions

 QgsComposerLegend ()
QList< AtomcreateAtomList (QStandardItem *rootItem, bool splitLayer)
 Create list of atoms according to current layer splitting mode.
QSizeF drawAtom (Atom atom, QPainter *painter=0, QPointF point=QPointF())
 Draw atom and return its actual size, the atom is drawn with the space above it so that first atoms in column are all aligned to the same line regardles their style top space.
QSizeF drawGroupItemTitle (QgsComposerGroupItem *groupItem, QPainter *painter=0, QPointF point=QPointF())
 Draws a group item and all subitems Returns list of sizes of layers and groups including this group.
QSizeF drawLayerItemTitle (QgsComposerLayerItem *layerItem, QPainter *painter=0, QPointF point=QPointF())
 Draws a layer item and all subitems.
Nucleon drawSymbolItem (QgsComposerLegendItem *symbolItem, QPainter *painter=0, QPointF point=QPointF(), double labelXOffset=0.)
void drawSymbolV2 (QPainter *p, QgsSymbolV2 *s, double currentYCoord, double &currentXPosition, double &symbolHeight) const
 Draws a symbol at the current y position and returns the new x position.
QSizeF drawTitle (QPainter *painter=0, QPointF point=QPointF(), Qt::AlignmentFlag halignment=Qt::AlignLeft)
QStringList layerIdList () const
 Helper function that lists ids of layers contained in map canvas.
void setColumns (QList< Atom > &atomList)
 Divide atoms to columns and set columns on atoms.
double spaceAboveAtom (Atom atom)
QStringList splitStringForWrapping (QString stringToSplt)
 Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping.

Private Attributes

QMap
< QgsComposerLegendStyle::Style,
QgsComposerLegendStyle
mStyleMap

Detailed Description

A legend that can be placed onto a map composition.

Definition at line 34 of file qgscomposerlegend.h.


Constructor & Destructor Documentation

Definition at line 64 of file qgscomposerlegend.cpp.


Member Function Documentation

Sets item box to the whole content.

Definition at line 289 of file qgscomposerlegend.cpp.

References paintAndDetermineSize(), QgsDebugMsg, QgsComposerItem::setSceneRect(), and size.

Referenced by QgsComposerLegend(), synchronizeWithModel(), and updateLegend().

double QgsComposerLegend::boxSpace ( ) const [inline]

Definition at line 76 of file qgscomposerlegend.h.

int QgsComposerLegend::columnCount ( ) const [inline]

Definition at line 94 of file qgscomposerlegend.h.

double QgsComposerLegend::columnSpace ( ) const [inline]

Definition at line 79 of file qgscomposerlegend.h.

Definition at line 104 of file qgscomposerlegend.h.

QSizeF QgsComposerLegend::drawGroupItemTitle ( QgsComposerGroupItem groupItem,
QPainter *  painter = 0,
QPointF  point = QPointF() 
) [private]

Draws a group item and all subitems Returns list of sizes of layers and groups including this group.

Definition at line 235 of file qgscomposerlegend.cpp.

References QgsComposerItem::drawText(), QgsComposerItem::fontAscentMillimeters(), mFontColor, mlineSpacing, size, splitStringForWrapping(), QgsComposerLegendItem::style(), styleFont(), and QgsComposerItem::textWidthMillimeters().

Referenced by createAtomList(), and drawAtom().

QSizeF QgsComposerLegend::drawLayerItemTitle ( QgsComposerLayerItem layerItem,
QPainter *  painter = 0,
QPointF  point = QPointF() 
) [private]
void QgsComposerLegend::drawSymbolV2 ( QPainter *  p,
QgsSymbolV2 s,
double  currentYCoord,
double &  currentXPosition,
double &  symbolHeight 
) const [private]

Draws a symbol at the current y position and returns the new x position.

Returns real symbol height, because for points, it is possible that it differs from mSymbolHeight

Definition at line 417 of file qgscomposerlegend.cpp.

References QgsSymbolV2::drawPreviewIcon(), QgsSymbolV2::MapUnit, QgsComposerMap::mapUnitsToMM(), mComposerMap, QgsSymbolV2::MM, mSymbolHeight, mSymbolWidth, QgsSymbolV2::outputUnit(), rasterScaleFactor, QgsSymbolV2::setOutputUnit(), QgsMarkerSymbolV2::setSize(), size, and QgsMarkerSymbolV2::size().

Referenced by drawSymbolItem().

int QgsComposerLegend::equalColumnWidth ( ) const [inline]

Definition at line 100 of file qgscomposerlegend.h.

QColor QgsComposerLegend::fontColor ( ) const [inline]

Definition at line 82 of file qgscomposerlegend.h.

Sets mCompositionMap to 0 if the map is deleted.

Definition at line 710 of file qgscomposerlegend.cpp.

References mComposerMap.

Referenced by setComposerMap().

QStringList QgsComposerLegend::layerIdList ( ) const [private]

Helper function that lists ids of layers contained in map canvas.

Definition at line 499 of file qgscomposerlegend.cpp.

References QgsMapRenderer::layerSet(), QgsComposition::mapRenderer(), and QgsComposerItem::mComposition.

Referenced by updateLegend().

Returns pointer to the legend model.

Definition at line 56 of file qgscomposerlegend.h.

void QgsComposerLegend::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  itemStyle,
QWidget *  pWidget 
)

Reimplementation of QCanvasItem::paint.

Definition at line 74 of file qgscomposerlegend.cpp.

References paintAndDetermineSize().

Returns reference to modifiable style.

Definition at line 63 of file qgscomposerlegend.h.

Referenced by QgsComposerLegend(), readXML(), setStyleFont(), and setStyleMargin().

void QgsComposerLegend::setBoxSpace ( double  s) [inline]

Definition at line 77 of file qgscomposerlegend.h.

void QgsComposerLegend::setColumnCount ( int  c) [inline]

Definition at line 95 of file qgscomposerlegend.h.

void QgsComposerLegend::setColumnSpace ( double  s) [inline]

Definition at line 80 of file qgscomposerlegend.h.

void QgsComposerLegend::setEqualColumnWidth ( bool  s) [inline]

Definition at line 101 of file qgscomposerlegend.h.

void QgsComposerLegend::setFontColor ( const QColor &  c) [inline]

Definition at line 83 of file qgscomposerlegend.h.

void QgsComposerLegend::setSplitLayer ( bool  s) [inline]

Definition at line 98 of file qgscomposerlegend.h.

Definition at line 66 of file qgscomposerlegend.h.

Referenced by readXML().

Set style font.

Definition at line 520 of file qgscomposerlegend.cpp.

References rstyle(), and QgsComposerLegendStyle::setFont().

Set style margin.

Definition at line 525 of file qgscomposerlegend.cpp.

References rstyle(), and QgsComposerLegendStyle::setMargin().

Referenced by QgsComposerLegend().

void QgsComposerLegend::setSymbolHeight ( double  h) [inline]

Definition at line 89 of file qgscomposerlegend.h.

void QgsComposerLegend::setSymbolWidth ( double  w) [inline]

Definition at line 86 of file qgscomposerlegend.h.

void QgsComposerLegend::setTitle ( const QString &  t) [inline]

Definition at line 59 of file qgscomposerlegend.h.

void QgsComposerLegend::setWrapChar ( const QString &  t) [inline]

Definition at line 91 of file qgscomposerlegend.h.

int QgsComposerLegend::splitLayer ( ) const [inline]

Definition at line 97 of file qgscomposerlegend.h.

QStringList QgsComposerLegend::splitStringForWrapping ( QString  stringToSplt) [private]

Splits a string using the wrap char taking into account handling empty wrap char which means no wrapping.

Definition at line 719 of file qgscomposerlegend.cpp.

References mWrapChar.

Referenced by drawGroupItemTitle(), drawLayerItemTitle(), drawSymbolItem(), and drawTitle().

double QgsComposerLegend::symbolHeight ( ) const [inline]

Definition at line 88 of file qgscomposerlegend.h.

double QgsComposerLegend::symbolWidth ( ) const [inline]

Definition at line 85 of file qgscomposerlegend.h.

Data changed.

Definition at line 513 of file qgscomposerlegend.cpp.

References adjustBoxSize(), and QgsDebugMsg.

Referenced by QgsComposerLegend().

QString QgsComposerLegend::title ( ) const [inline]

Definition at line 60 of file qgscomposerlegend.h.

virtual int QgsComposerLegend::type ( ) const [inline, virtual]

return correct graphics item type.

Added in v1.7

Reimplemented from QgsComposerItem.

Definition at line 43 of file qgscomposerlegend.h.

References QgsComposerItem::ComposerLegend.

Referenced by createAtomList(), drawAtom(), setColumns(), and spaceAboveAtom().

Updates the model and all legend entries.

Definition at line 535 of file qgscomposerlegend.cpp.

References adjustBoxSize(), layerIdList(), mLegendModel, and QgsLegendModel::setLayerSet().

Referenced by QgsComposerView::mousePressEvent().

QString QgsComposerLegend::wrapChar ( ) const [inline]

Definition at line 92 of file qgscomposerlegend.h.


Member Data Documentation

qreal QgsComposerLegend::mBoxSpace [protected]

Space between item box and contents.

Definition at line 134 of file qgscomposerlegend.h.

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

Number of legend columns.

Definition at line 147 of file qgscomposerlegend.h.

Referenced by paintAndDetermineSize(), readXML(), setColumns(), and writeXML().

double QgsComposerLegend::mColumnSpace [protected]

Space between columns.

Definition at line 136 of file qgscomposerlegend.h.

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

Reference to map (because symbols are sometimes in map units)

Definition at line 152 of file qgscomposerlegend.h.

Referenced by drawSymbolV2(), invalidateCurrentMap(), readXML(), setComposerMap(), and writeXML().

Use the same width (maximum) for all columns.

Definition at line 158 of file qgscomposerlegend.h.

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

double QgsComposerLegend::mlineSpacing [protected]

Spacing between lines when wrapped.

Definition at line 144 of file qgscomposerlegend.h.

Referenced by drawGroupItemTitle(), drawLayerItemTitle(), drawSymbolItem(), drawTitle(), and QgsComposerLegend().

Allow splitting layers into multiple columns.

Definition at line 155 of file qgscomposerlegend.h.

Referenced by createAtomList(), paintAndDetermineSize(), readXML(), and writeXML().

Height of symbol icon.

Definition at line 141 of file qgscomposerlegend.h.

Referenced by drawSymbolItem(), drawSymbolV2(), QgsComposerLegend(), readXML(), and writeXML().

double QgsComposerLegend::mSymbolWidth [protected]

Width of symbol icon.

Definition at line 139 of file qgscomposerlegend.h.

Referenced by drawSymbolItem(), drawSymbolV2(), QgsComposerLegend(), readXML(), and writeXML().

QString QgsComposerLegend::mTitle [protected]

Definition at line 128 of file qgscomposerlegend.h.

Referenced by drawTitle(), paintAndDetermineSize(), readXML(), and writeXML().

QString QgsComposerLegend::mWrapChar [protected]

Definition at line 129 of file qgscomposerlegend.h.

Referenced by QgsComposerLegend(), readXML(), splitStringForWrapping(), and writeXML().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines