1
/***************************************************************************
2
qgscomposerlegend.h - description
5
copyright : (C) 2008 by Marco Hugentobler
6
email : marco dot hugentobler at karto dot baug dot ethz dot ch
7
***************************************************************************/
9
/***************************************************************************
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. *
16
***************************************************************************/
18
#ifndef QGSCOMPOSERLEGEND_H
19
#define QGSCOMPOSERLEGEND_H
21
#include "qgscomposeritem.h"
22
#include "qgslegendmodel.h"
26
/** \ingroup MapComposer
27
* A legend that can be placed onto a map composition
29
class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
34
QgsComposerLegend( QgsComposition* composition );
37
/** \brief Reimplementation of QCanvasItem::paint*/
38
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
40
/**Paints the legend and calculates its size. If painter is 0, only size is calculated*/
41
QSizeF paintAndDetermineSize( QPainter* painter );
43
/**Sets item box to the whole content*/
46
/**Returns pointer to the legend model*/
47
QgsLegendModel* model() {return &mLegendModel;}
50
void setTitle( const QString& t ) {mTitle = t;}
51
QString title() const {return mTitle;}
53
QFont titleFont() const;
54
void setTitleFont( const QFont& f );
56
QFont layerFont() const;
57
void setLayerFont( const QFont& f );
59
QFont itemFont() const;
60
void setItemFont( const QFont& f );
62
double boxSpace() const {return mBoxSpace;}
63
void setBoxSpace( double s ) {mBoxSpace = s;}
65
double layerSpace() const {return mLayerSpace;}
66
void setLayerSpace( double s ) {mLayerSpace = s;}
68
double symbolSpace() const {return mSymbolSpace;}
69
void setSymbolSpace( double s ) {mSymbolSpace = s;}
71
double iconLabelSpace() const {return mIconLabelSpace;}
72
void setIconLabelSpace( double s ) {mIconLabelSpace = s;}
74
double symbolWidth() const {return mSymbolWidth;}
75
void setSymbolWidth( double w ) {mSymbolWidth = w;}
77
double symbolHeight() const {return mSymbolHeight;}
78
void setSymbolHeight( double h ) {mSymbolHeight = h;}
80
/**Updates the model and all legend entries*/
83
/** stores state in Dom node
84
* @param elem is Dom element corresponding to 'Composer' tag
85
* @param temp write template file
87
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
89
/** sets state from Dom document
90
* @param itemElem is Dom node corresponding to item tag
92
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
96
void synchronizeWithModel();
101
//different fonts for entries
106
/**Space between item box and contents*/
108
/**Vertical space between layer entries*/
110
/**Vertical space between symbol entries*/
112
/**Horizontal space between item icon and label*/
113
double mIconLabelSpace;
114
/**Width of symbol icon*/
116
/**Height of symbol icon*/
117
double mSymbolHeight;
119
QgsLegendModel mLegendModel;
123
QgsComposerLegend(); //forbidden
125
/**Draws child items of a layer item
126
@param layerItem parent model item (layer)
127
@param currentYCoord in/out: current y position of legend item
128
@param maxXCoord in/out: maximum x-coordinate of the whole legend
129
@param layerOpacity opacity of the corresponding map layer
131
void drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord, int layerOpacity = 255 );
133
/**Draws a symbol at the current y position and returns the new x position. Returns real symbol height, because for points,
134
it is possible that it differs from mSymbolHeight*/
135
void drawSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const;
136
void drawPointSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity = 255 ) const;
137
void drawLineSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const;
138
void drawPolygonSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const;
140
/**Helper function that lists ids of layers contained in map canvas*/
141
QStringList layerIdList() const;