QGIS API Documentation  2.99.0-Master (c42dad3)
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 
29 class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
30 {
31  public:
34  QgsComposerLegendItem( const QIcon& icon, const QString& text, QgsComposerLegendStyle::Style s = QgsComposerLegendStyle::Undefined );
35  virtual ~QgsComposerLegendItem();
36 
37  enum ItemType
38  {
39  GroupItem = QStandardItem::UserType,
43  StyleItem
44  };
45 
46  virtual void writeXml( QDomElement& elem, QDomDocument& doc ) const = 0;
47 
51  virtual void readXml( const QDomElement& itemElem, bool xServerAvailable = true ) = 0;
52 
53  virtual ItemType itemType() const = 0;
54  virtual QStandardItem* clone() const override = 0;
55 
56  QgsComposerLegendStyle::Style style() const { return mStyle; }
57  void setStyle( QgsComposerLegendStyle::Style style ) { mStyle = style; }
58 
59  // Get text defined by user
60  virtual QString userText() const { return mUserText; }
61  // Set text defined by user
62  virtual void setUserText( const QString & text ) { mUserText = text; }
63 
64  protected:
65  void writeXmlChildren( QDomElement& elem, QDomDocument& doc ) const;
66 
68 
69  // User defined text
70  QString mUserText;
71 };
72 
73 
74 class QgsSymbol;
75 
80 {
81  public:
83  QgsComposerSymbolItem( const QString& text );
84  QgsComposerSymbolItem( const QIcon& icon, const QString& text );
85  virtual ~QgsComposerSymbolItem();
86 
87  virtual QStandardItem* clone() const override;
88 
89  virtual void writeXml( QDomElement& elem, QDomDocument& doc ) const override;
90  virtual void readXml( const QDomElement& itemElem, bool xServerAvailable = true ) override;
91 
93  void setSymbol( QgsSymbol* s );
94  QgsSymbol* symbol() {return mSymbol;}
95 
96  ItemType itemType() const override { return SymbologyV2Item; }
97 
98  private:
99  QgsSymbol* mSymbol;
100 };
101 
106 {
107  public:
109  QgsComposerRasterSymbolItem( const QString& text );
110  QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text );
111  virtual ~QgsComposerRasterSymbolItem();
112 
113  virtual QStandardItem* clone() const override;
114 
115  virtual void writeXml( QDomElement& elem, QDomDocument& doc ) const override;
116  virtual void readXml( const QDomElement& itemElem, bool xServerAvailable = true ) override;
117 
118  void setLayerId( const QString& id ) { mLayerID = id; }
119  QString layerId() const { return mLayerID; }
120  ItemType itemType() const override { return RasterSymbolItem; }
121 
122  void setColor( const QColor& c ) { mColor = c; }
123  QColor color() const { return mColor; }
124 
125  private:
126  QString mLayerID;
127  QColor mColor;
128 };
129 
133 class CORE_EXPORT QgsComposerLayerItem : public QgsComposerLegendItem
134 {
135  public:
137  QgsComposerLayerItem( const QString& text );
138  virtual ~QgsComposerLayerItem();
139  virtual QStandardItem* clone() const override;
140 
141  virtual void writeXml( QDomElement& elem, QDomDocument& doc ) const override;
142  virtual void readXml( const QDomElement& itemElem, bool xServerAvailable = true ) override;
143 
144  ItemType itemType() const override { return LayerItem; }
145 
150  void setLayerId( const QString& id ) { mLayerID = id; }
151 
156  QString layerId() const { return mLayerID; }
157 
158  void setShowFeatureCount( bool show ) { mShowFeatureCount = show; }
159  bool showFeatureCount() const { return mShowFeatureCount; }
160 
161  void setDefaultStyle( double scaleDenominator = -1, const QString& rule = "" );
162 
163  private:
164  QString mLayerID;
165  // Show vector feature counts
166  bool mShowFeatureCount;
167 };
168 
173 {
174  public:
176  QgsComposerGroupItem( const QString& text );
177  virtual ~QgsComposerGroupItem();
178  virtual QStandardItem* clone() const override;
179 
180  virtual void writeXml( QDomElement& elem, QDomDocument& doc ) const override;
181  virtual void readXml( const QDomElement& itemElem, bool xServerAvailable = true ) override;
182 
183  ItemType itemType() const override { return GroupItem; }
184 };
185 
189 class CORE_EXPORT QgsComposerStyleItem: public QStandardItem
190 {
191  public:
195 };
196 
197 #endif // QGSCOMPOSERLEGENDITEM_H
ItemType itemType() const override
QgsComposerLegendStyle::Style style() const
virtual QStandardItem * clone() const override=0
void setLayerId(const QString &id)
Sets the associated layer ID.
void setLayerId(const QString &id)
virtual void readXml(const QDomElement &itemElem, bool xServerAvailable=true)=0
Read item content from xml.
void setStyle(QgsComposerLegendStyle::Style style)
ItemType itemType() const override
virtual QString userText() const
QString layerId() const
Returns the ID of the associated layer.
virtual void writeXml(QDomElement &elem, QDomDocument &doc) const =0
QgsComposerLegendStyle::Style mStyle
Abstract base class for the legend item types.
ItemType itemType() const override
ItemType itemType() const override
void setShowFeatureCount(bool show)
virtual void setUserText(const QString &text)