QGIS API Documentation  2.12.0-Lyon
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  bool splitLayer() const;
154  void setSplitLayer( bool s );
155 
156  bool equalColumnWidth() const;
157  void setEqualColumnWidth( bool s );
158 
165  bool drawRasterBorder() const;
166 
174  void setDrawRasterBorder( bool enabled );
175 
183  QColor rasterBorderColor() const;
184 
193  void setRasterBorderColor( const QColor& color );
194 
202  double rasterBorderWidth() const;
203 
212  void setRasterBorderWidth( double width );
213 
214  void setComposerMap( const QgsComposerMap* map );
215  const QgsComposerMap* composerMap() const { return mComposerMap;}
216 
218  void updateLegend();
219 
224  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
225 
230  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
231 
232  //Overridden to show legend title
233  virtual QString displayName() const override;
234 
235  public slots:
237  void synchronizeWithModel();
239  void invalidateCurrentMap();
240 
241  private slots:
242  void updateFilterByMap();
243 
245  void mapLayerStyleOverridesChanged();
246 
247  private:
248  QgsComposerLegend(); //forbidden
249 
251  void setCustomLayerTree( QgsLayerTreeGroup* rootGroup );
252 
253  QgsLegendModel mLegendModel;
254 
255  QgsLegendModelV2* mLegendModel2;
256  QgsLayerTreeGroup* mCustomLayerTree;
257 
258  QgsLegendSettings mSettings;
259 
260  const QgsComposerMap* mComposerMap;
261 
262  bool mLegendFilterByMap;
263 };
264 
265 #endif
266 
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