Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgscomposerlegend.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlegend.h - description
3  -------------------
4  begin : June 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : marco dot hugentobler at karto dot baug dot ethz dot ch
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 
18 #ifndef QGSCOMPOSERLEGEND_H
19 #define QGSCOMPOSERLEGEND_H
20 
21 #include "qgscomposeritem.h"
22 #include "qgslegendmodel.h"
23 
24 class QgsSymbol;
25 class QgsSymbolV2;
28 class QgsComposerMap;
29 
33 class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
34 {
35  Q_OBJECT
36 
37  public:
38  QgsComposerLegend( QgsComposition* composition );
40 
42  virtual int type() const { return ComposerLegend; }
43 
45  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
46 
48  QSizeF paintAndDetermineSize( QPainter* painter );
49 
51  void adjustBoxSize();
52 
54  QgsLegendModel* model() {return &mLegendModel;}
55 
56  //setters and getters
57  void setTitle( const QString& t ) {mTitle = t;}
58  QString title() const {return mTitle;}
59 
60  QFont titleFont() const;
61  void setTitleFont( const QFont& f );
62 
63  QFont groupFont() const;
64  void setGroupFont( const QFont& f );
65 
66  QFont layerFont() const;
67  void setLayerFont( const QFont& f );
68 
69  QFont itemFont() const;
70  void setItemFont( const QFont& f );
71 
72  double boxSpace() const {return mBoxSpace;}
73  void setBoxSpace( double s ) {mBoxSpace = s;}
74 
75  double layerSpace() const {return mLayerSpace;}
76  void setLayerSpace( double s ) {mLayerSpace = s;}
77 
78  double symbolSpace() const {return mSymbolSpace;}
79  void setSymbolSpace( double s ) {mSymbolSpace = s;}
80 
81  double iconLabelSpace() const {return mIconLabelSpace;}
82  void setIconLabelSpace( double s ) {mIconLabelSpace = s;}
83 
84  double symbolWidth() const {return mSymbolWidth;}
85  void setSymbolWidth( double w ) {mSymbolWidth = w;}
86 
87  double symbolHeight() const {return mSymbolHeight;}
88  void setSymbolHeight( double h ) {mSymbolHeight = h;}
89 
90  void setComposerMap( const QgsComposerMap* map );
91  const QgsComposerMap* composerMap() const { return mComposerMap; }
92 
94  void updateLegend();
95 
100  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
101 
106  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
107 
108  public slots:
110  void synchronizeWithModel();
112  void invalidateCurrentMap();
113 
114  protected:
115  QString mTitle;
116 
117  //different fonts for entries
118  QFont mTitleFont;
119  QFont mGroupFont;
120  QFont mLayerFont;
121  QFont mItemFont;
122 
124  double mBoxSpace;
126  double mLayerSpace;
128  double mSymbolSpace;
132  double mSymbolWidth;
135 
137 
140 
141 
142  private:
143  QgsComposerLegend(); //forbidden
144 
146  void drawGroupItem( QPainter* p, QgsComposerGroupItem* groupItem, double& currentYCoord, double& maxXCoord );
148  void drawLayerItem( QPainter* p, QgsComposerLayerItem* layerItem, double& currentYCoord, double& maxXCoord );
149 
157  void drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord, int layerOpacity = 255 );
158 
161  void drawSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const;
162  void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const;
163  void drawPointSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity = 255 ) const;
164  void drawLineSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const;
165  void drawPolygonSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const;
166 
168  QStringList layerIdList() const;
169 };
170 
171 #endif