QGIS API Documentation  2.12.0-Lyon
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 
62  protected:
63  void writeXMLChildren( QDomElement& elem, QDomDocument& doc ) const;
64 
66 
67  // User defined text
69 };
70 
71 
72 class QgsSymbolV2;
73 
75 {
76  public:
78  QgsComposerSymbolV2Item( const QString& text );
79  QgsComposerSymbolV2Item( const QIcon& icon, const QString& text );
80  virtual ~QgsComposerSymbolV2Item();
81 
82  virtual QStandardItem* clone() const override;
83 
84  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
85  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
86 
88  void setSymbolV2( QgsSymbolV2* s );
89  QgsSymbolV2* symbolV2() {return mSymbolV2;}
90 
91  ItemType itemType() const override { return SymbologyV2Item; }
92 
93  private:
94  QgsSymbolV2* mSymbolV2;
95 };
96 
98 {
99  public:
101  QgsComposerRasterSymbolItem( const QString& text );
102  QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text );
103  virtual ~QgsComposerRasterSymbolItem();
104 
105  virtual QStandardItem* clone() const override;
106 
107  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
108  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
109 
110  void setLayerID( const QString& id ) { mLayerID = id; }
111  QString layerID() const { return mLayerID; }
112  ItemType itemType() const override { return RasterSymbolItem; }
113 
114  void setColor( const QColor& c ) { mColor = c; }
115  QColor color() const { return mColor; }
116 
117  private:
118  QString mLayerID;
119  QColor mColor;
120 };
121 
122 class CORE_EXPORT QgsComposerLayerItem : public QgsComposerLegendItem
123 {
124  public:
126  QgsComposerLayerItem( const QString& text );
127  virtual ~QgsComposerLayerItem();
128  virtual QStandardItem* clone() const override;
129 
130  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
131  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
132 
133  ItemType itemType() const override { return LayerItem; }
134 
135  void setLayerID( const QString& id ) { mLayerID = id; }
136  QString layerID() const { return mLayerID; }
137 
138  void setShowFeatureCount( bool show ) { mShowFeatureCount = show; }
139  bool showFeatureCount() const { return mShowFeatureCount; }
140 
141  void setDefaultStyle( double scaleDenominator = -1, const QString& rule = "" );
142 
143  private:
144  QString mLayerID;
145  // Show vector feature counts
146  bool mShowFeatureCount;
147 };
148 
150 {
151  public:
153  QgsComposerGroupItem( const QString& text );
154  virtual ~QgsComposerGroupItem();
155  virtual QStandardItem* clone() const override;
156 
157  virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const override;
158  virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) override;
159 
160  ItemType itemType() const override { return GroupItem; }
161 };
162 
163 class CORE_EXPORT QgsComposerStyleItem: public QStandardItem
164 {
165  public:
169 };
170 
171 #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)