QGIS API Documentation
qgscomposerlegenditem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlegenditem.h - description
3  ------------------------
4  begin : May 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole 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 QGSCOMPOSERLEGENDITEM_H
19 #define QGSCOMPOSERLEGENDITEM_H
20 
21 #include "qgscomposerlegendstyle.h"
22 #include <QStandardItem>
23 class QDomDocument;
24 class QDomElement;
25 
27 class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
28 {
29  public:
33  virtual ~QgsComposerLegendItem();
34 
35  enum ItemType
36  {
37  GroupItem = QStandardItem::UserType,
41  StyleItem
42  };
43 
44  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const = 0;
48  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) = 0;
49 
50  virtual ItemType itemType() const = 0;
51  virtual QStandardItem* clone() const override = 0;
52 
53  QgsComposerLegendStyle::Style style() const { return mStyle; }
54  void setStyle( QgsComposerLegendStyle::Style style ) { mStyle = style; }
55 
56  // Get text defined by user
57  virtual QString userText() const { return mUserText; }
58  // Set text defined by user
59  virtual void setUserText( const QString & text ) { mUserText = text; }
60 
61  protected:
62  void writeXMLChildren( QDomElement& elem, QDomDocument& doc ) const;
63 
65 
66  // User defined text
68 };
69 
70 
71 class QgsSymbolV2;
72 
74 {
75  public:
77  QgsComposerSymbolV2Item( const QString& text );
78  QgsComposerSymbolV2Item( const QIcon& icon, const QString& text );
79  virtual ~QgsComposerSymbolV2Item();
80 
81  virtual QStandardItem* clone() const override;
82 
83  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
84  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
85 
87  void setSymbolV2( QgsSymbolV2* s );
88  QgsSymbolV2* symbolV2() {return mSymbolV2;}
89 
90  ItemType itemType() const override { return SymbologyV2Item; }
91 
92  private:
93  QgsSymbolV2* mSymbolV2;
94 };
95 
97 {
98  public:
100  QgsComposerRasterSymbolItem( const QString& text );
101  QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text );
102  virtual ~QgsComposerRasterSymbolItem();
103 
104  virtual QStandardItem* clone() const override;
105 
106  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
107  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
108 
109  void setLayerID( const QString& id ) { mLayerID = id; }
110  QString layerID() const { return mLayerID; }
111  ItemType itemType() const override { return RasterSymbolItem; }
112 
113  void setColor( const QColor& c ) { mColor = c; }
114  QColor color() const { return mColor; }
115 
116  private:
117  QString mLayerID;
118  QColor mColor;
119 };
120 
121 class CORE_EXPORT QgsComposerLayerItem : public QgsComposerLegendItem
122 {
123  public:
125  QgsComposerLayerItem( const QString& text );
126  virtual ~QgsComposerLayerItem();
127  virtual QStandardItem* clone() const override;
128 
129  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
130  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
131 
132  ItemType itemType() const override { return LayerItem; }
133 
134  void setLayerID( const QString& id ) { mLayerID = id; }
135  QString layerID() const { return mLayerID; }
136 
137  void setShowFeatureCount( bool show ) { mShowFeatureCount = show; }
138  bool showFeatureCount() const { return mShowFeatureCount; }
139 
140  void setDefaultStyle( double scaleDenominator = -1, const QString& rule = "" );
141 
142  private:
143  QString mLayerID;
144  // Show vector feature counts
145  bool mShowFeatureCount;
146 };
147 
149 {
150  public:
152  QgsComposerGroupItem( const QString& text );
153  virtual ~QgsComposerGroupItem();
154  virtual QStandardItem* clone() const override;
155 
156  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
157  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
158 
159  ItemType itemType() const override { return GroupItem; }
160 };
161 
162 class CORE_EXPORT QgsComposerStyleItem: public QStandardItem
163 {
164  public:
168 };
169 
170 #endif // QGSCOMPOSERLEGENDITEM_H
ItemType itemType() const override
ItemType itemType() const override
virtual void readXML(const QDomElement &itemElem, bool xServerAvailable=true)=0
Read item content from xml.
void setLayerID(const QString &id)
virtual QStandardItem * clone() const override=0
virtual QString userText() const
virtual QStandardItem * clone() const
QString text() const
void setLayerID(const QString &id)
void setStyle(QgsComposerLegendStyle::Style style)
ItemType itemType() const override
virtual void writeXML(QDomElement &elem, QDomDocument &doc) const =0
QgsComposerLegendStyle::Style mStyle
Abstract base class for the legend item types.
QgsComposerLegendStyle::Style style() const
ItemType itemType() const override
void setShowFeatureCount(bool show)
virtual void setUserText(const QString &text)