QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  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 
Layer tree group node serves as a container for layers and further groups.
Definition: qgslayertreegroup.h:31
static unsigned index
Definition: mersenne-twister.cpp:36
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
Definition: qgscomposerobject.cpp:61
A model that provides group, layer and classification items.
Definition: qgslegendmodel.h:40
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: qgslayertreemodel.cpp:168
Item model implementation based on layer tree model for composer legend.
Definition: qgscomposerlegend.h:42
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
QgsLegendModelV2 * modelV2()
Definition: qgscomposerlegend.h:81
Flags flags() const
Return OR-ed combination of model flags.
Definition: qgslayertreemodel.cpp:1061
Definition: qgscomposerlegenditem.h:122
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Definition: qgslayertreemodel.h:46
bool legendFilterByMapEnabled() const
Find out whether legend items are filtered to show just the ones visible in the associated map...
Definition: qgscomposerlegend.h:93
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:36
Definition: qgssymbolv2.h:43
Graphics scene for map printing.
Definition: qgscomposition.h:72
Object representing map window.
Definition: qgscomposermap.h:46
Definition: qgscomposeritem.h:52
virtual QString displayName() const
Get item display name.
Definition: qgscomposeritem.cpp:1355
Composer legend components style.
Definition: qgscomposerlegendstyle.h:30
Style
Definition: qgscomposerlegendstyle.h:33
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Definition: qgscomposerobject.cpp:74
const QgsComposerMap * composerMap() const
Definition: qgscomposerlegend.h:160
Side
Definition: qgscomposerlegendstyle.h:43
Definition: qgscomposerlegenditem.h:149
A legend that can be placed onto a map composition.
Definition: qgscomposerlegend.h:56
virtual int type() const
return correct graphics item type.
Definition: qgscomposerlegend.h:65
The QgsLegendRenderer class handles automatic layout and rendering of legend.
Definition: qgslegendrenderer.h:42