QGIS API Documentation  2.10.1-Pisa
 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 override;
48 
49  Qt::ItemFlags flags( const QModelIndex &index ) const override;
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 override { return ComposerLegend; }
66 
68  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
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 override;
170 
175  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
176 
177  //Overriden to show legend title
178  virtual QString displayName() const override;
179 
180  public slots:
182  void synchronizeWithModel();
184  void invalidateCurrentMap();
185 
186  private slots:
187  void updateFilterByMap();
188 
190  void mapLayerStyleOverridesChanged();
191 
192  private:
193  QgsComposerLegend(); //forbidden
194 
196  void setCustomLayerTree( QgsLayerTreeGroup* rootGroup );
197 
198  QgsLegendModel mLegendModel;
199 
200  QgsLegendModelV2* mLegendModel2;
201  QgsLayerTreeGroup* mCustomLayerTree;
202 
203  QgsLegendSettings mSettings;
204 
205  const QgsComposerMap* mComposerMap;
206 
207  bool mLegendFilterByMap;
208 };
209 
210 #endif
211 
Layer tree group node serves as a container for layers and further groups.
static unsigned index
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
A model that provides group, layer and classification items.
Item model implementation based on layer tree model for composer legend.
A item that forms part of a map composition.
QgsLegendModelV2 * modelV2()
Flags flags() const
Return OR-ed combination of model flags.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
bool legendFilterByMapEnabled() const
Find out whether legend items are filtered to show just the ones visible in the associated map...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Graphics scene for map printing.
Object representing map window.
virtual QString displayName() const
Get item display name.
Composer legend components style.
virtual int type() const override
return correct graphics item type.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
const QgsComposerMap * composerMap() const
A legend that can be placed onto a map composition.
The QgsLegendRenderer class handles automatic layout and rendering of legend.
typedef ItemFlags