QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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:
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;
50  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) = 0;
51 
52  virtual ItemType itemType() const = 0;
53  virtual QStandardItem* clone() const override = 0;
54 
55  QgsComposerLegendStyle::Style style() const { return mStyle; }
56  void setStyle( QgsComposerLegendStyle::Style style ) { mStyle = style; }
57 
58  // Get text defined by user
59  virtual QString userText() const { return mUserText; }
60  // Set text defined by user
61  virtual void setUserText( const QString & text ) { mUserText = text; }
62 
63  protected:
64  void writeXMLChildren( QDomElement& elem, QDomDocument& doc ) const;
65 
67 
68  // User defined text
70 };
71 
72 
73 class QgsSymbolV2;
74 
79 {
80  public:
82  QgsComposerSymbolV2Item( const QString& text );
83  QgsComposerSymbolV2Item( const QIcon& icon, const QString& text );
84  virtual ~QgsComposerSymbolV2Item();
85 
86  virtual QStandardItem* clone() const override;
87 
88  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
89  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
90 
92  void setSymbolV2( QgsSymbolV2* s );
93  QgsSymbolV2* symbolV2() {return mSymbolV2;}
94 
95  ItemType itemType() const override { return SymbologyV2Item; }
96 
97  private:
98  QgsSymbolV2* mSymbolV2;
99 };
100 
105 {
106  public:
108  QgsComposerRasterSymbolItem( const QString& text );
109  QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text );
110  virtual ~QgsComposerRasterSymbolItem();
111 
112  virtual QStandardItem* clone() const override;
113 
114  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
115  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
116 
117  void setLayerID( const QString& id ) { mLayerID = id; }
118  QString layerID() const { return mLayerID; }
119  ItemType itemType() const override { return RasterSymbolItem; }
120 
121  void setColor( const QColor& c ) { mColor = c; }
122  QColor color() const { return mColor; }
123 
124  private:
125  QString mLayerID;
126  QColor mColor;
127 };
128 
132 class CORE_EXPORT QgsComposerLayerItem : public QgsComposerLegendItem
133 {
134  public:
136  QgsComposerLayerItem( const QString& text );
137  virtual ~QgsComposerLayerItem();
138  virtual QStandardItem* clone() const override;
139 
140  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
141  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
142 
143  ItemType itemType() const override { return LayerItem; }
144 
145  void setLayerID( const QString& id ) { mLayerID = id; }
146  QString layerID() const { return mLayerID; }
147 
148  void setShowFeatureCount( bool show ) { mShowFeatureCount = show; }
149  bool showFeatureCount() const { return mShowFeatureCount; }
150 
151  void setDefaultStyle( double scaleDenominator = -1, const QString& rule = "" );
152 
153  private:
154  QString mLayerID;
155  // Show vector feature counts
156  bool mShowFeatureCount;
157 };
158 
163 {
164  public:
166  QgsComposerGroupItem( const QString& text );
167  virtual ~QgsComposerGroupItem();
168  virtual QStandardItem* clone() const override;
169 
170  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
171  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
172 
173  ItemType itemType() const override { return GroupItem; }
174 };
175 
179 class CORE_EXPORT QgsComposerStyleItem: public QStandardItem
180 {
181  public:
185 };
186 
187 #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.
QgsComposerLegendStyle::Style style() const
void setLayerID(const QString &id)
virtual QStandardItem * clone() const override=0
virtual QStandardItem * clone() const
QString text() const
void setLayerID(const QString &id)
void setStyle(QgsComposerLegendStyle::Style style)
ItemType itemType() const override
virtual QString userText() const
virtual void writeXML(QDomElement &elem, QDomDocument &doc) const =0
QgsComposerLegendStyle::Style mStyle
Abstract base class for the legend item types.
ItemType itemType() const override
void setShowFeatureCount(bool show)
virtual void setUserText(const QString &text)