QGIS API Documentation  2.15.0-Master (1f0fce7)
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  Q_OBJECT
45 
46  public:
47  QgsLegendModelV2( QgsLayerTreeGroup* rootNode, QObject *parent = nullptr );
48 
49  QVariant data( const QModelIndex& index, int role ) const override;
50 
51  Qt::ItemFlags flags( const QModelIndex &index ) const override;
52 };
53 
54 
58 class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
59 {
60  Q_OBJECT
61 
62  public:
63  QgsComposerLegend( QgsComposition* composition );
65 
67  virtual int type() const override { return ComposerLegend; }
68 
70  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ) override;
71 
73  QSizeF paintAndDetermineSize( QPainter* painter );
74 
76  void adjustBoxSize();
77 
79  Q_DECL_DEPRECATED QgsLegendModel* model() {return &mLegendModel;}
81 
83  QgsLegendModelV2* modelV2() { return mLegendModel2; }
84 
86  void setAutoUpdateModel( bool autoUpdate );
88  bool autoUpdateModel() const;
89 
92  void setLegendFilterByMapEnabled( bool enabled );
95  bool legendFilterByMapEnabled() const { return mLegendFilterByMap; }
96 
99  virtual void updateItem() override;
100 
104  void setLegendFilterOutAtlas( bool doFilter );
105 
109  bool legendFilterOutAtlas() const;
110 
111  //setters and getters
112  void setTitle( const QString& t );
113  QString title() const;
114 
120  Qt::AlignmentFlag titleAlignment() const;
126  void setTitleAlignment( Qt::AlignmentFlag alignment );
127 
132  void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle& style );
133 
134  QFont styleFont( QgsComposerLegendStyle::Style s ) const;
136  void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f );
137 
139  void setStyleMargin( QgsComposerLegendStyle::Style s, double margin );
140  void setStyleMargin( QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin );
141 
142  double boxSpace() const;
143  void setBoxSpace( double s );
144 
145  double columnSpace() const;
146  void setColumnSpace( double s );
147 
148  QColor fontColor() const;
149  void setFontColor( const QColor& c );
150 
151  double symbolWidth() const;
152  void setSymbolWidth( double w );
153 
154  double symbolHeight() const;
155  void setSymbolHeight( double h );
156 
157  double wmsLegendWidth() const;
158  void setWmsLegendWidth( double w );
159 
160  double wmsLegendHeight() const;
161  void setWmsLegendHeight( double h );
162 
163  void setWrapChar( const QString& t );
164  QString wrapChar() const;
165 
166  int columnCount() const;
167  void setColumnCount( int c );
168 
169  bool splitLayer() const;
170  void setSplitLayer( bool s );
171 
172  bool equalColumnWidth() const;
173  void setEqualColumnWidth( bool s );
174 
181  bool drawRasterBorder() const;
182 
190  void setDrawRasterBorder( bool enabled );
191 
199  QColor rasterBorderColor() const;
200 
209  void setRasterBorderColor( const QColor& color );
210 
218  double rasterBorderWidth() const;
219 
228  void setRasterBorderWidth( double width );
229 
230  void setComposerMap( const QgsComposerMap* map );
231  const QgsComposerMap* composerMap() const { return mComposerMap;}
232 
234  void updateLegend();
235 
240  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
241 
246  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
247 
248  //Overridden to show legend title
249  virtual QString displayName() const override;
250 
251  public slots:
253  void synchronizeWithModel();
255  void invalidateCurrentMap();
256 
257  private slots:
258  void updateFilterByMap( bool redraw = true );
259 
261  void mapLayerStyleOverridesChanged();
262 
264  void onAtlasEnded();
265  void onAtlasFeature( QgsFeature* );
266 
267  void nodeCustomPropertyChanged( QgsLayerTreeNode* node, const QString& key );
268 
269  private:
270  QgsComposerLegend(); //forbidden
271 
273  void setCustomLayerTree( QgsLayerTreeGroup* rootGroup );
274 
275  QgsLegendModel mLegendModel;
276 
277  QgsLegendModelV2* mLegendModel2;
278  QgsLayerTreeGroup* mCustomLayerTree;
279 
280  QgsLegendSettings mSettings;
281 
282  const QgsComposerMap* mComposerMap;
283 
284  bool mLegendFilterByMap;
285  bool mLegendFilterByExpression;
286 
288  bool mFilterOutAtlas;
289 
291  bool mFilterAskedForUpdate;
293  void doUpdateFilterByMap();
294 
295  bool mInAtlas;
296 };
297 
298 #endif
299 
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 feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
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...
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
This class is a base class for nodes in a layer tree.
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