QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgslayertreemodellegendnode.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreemodellegendnode.h
3  --------------------------------------
4  Date : August 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSLAYERTREEMODELLEGENDNODE_H
17 #define QGSLAYERTREEMODELLEGENDNODE_H
18 
19 #include <QIcon>
20 #include <QObject>
21 
22 class QgsLayerTreeLayer;
23 class QgsLayerTreeModel;
24 class QgsLegendSettings;
25 class QgsSymbolV2;
26 
36 class CORE_EXPORT QgsLayerTreeModelLegendNode : public QObject
37 {
38  Q_OBJECT
39  public:
41 
43  {
44  RuleKeyRole = Qt::UserRole,
45  SymbolV2LegacyRuleKeyRole
46  };
47 
49  QgsLayerTreeLayer* layerNode() const { return mLayerNode; }
50 
52  QgsLayerTreeModel* model() const;
53 
55  virtual Qt::ItemFlags flags() const;
56 
58  virtual QVariant data( int role ) const = 0;
59 
61  virtual bool setData( const QVariant& value, int role );
62 
63  virtual bool isEmbeddedInParent() const { return mEmbeddedInParent; }
64  virtual void setEmbeddedInParent( bool embedded ) { mEmbeddedInParent = embedded; }
65 
66  virtual QString userLabel() const { return mUserLabel; }
67  virtual void setUserLabel( const QString& userLabel ) { mUserLabel = userLabel; }
68 
69  virtual bool isScaleOK( double scale ) const { Q_UNUSED( scale ); return true; }
70 
73  virtual void invalidateMapBasedData() {}
74 
75  struct ItemContext
76  {
78  QPainter* painter;
80  QPointF point;
82  double labelXOffset;
83  };
84 
85  struct ItemMetrics
86  {
87  QSizeF symbolSize;
88  QSizeF labelSize;
89  };
90 
96  virtual ItemMetrics draw( const QgsLegendSettings& settings, ItemContext* ctx );
97 
105  virtual QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
106 
114  virtual QSizeF drawSymbolText( const QgsLegendSettings& settings, ItemContext* ctx, const QSizeF& symbolSize ) const;
115 
116  signals:
118  void dataChanged();
119 
120  protected:
122  explicit QgsLayerTreeModelLegendNode( QgsLayerTreeLayer* nodeL, QObject* parent = 0 );
123 
124  protected:
127  QString mUserLabel;
128 };
129 
130 #include "qgslegendsymbolitemv2.h"
131 
139 {
140  public:
141  QgsSymbolV2LegendNode( QgsLayerTreeLayer* nodeLayer, const QgsLegendSymbolItemV2& item, QObject* parent = 0 );
143 
144  virtual Qt::ItemFlags flags() const;
145  virtual QVariant data( int role ) const;
146  virtual bool setData( const QVariant& value, int role );
147 
148  QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
149 
150  virtual void setEmbeddedInParent( bool embedded );
151 
152  void setUserLabel( const QString& userLabel ) { mUserLabel = userLabel; updateLabel(); }
153 
154  virtual bool isScaleOK( double scale ) const { return mItem.isScaleOK( scale ); }
155 
156  virtual void invalidateMapBasedData();
157 
158  private:
159  void updateLabel();
160 
161  private:
162  QgsLegendSymbolItemV2 mItem;
163  mutable QPixmap mPixmap; // cached symbol preview
164  QString mLabel;
165  bool mSymbolUsesMapUnits;
166 };
167 
168 
175 {
176  public:
177  QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon(), QObject* parent = 0 );
178 
179  virtual QVariant data( int role ) const;
180 
181  private:
182  QString mLabel;
183  QString mId;
184  QIcon mIcon;
185 };
186 
187 
194 {
195  public:
196  QgsImageLegendNode( QgsLayerTreeLayer* nodeLayer, const QImage& img, QObject* parent = 0 );
197 
198  virtual QVariant data( int role ) const;
199 
200  QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
201 
202  private:
203  QImage mImage;
204 };
205 
212 {
213  public:
214  QgsRasterSymbolLegendNode( QgsLayerTreeLayer* nodeLayer, const QColor& color, const QString& label, QObject* parent = 0 );
215 
216  virtual QVariant data( int role ) const;
217 
218  QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
219 
220  private:
221  QColor mColor;
222  QString mLabel;
223 };
224 
225 #endif // QGSLAYERTREEMODELLEGENDNODE_H