QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgscomposerlegend.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlegend.cpp - 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 #include <limits>
18 
19 #include "qgscomposerlegendstyle.h"
20 #include "qgscomposerlegend.h"
21 #include "qgscomposerlegenditem.h"
22 #include "qgscomposermap.h"
23 #include "qgscomposition.h"
24 #include "qgscomposermodel.h"
25 #include "qgslayertree.h"
26 #include "qgslayertreemodel.h"
27 #include "qgslegendrenderer.h"
28 #include "qgslogger.h"
29 #include "qgsproject.h"
30 #include <QDomDocument>
31 #include <QDomElement>
32 #include <QPainter>
33 
35  : QgsComposerItem( composition )
36  , mCustomLayerTree( 0 )
37  , mComposerMap( 0 )
38 {
39  mLegendModel2 = new QgsLegendModelV2( QgsProject::instance()->layerTreeRoot() );
40 
41  adjustBoxSize();
42 
43  connect( &mLegendModel, SIGNAL( layersChanged() ), this, SLOT( synchronizeWithModel() ) );
44 }
45 
47  : QgsComposerItem( 0 )
48  , mLegendModel2( 0 )
49  , mCustomLayerTree( 0 )
50  , mComposerMap( 0 )
51 {
52 
53 }
54 
56 {
57  delete mLegendModel2;
58  delete mCustomLayerTree;
59 }
60 
61 void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
62 {
63  Q_UNUSED( itemStyle );
64  Q_UNUSED( pWidget );
65 
66  if ( !painter )
67  return;
68 
69  int dpi = painter->device()->logicalDpiX();
70  double dotsPerMM = dpi / 25.4;
71 
72  if ( mComposition )
73  {
75  mSettings.setDpi( dpi );
76  }
77  if ( mComposerMap )
78  {
80 
81  // use a temporary QgsMapSettings to find out real map scale
83  ms.setOutputSize( QSizeF( mComposerMap->rect().width() * dotsPerMM, mComposerMap->rect().height() * dotsPerMM ).toSize() );
85  ms.setOutputDpi( dpi );
86  mSettings.setMapScale( ms.scale() );
87  }
88 
89  drawBackground( painter );
90  painter->save();
91  //antialiasing on
92  painter->setRenderHint( QPainter::Antialiasing, true );
93  painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
94 
95  QgsLegendRenderer legendRenderer( mLegendModel2, mSettings );
96  legendRenderer.setLegendSize( rect().size() );
97  legendRenderer.drawLegend( painter );
98 
99  painter->restore();
100 
101  //draw frame and selection boxes if necessary
102  drawFrame( painter );
103  if ( isSelected() )
104  {
105  drawSelectionBoxes( painter );
106  }
107 }
108 
109 QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
110 {
111  QgsLegendRenderer legendRenderer( mLegendModel2, mSettings );
112  QSizeF size = legendRenderer.minimumSize();
113  if ( !painter )
114  legendRenderer.drawLegend( painter );
115  return size;
116 }
117 
118 
120 {
121  QgsLegendRenderer legendRenderer( mLegendModel2, mSettings );
122  QSizeF size = legendRenderer.minimumSize();
123  QgsDebugMsg( QString( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
124  if ( size.isValid() )
125  {
126  setSceneRect( QRectF( pos().x(), pos().y(), size.width(), size.height() ) );
127  }
128 }
129 
130 
132 {
133  mLegendModel2->setRootGroup( rootGroup ? rootGroup : QgsProject::instance()->layerTreeRoot() );
134 
135  delete mCustomLayerTree;
136  mCustomLayerTree = rootGroup;
137 }
138 
139 
141 {
142  if ( autoUpdate == autoUpdateModel() )
143  return;
144 
145  setCustomLayerTree( autoUpdate ? 0 : QgsLayerTree::toGroup( QgsProject::instance()->layerTreeRoot()->clone() ) );
146 }
147 
149 {
150  return !mCustomLayerTree;
151 }
152 
153 void QgsComposerLegend::setTitle( const QString& t )
154 {
155  mSettings.setTitle( t );
156 
157  if ( mComposition && id().isEmpty() )
158  {
159  //notify the model that the display name has changed
161  }
162 }
163 QString QgsComposerLegend::title() const { return mSettings.title(); }
164 
165 Qt::AlignmentFlag QgsComposerLegend::titleAlignment() const { return mSettings.titleAlignment(); }
166 void QgsComposerLegend::setTitleAlignment( Qt::AlignmentFlag alignment ) { mSettings.setTitleAlignment( alignment ); }
167 
171 
174 
177 
178 double QgsComposerLegend::boxSpace() const { return mSettings.boxSpace(); }
180 
183 
185 void QgsComposerLegend::setFontColor( const QColor& c ) { mSettings.setFontColor( c ); }
186 
187 double QgsComposerLegend::symbolWidth() const { return mSettings.symbolSize().width(); }
188 void QgsComposerLegend::setSymbolWidth( double w ) { mSettings.setSymbolSize( QSizeF( w, mSettings.symbolSize().height() ) ); }
189 
190 double QgsComposerLegend::symbolHeight() const { return mSettings.symbolSize().height(); }
191 void QgsComposerLegend::setSymbolHeight( double h ) { mSettings.setSymbolSize( QSizeF( mSettings.symbolSize().width(), h ) ); }
192 
193 double QgsComposerLegend::wmsLegendWidth() const { return mSettings.wmsLegendSize().width(); }
195 
196 double QgsComposerLegend::wmsLegendHeight() const {return mSettings.wmsLegendSize().height(); }
198 
199 void QgsComposerLegend::setWrapChar( const QString& t ) { mSettings.setWrapChar( t ); }
200 QString QgsComposerLegend::wrapChar() const {return mSettings.wrapChar(); }
201 
204 
207 
210 
211 
213 {
214  QgsDebugMsg( "Entered" );
215  adjustBoxSize();
216  update();
217 }
218 
220 {
221  // take layer list from map renderer (to have legend order)
223  adjustBoxSize();
224  update();
225 }
226 
227 bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
228 {
229  if ( elem.isNull() )
230  {
231  return false;
232  }
233 
234  QDomElement composerLegendElem = doc.createElement( "ComposerLegend" );
235  elem.appendChild( composerLegendElem );
236 
237  //write general properties
238  composerLegendElem.setAttribute( "title", mSettings.title() );
239  composerLegendElem.setAttribute( "titleAlignment", QString::number(( int ) mSettings.titleAlignment() ) );
240  composerLegendElem.setAttribute( "columnCount", QString::number( mSettings.columnCount() ) );
241  composerLegendElem.setAttribute( "splitLayer", QString::number( mSettings.splitLayer() ) );
242  composerLegendElem.setAttribute( "equalColumnWidth", QString::number( mSettings.equalColumnWidth() ) );
243 
244  composerLegendElem.setAttribute( "boxSpace", QString::number( mSettings.boxSpace() ) );
245  composerLegendElem.setAttribute( "columnSpace", QString::number( mSettings.columnSpace() ) );
246 
247  composerLegendElem.setAttribute( "symbolWidth", QString::number( mSettings.symbolSize().width() ) );
248  composerLegendElem.setAttribute( "symbolHeight", QString::number( mSettings.symbolSize().height() ) );
249  composerLegendElem.setAttribute( "wmsLegendWidth", QString::number( mSettings.wmsLegendSize().width() ) );
250  composerLegendElem.setAttribute( "wmsLegendHeight", QString::number( mSettings.wmsLegendSize().height() ) );
251  composerLegendElem.setAttribute( "wrapChar", mSettings.wrapChar() );
252  composerLegendElem.setAttribute( "fontColor", mSettings.fontColor().name() );
253 
254  if ( mComposerMap )
255  {
256  composerLegendElem.setAttribute( "map", mComposerMap->id() );
257  }
258 
259  QDomElement composerLegendStyles = doc.createElement( "styles" );
260  composerLegendElem.appendChild( composerLegendStyles );
261 
262  style( QgsComposerLegendStyle::Title ).writeXML( "title", composerLegendStyles, doc );
263  style( QgsComposerLegendStyle::Group ).writeXML( "group", composerLegendStyles, doc );
264  style( QgsComposerLegendStyle::Subgroup ).writeXML( "subgroup", composerLegendStyles, doc );
265  style( QgsComposerLegendStyle::Symbol ).writeXML( "symbol", composerLegendStyles, doc );
266  style( QgsComposerLegendStyle::SymbolLabel ).writeXML( "symbolLabel", composerLegendStyles, doc );
267 
268  if ( mCustomLayerTree )
269  {
270  // if not using auto-update - store the custom layer tree
271  mCustomLayerTree->writeXML( composerLegendElem );
272  }
273 
274  return _writeXML( composerLegendElem, doc );
275 }
276 
277 bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument& doc )
278 {
279  if ( itemElem.isNull() )
280  {
281  return false;
282  }
283 
284  //read general properties
285  mSettings.setTitle( itemElem.attribute( "title" ) );
286  if ( !itemElem.attribute( "titleAlignment" ).isEmpty() )
287  {
288  mSettings.setTitleAlignment(( Qt::AlignmentFlag )itemElem.attribute( "titleAlignment" ).toInt() );
289  }
290  int colCount = itemElem.attribute( "columnCount", "1" ).toInt();
291  if ( colCount < 1 ) colCount = 1;
292  mSettings.setColumnCount( colCount );
293  mSettings.setSplitLayer( itemElem.attribute( "splitLayer", "0" ).toInt() == 1 );
294  mSettings.setEqualColumnWidth( itemElem.attribute( "equalColumnWidth", "0" ).toInt() == 1 );
295 
296  QDomNodeList stylesNodeList = itemElem.elementsByTagName( "styles" );
297  if ( stylesNodeList.size() > 0 )
298  {
299  QDomNode stylesNode = stylesNodeList.at( 0 );
300  for ( int i = 0; i < stylesNode.childNodes().size(); i++ )
301  {
302  QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
304  style.readXML( styleElem, doc );
305  QString name = styleElem.attribute( "name" );
307  if ( name == "title" ) s = QgsComposerLegendStyle::Title;
308  else if ( name == "group" ) s = QgsComposerLegendStyle::Group;
309  else if ( name == "subgroup" ) s = QgsComposerLegendStyle::Subgroup;
310  else if ( name == "symbol" ) s = QgsComposerLegendStyle::Symbol;
311  else if ( name == "symbolLabel" ) s = QgsComposerLegendStyle::SymbolLabel;
312  else continue;
313  setStyle( s, style );
314  }
315  }
316 
317  //font color
318  QColor fontClr;
319  fontClr.setNamedColor( itemElem.attribute( "fontColor", "#000000" ) );
320  mSettings.setFontColor( fontClr );
321 
322  //spaces
323  mSettings.setBoxSpace( itemElem.attribute( "boxSpace", "2.0" ).toDouble() );
324  mSettings.setColumnSpace( itemElem.attribute( "columnSpace", "2.0" ).toDouble() );
325 
326  mSettings.setSymbolSize( QSizeF( itemElem.attribute( "symbolWidth", "7.0" ).toDouble(), itemElem.attribute( "symbolHeight", "14.0" ).toDouble() ) );
327  mSettings.setWmsLegendSize( QSizeF( itemElem.attribute( "wmsLegendWidth", "50" ).toDouble(), itemElem.attribute( "wmsLegendHeight", "25" ).toDouble() ) );
328 
329  mSettings.setWrapChar( itemElem.attribute( "wrapChar" ) );
330 
331  //composer map
332  if ( !itemElem.attribute( "map" ).isEmpty() )
333  {
334  mComposerMap = mComposition->getComposerMapById( itemElem.attribute( "map" ).toInt() );
335  }
336 
337  QDomElement layerTreeElem = itemElem.firstChildElement( "layer-tree-group" );
339 
340  //restore general composer item properties
341  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
342  if ( composerItemList.size() > 0 )
343  {
344  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
345  _readXML( composerItemElem, doc );
346  }
347 
348  // < 2.0 projects backward compatibility >>>>>
349  //title font
350  QString titleFontString = itemElem.attribute( "titleFont" );
351  if ( !titleFontString.isEmpty() )
352  {
353  rstyle( QgsComposerLegendStyle::Title ).rfont().fromString( titleFontString );
354  }
355  //group font
356  QString groupFontString = itemElem.attribute( "groupFont" );
357  if ( !groupFontString.isEmpty() )
358  {
359  rstyle( QgsComposerLegendStyle::Group ).rfont().fromString( groupFontString );
360  }
361 
362  //layer font
363  QString layerFontString = itemElem.attribute( "layerFont" );
364  if ( !layerFontString.isEmpty() )
365  {
366  rstyle( QgsComposerLegendStyle::Subgroup ).rfont().fromString( layerFontString );
367  }
368  //item font
369  QString itemFontString = itemElem.attribute( "itemFont" );
370  if ( !itemFontString.isEmpty() )
371  {
372  rstyle( QgsComposerLegendStyle::SymbolLabel ).rfont().fromString( itemFontString );
373  }
374 
375  if ( !itemElem.attribute( "groupSpace" ).isEmpty() )
376  {
377  rstyle( QgsComposerLegendStyle::Group ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "groupSpace", "3.0" ).toDouble() );
378  }
379  if ( !itemElem.attribute( "layerSpace" ).isEmpty() )
380  {
381  rstyle( QgsComposerLegendStyle::Subgroup ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "layerSpace", "3.0" ).toDouble() );
382  }
383  if ( !itemElem.attribute( "symbolSpace" ).isEmpty() )
384  {
385  rstyle( QgsComposerLegendStyle::Symbol ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
386  rstyle( QgsComposerLegendStyle::SymbolLabel ).setMargin( QgsComposerLegendStyle::Top, itemElem.attribute( "symbolSpace", "2.0" ).toDouble() );
387  }
388  // <<<<<<< < 2.0 projects backward compatibility
389 
390  emit itemChanged();
391  return true;
392 }
393 
395 {
396  if ( !id().isEmpty() )
397  {
398  return id();
399  }
400 
401  //if no id, default to portion of title text
402  QString text = mSettings.title();
403  if ( text.isEmpty() )
404  {
405  return tr( "<legend>" );
406  }
407  if ( text.length() > 25 )
408  {
409  return QString( tr( "%1..." ) ).arg( text.left( 25 ) );
410  }
411  else
412  {
413  return text;
414  }
415 }
416 
418 {
419  mComposerMap = map;
420  if ( map )
421  {
422  QObject::connect( map, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
423  }
424 }
425 
427 {
428  if ( mComposerMap )
429  {
430  disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
431  }
432  mComposerMap = 0;
433 }
434 
435 // -------------------------------------------------------------------------
437 #include "qgsvectorlayer.h"
438 
440  : QgsLayerTreeModel( rootNode, parent )
441 {
444 }
445 
446 QVariant QgsLegendModelV2::data( const QModelIndex& index, int role ) const
447 {
448  // handle custom layer node labels
449  if ( QgsLayerTreeNode* node = index2node( index ) )
450  {
451  if ( QgsLayerTree::isLayer( node ) && ( role == Qt::DisplayRole || role == Qt::EditRole ) && !node->customProperty( "legend/title-label" ).isNull() )
452  {
453  QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
454  QString name = node->customProperty( "legend/title-label" ).toString();
455  if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
456  {
457  QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
458  if ( vlayer && vlayer->pendingFeatureCount() >= 0 )
459  name += QString( " [%1]" ).arg( vlayer->pendingFeatureCount() );
460  }
461  return name;
462  }
463  }
464 
465  return QgsLayerTreeModel::data( index, role );
466 }
467 
468 Qt::ItemFlags QgsLegendModelV2::flags( const QModelIndex& index ) const
469 {
470  // make the legend nodes selectable even if they are not by default
471  if ( index2symnode( index ) )
472  return QgsLayerTreeModel::flags( index ) | Qt::ItemIsSelectable;
473 
474  return QgsLayerTreeModel::flags( index );
475 }
double boxSpace() const
void setCustomLayerTree(QgsLayerTreeGroup *rootGroup)
use new custom layer tree and update model. if new root is null pointer, will use project's tree ...
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
QString wrapChar() const
void setWrapChar(const QString &t)
Layer tree group node serves as a container for layers and further groups.
void setLegendSize(QSizeF s)
Set the preferred resulting legend size.
static unsigned index
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const
Returns style.
double boxSpace() const
void setEqualColumnWidth(bool s)
void setBoxSpace(double s)
void setMmPerMapUnit(double mmPerMapUnit)
double scale() const
Return the calculated scale of the map.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
void readXML(const QDomElement &elem, const QDomDocument &doc)
double mapUnitsToMM() const
Returns the conversion factor map units -> mm.
QgsComposerLegendStyle & rstyle(QgsComposerLegendStyle::Style s)
Returns reference to modifiable style.
void setMargin(Side side, double margin)
Item model implementation based on layer tree model for composer legend.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
int columnCount() const
static QgsLayerTreeGroup * readXML(QDomElement &element)
Read group (tree) from XML element and return the newly created group (or null on ...
QgsMapLayer * layer() const
void setSplitLayer(bool s)
QgsComposerModel * itemsModel()
Returns the items model attached to the composition.
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
bool writeXML(QDomElement &elem, QDomDocument &doc) const
stores state in Dom node
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
void itemChanged()
Emitted when the item changes.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void setSymbolSize(QSizeF s)
void drawLegend(QPainter *painter)
Draw the legend with given painter.
void setColumnSpace(double s)
A item that forms part of a map composition.
double columnSpace() const
double columnSpace() const
QgsLegendModel mLegendModel
Flags flags() const
Return OR-ed combination of model flags.
double wmsLegendWidth() const
virtual void drawFrame(QPainter *p)
Draw black frame around item.
static QgsLayerTreeModelLegendNode * index2symnode(const QModelIndex &index)
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const
Returns style.
void setTitle(const QString &t)
void updateLegend()
Updates the model and all legend entries.
void updateItemDisplayName(QgsComposerItem *item)
Must be called when an item's display name is modified.
QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. No type checking is done - use isGroup() to find out whether this operation is ...
Definition: qgslayertree.h:46
void setWmsLegendHeight(double h)
QgsComposerLegendStyle & rstyle(QgsComposerLegendStyle::Style s)
Returns reference to modifiable style.
void adjustBoxSize()
Sets item box to the whole content.
The QgsMapSettings class contains configuration for rendering of the map.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
QgsLegendModelV2(QgsLayerTreeGroup *rootNode, QObject *parent=0)
QColor fontColor() const
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QVariant data(const QModelIndex &index, int role) const
const QgsComposerMap * mComposerMap
Allow check boxes for symbology items (if supported by layer's legend)
void setLayerSet(const QStringList &layerIds, double scaleDenominator=-1, QString rule="")
int splitLayer() const
void setSymbolHeight(double h)
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
QColor fontColor() const
const QgsComposition * composition() const
Returns the composition the item is attached to.
void setMapScale(double scale)
void setComposerMap(const QgsComposerMap *map)
void synchronizeWithModel()
Data changed.
void setStyleFont(QgsComposerLegendStyle::Style s, const QFont &f)
Set style font.
QString wrapChar() const
int pendingFeatureCount()
returns feature count after commit
void setTitle(const QString &t)
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
This class is a base class for nodes in a layer tree.
QString title() const
QgsLegendModelV2 * mLegendModel2
void setDpi(int dpi)
void setFontColor(const QColor &c)
virtual QString displayName() const
Get item display name.
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:40
void setColumnSpace(double s)
bool autoUpdateModel() const
void setFlag(Flag f, bool on=true)
Enable or disable a model flag.
Graphics scene for map printing.
QSizeF minimumSize()
Run the layout algorithm and determine the size required for legend.
QFont styleFont(QgsComposerLegendStyle::Style s) const
Object representing map window.
void setSymbolWidth(double w)
QSizeF paintAndDetermineSize(QPainter *painter)
Paints the legend and calculates its size.
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style)
void setRootGroup(QgsLayerTreeGroup *newRootGroup)
Reset the model and use a new root group node.
void invalidateCurrentMap()
Sets mCompositionMap to 0 if the map is deleted.
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
virtual void writeXML(QDomElement &parentElement)
Write group (tree) as XML element and add it to the given parent element...
double symbolWidth() const
void setWmsLegendWidth(double w)
void writeXML(QString name, QDomElement &elem, QDomDocument &doc) const
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
bool useAdvancedEffects() const
Returns true if a composition should use advanced effects such as blend modes.
int id() const
Get identification number.
QgsComposition * mComposition
Composer legend components style.
void setWmsLegendSize(QSizeF s)
void setUseAdvancedEffects(bool use)
void setAutoUpdateModel(bool autoUpdate)
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
void setStyleMargin(QgsComposerLegendStyle::Style s, double margin)
Set style margin.
QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. No type checking is done - use isLayer() to find out whether this operation is ...
Definition: qgslayertree.h:52
void setWrapChar(const QString &t)
void setOutputSize(const QSize &size)
Set the size of the resulting map image.
virtual void drawBackground(QPainter *p)
Draw background.
void setColumnCount(int c)
double wmsLegendHeight() const
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
int equalColumnWidth() const
void setEqualColumnWidth(bool s)
void setStyle(QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style)
QString title() const
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
QgsLegendSettings mSettings
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint.
QSizeF symbolSize() const
QSizeF wmsLegendSize() const
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Return layer tree node for given index.
void setFontColor(const QColor &c)
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void setBoxSpace(double s)
Allow reordering with drag'n'drop.
double symbolHeight() const
int equalColumnWidth() const
void setSplitLayer(bool s)
QgsLayerTreeGroup * mCustomLayerTree
Layer tree node points to a map layer.
The QgsLegendRenderer class handles automatic layout and rendering of legend.
#define tr(sourceText)
void setFont(const QFont &font)
QString id() const
Get item's id (which is not necessarly unique)