@@ -15,6 +15,7 @@ class QgsLayerTreeModelLegendNode : QObject
1515%End
1616
1717 public:
18+ ~QgsLayerTreeModelLegendNode();
1819
1920 /** Return pointer to the parent layer node */
2021 QgsLayerTreeLayer* parent() const;
@@ -28,9 +29,57 @@ class QgsLayerTreeModelLegendNode : QObject
2829 /** Set some data associated with the item. Default implementation does nothing and returns false. */
2930 virtual bool setData( const QVariant& value, int role );
3031
32+ virtual bool isEmbeddedInParent() const;
33+ virtual void setEmbeddedInParent( bool embedded );
34+
35+ virtual QString userLabel() const;
36+ virtual void setUserLabel( const QString& userLabel );
37+
38+ virtual bool isScaleOK( double scale ) const;
39+
40+ struct ItemContext
41+ {
42+ //! Painter
43+ QPainter* painter;
44+ //! Top-left corner of the legend item
45+ QPointF point;
46+ //! offset from the left side where label should start
47+ double labelXOffset;
48+ };
49+
50+ struct ItemMetrics
51+ {
52+ QSizeF symbolSize;
53+ QSizeF labelSize;
54+ };
55+
56+ /** Entry point called from QgsLegendRenderer to do the rendering.
57+ * Default implementation calls drawSymbol() and drawSymbolText() methods.
58+ *
59+ * If ctx is null, this is just first stage when preparing layout - without actual rendering.
60+ */
61+ virtual ItemMetrics draw( const QgsLegendSettings& settings, ItemContext* ctx );
62+
63+ /**
64+ * Draws symbol on the left side of the item
65+ * @param itemHeight Minimal height of the legend item - used for correct positioning when rendering
66+ * @return Real size of the symbol (may be bigger than "normal" symbol size from settings)
67+ */
68+ virtual QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
69+
70+ /**
71+ * Draws label on the right side of the item
72+ * @param symbolSize Real size of the associated symbol - used for correct positioning when rendering
73+ * @return Size of the label (may span multiple lines)
74+ */
75+ virtual QSizeF drawSymbolText( const QgsLegendSettings& settings, ItemContext* ctx, const QSizeF& symbolSize ) const;
76+
3177 protected:
3278 /** Construct the node with pointer to its parent layer node */
33- explicit QgsLayerTreeModelLegendNode( QgsLayerTreeLayer* nodeL );
79+ explicit QgsLayerTreeModelLegendNode( QgsLayerTreeLayer* nodeL, QObject* parent /TransferThis/ = 0 );
80+
81+ private:
82+ QgsLayerTreeModelLegendNode(const QgsLayerTreeModelLegendNode &);
3483};
3584
3685
@@ -41,19 +90,29 @@ class QgsLayerTreeModelLegendNode : QObject
4190 *
4291 * @note added in 2.6
4392 */
44- /*
4593class QgsSymbolV2LegendNode : QgsLayerTreeModelLegendNode
4694{
4795%TypeHeaderCode
4896#include <qgslayertreemodellegendnode.h>
4997%End
5098 public:
5199 QgsSymbolV2LegendNode( QgsLayerTreeLayer* nodeLayer, const QgsLegendSymbolItemV2& item );
100+ ~QgsSymbolV2LegendNode();
52101
53102 virtual Qt::ItemFlags flags() const;
54103 virtual QVariant data( int role ) const;
55104 virtual bool setData( const QVariant& value, int role );
56- };*/
105+
106+ /** Draws a symbol at the current y position and returns the new x position. Returns real symbol height, because for points,
107+ it is possible that it differs from mSymbolHeight */
108+ QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
109+
110+ virtual void setEmbeddedInParent( bool embedded );
111+
112+ void setUserLabel( const QString& userLabel );
113+
114+ virtual bool isScaleOK( double scale ) const;
115+ };
57116
58117
59118/**
@@ -67,8 +126,47 @@ class QgsSimpleLegendNode : QgsLayerTreeModelLegendNode
67126#include <qgslayertreemodellegendnode.h>
68127%End
69128 public:
70- QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QString& id, const QIcon& icon = QIcon() );
129+ QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon(), QObject* parent /TransferThis/ = 0 );
71130
72131 virtual QVariant data( int role ) const;
73132};
74133
134+
135+ /**
136+ * Implementation of legend node interface for displaying arbitrary raster image
137+ *
138+ * @note added in 2.6
139+ */
140+ class QgsImageLegendNode : QgsLayerTreeModelLegendNode
141+ {
142+ %TypeHeaderCode
143+ #include <qgslayertreemodellegendnode.h>
144+ %End
145+ public:
146+ QgsImageLegendNode( QgsLayerTreeLayer* nodeLayer, const QImage& img, QObject* parent /TransferThis/ = 0 );
147+
148+ virtual QVariant data( int role ) const;
149+
150+ QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
151+
152+ };
153+
154+ /**
155+ * Implementation of legend node interface for displaying raster legend entries
156+ *
157+ * @note added in 2.6
158+ */
159+ class QgsRasterSymbolLegendNode : QgsLayerTreeModelLegendNode
160+ {
161+ %TypeHeaderCode
162+ #include <qgslayertreemodellegendnode.h>
163+ %End
164+ public:
165+ QgsRasterSymbolLegendNode( QgsLayerTreeLayer* nodeLayer, const QColor& color, const QString& label, QObject* parent /TransferThis/ = 0 );
166+
167+ virtual QVariant data( int role ) const;
168+
169+ QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
170+
171+ };
172+
0 commit comments