QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 "qgscomposerlegendstyle.h"
22 #include "qgscomposeritem.h"
23 #include "qgscomposerlegenditem.h"
24 #include "qgslayertreemodel.h"
25 #include "qgslegendmodel.h"
26 #include "qgslegendsettings.h"
27 
28 class QgsLayerTreeModel;
29 class QgsSymbolV2;
32 class QgsComposerMap;
33 class QgsLegendRenderer;
34 
35 
42 class CORE_EXPORT QgsLegendModelV2 : public QgsLayerTreeModel
43 {
44  public:
45  QgsLegendModelV2( QgsLayerTreeGroup* rootNode, QObject *parent = 0 );
46 
47  QVariant data( const QModelIndex& index, int role ) const;
48 
49  Qt::ItemFlags flags( const QModelIndex &index ) const;
50 };
51 
52 
56 class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
57 {
58  Q_OBJECT;
59 
60  public:
61  QgsComposerLegend( QgsComposition* composition );
63 
65  virtual int type() const { return ComposerLegend; }
66 
68  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
69 
71  QSizeF paintAndDetermineSize( QPainter* painter );
72 
74  void adjustBoxSize();
75 
77 
78  Q_DECL_DEPRECATED QgsLegendModel* model() {return &mLegendModel;}
79 
81  QgsLegendModelV2* modelV2() { return mLegendModel2; }
82 
84  void setAutoUpdateModel( bool autoUpdate );
86  bool autoUpdateModel() const;
87 
90  void setLegendFilterByMapEnabled( bool enabled );
93  bool legendFilterByMapEnabled() const { return mLegendFilterByMap; }
94 
95  //setters and getters
96  void setTitle( const QString& t );
97  QString title() const;
98 
104  Qt::AlignmentFlag titleAlignment() const;
110  void setTitleAlignment( Qt::AlignmentFlag alignment );
111 
116  void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style );
117 
118  QFont styleFont( QgsComposerLegendStyle::Style s ) const;
120  void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f );
121 
123  void setStyleMargin( QgsComposerLegendStyle::Style s, double margin );
124  void setStyleMargin( QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin );
125 
126  double boxSpace() const;
127  void setBoxSpace( double s );
128 
129  double columnSpace() const;
130  void setColumnSpace( double s );
131 
132  QColor fontColor() const;
133  void setFontColor( const QColor& c );
134 
135  double symbolWidth() const;
136  void setSymbolWidth( double w );
137 
138  double symbolHeight() const;
139  void setSymbolHeight( double h );
140 
141  double wmsLegendWidth() const;
142  void setWmsLegendWidth( double w );
143 
144  double wmsLegendHeight() const;
145  void setWmsLegendHeight( double h );
146 
147  void setWrapChar( const QString& t );
148  QString wrapChar() const;
149 
150  int columnCount() const;
151  void setColumnCount( int c );
152 
153  int splitLayer() const;
154  void setSplitLayer( bool s );
155 
156  int equalColumnWidth() const;
157  void setEqualColumnWidth( bool s );
158 
159  void setComposerMap( const QgsComposerMap* map );
160  const QgsComposerMap* composerMap() const { return mComposerMap;}
161 
163  void updateLegend();
164 
169  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
170 
175  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
176 
177  //Overriden to show legend title
178  virtual QString displayName() const;
179 
180  public slots:
182  void synchronizeWithModel();
184  void invalidateCurrentMap();
185 
186  private slots:
187  void updateFilterByMap();
188 
189  private:
190  QgsComposerLegend(); //forbidden
191 
193  void setCustomLayerTree( QgsLayerTreeGroup* rootGroup );
194 
195  QgsLegendModel mLegendModel;
196 
197  QgsLegendModelV2* mLegendModel2;
198  QgsLayerTreeGroup* mCustomLayerTree;
199 
200  QgsLegendSettings mSettings;
201 
202  const QgsComposerMap* mComposerMap;
203 
204  bool mLegendFilterByMap;
205 };
206 
207 #endif
208