QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
88  //setters and getters
89  void setTitle( const QString& t );
90  QString title() const;
91 
97  Qt::AlignmentFlag titleAlignment() const;
103  void setTitleAlignment( Qt::AlignmentFlag alignment );
104 
109  void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style );
110 
111  QFont styleFont( QgsComposerLegendStyle::Style s ) const;
113  void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f );
114 
116  void setStyleMargin( QgsComposerLegendStyle::Style s, double margin );
117  void setStyleMargin( QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin );
118 
119  double boxSpace() const;
120  void setBoxSpace( double s );
121 
122  double columnSpace() const;
123  void setColumnSpace( double s );
124 
125  QColor fontColor() const;
126  void setFontColor( const QColor& c );
127 
128  double symbolWidth() const;
129  void setSymbolWidth( double w );
130 
131  double symbolHeight() const;
132  void setSymbolHeight( double h );
133 
134  double wmsLegendWidth() const;
135  void setWmsLegendWidth( double w );
136 
137  double wmsLegendHeight() const;
138  void setWmsLegendHeight( double h );
139 
140  void setWrapChar( const QString& t );
141  QString wrapChar() const;
142 
143  int columnCount() const;
144  void setColumnCount( int c );
145 
146  int splitLayer() const;
147  void setSplitLayer( bool s );
148 
149  int equalColumnWidth() const;
150  void setEqualColumnWidth( bool s );
151 
152  void setComposerMap( const QgsComposerMap* map );
153  const QgsComposerMap* composerMap() const { return mComposerMap;}
154 
156  void updateLegend();
157 
162  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
163 
168  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
169 
170  //Overriden to show legend title
171  virtual QString displayName() const;
172 
173  public slots:
175  void synchronizeWithModel();
177  void invalidateCurrentMap();
178 
179  private:
180  QgsComposerLegend(); //forbidden
181 
183  void setCustomLayerTree( QgsLayerTreeGroup* rootGroup );
184 
186 
189 
191 
193 };
194 
195 #endif
196 
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.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Item model implementation based on layer tree model for composer legend.
A item that forms part of a map composition.
QgsLegendModelV2 * modelV2()
QgsLegendModel mLegendModel
Flags flags() const
Return OR-ed combination of model flags.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
const QgsComposerMap * mComposerMap
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
QgsLegendModelV2 * mLegendModel2
Graphics scene for map printing.
Object representing map window.
virtual QString displayName() const
Get item display name.
Composer legend components style.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
const QgsComposerMap * composerMap() const
QgsLegendSettings mSettings
A legend that can be placed onto a map composition.
virtual int type() const
return correct graphics item type.
QgsLayerTreeGroup * mCustomLayerTree
The QgsLegendRenderer class handles automatic layout and rendering of legend.