2014-08-12 11:01:48 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The QgsLegendRendererItem class is abstract interface for legend items
|
|
|
|
* returned from QgsMapLayerLegend implementation.
|
|
|
|
*
|
|
|
|
* The objects are used in QgsLayerTreeModel. Custom implementations may offer additional interactivity
|
|
|
|
* and customized look.
|
|
|
|
*
|
|
|
|
* @note added in 2.6
|
|
|
|
*/
|
|
|
|
class QgsLayerTreeModelLegendNode : QObject
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgslayertreemodellegendnode.h>
|
|
|
|
%End
|
2014-11-13 23:13:13 +01:00
|
|
|
|
2014-08-12 11:01:48 +07:00
|
|
|
public:
|
2014-08-22 11:19:45 +07:00
|
|
|
~QgsLayerTreeModelLegendNode();
|
2014-08-12 11:01:48 +07:00
|
|
|
|
2014-09-05 11:28:08 +07:00
|
|
|
enum LegendNodeRoles
|
|
|
|
{
|
2014-09-25 12:00:45 +02:00
|
|
|
RuleKeyRole, //!< rule key of the node (QString)
|
2015-01-22 12:23:05 +07:00
|
|
|
SymbolV2LegacyRuleKeyRole, //!< for QgsSymbolV2LegendNode only - legacy rule key (void ptr, to be cast to QgsSymbolV2 ptr)
|
|
|
|
ParentRuleKeyRole //!< rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2.8
|
2014-09-05 11:28:08 +07:00
|
|
|
};
|
|
|
|
|
2014-08-12 11:01:48 +07:00
|
|
|
/** Return pointer to the parent layer node */
|
2014-09-25 12:00:45 +02:00
|
|
|
QgsLayerTreeLayer* layerNode() const;
|
|
|
|
|
|
|
|
/** Return pointer to model owning this legend node */
|
|
|
|
QgsLayerTreeModel* model() const;
|
2014-08-12 11:01:48 +07:00
|
|
|
|
|
|
|
/** Return item flags associated with the item. Default implementation returns Qt::ItemIsEnabled. */
|
|
|
|
virtual Qt::ItemFlags flags() const;
|
|
|
|
|
|
|
|
/** Return data associated with the item. Must be implemented in derived class. */
|
|
|
|
virtual QVariant data( int role ) const = 0;
|
|
|
|
|
|
|
|
/** Set some data associated with the item. Default implementation does nothing and returns false. */
|
|
|
|
virtual bool setData( const QVariant& value, int role );
|
|
|
|
|
2014-08-22 11:19:45 +07:00
|
|
|
virtual bool isEmbeddedInParent() const;
|
|
|
|
virtual void setEmbeddedInParent( bool embedded );
|
|
|
|
|
|
|
|
virtual QString userLabel() const;
|
|
|
|
virtual void setUserLabel( const QString& userLabel );
|
|
|
|
|
|
|
|
virtual bool isScaleOK( double scale ) const;
|
|
|
|
|
2014-09-25 12:00:45 +02:00
|
|
|
/** Notification from model that information from associated map view has changed.
|
|
|
|
* Default implementation does nothing. */
|
|
|
|
virtual void invalidateMapBasedData();
|
|
|
|
|
2014-08-22 11:19:45 +07:00
|
|
|
struct ItemContext
|
|
|
|
{
|
|
|
|
//! Painter
|
|
|
|
QPainter* painter;
|
|
|
|
//! Top-left corner of the legend item
|
|
|
|
QPointF point;
|
|
|
|
//! offset from the left side where label should start
|
|
|
|
double labelXOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ItemMetrics
|
|
|
|
{
|
|
|
|
QSizeF symbolSize;
|
|
|
|
QSizeF labelSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Entry point called from QgsLegendRenderer to do the rendering.
|
|
|
|
* Default implementation calls drawSymbol() and drawSymbolText() methods.
|
|
|
|
*
|
|
|
|
* If ctx is null, this is just first stage when preparing layout - without actual rendering.
|
|
|
|
*/
|
|
|
|
virtual ItemMetrics draw( const QgsLegendSettings& settings, ItemContext* ctx );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws symbol on the left side of the item
|
2014-09-01 11:05:51 +07:00
|
|
|
* @param settings Legend layout configuration
|
|
|
|
* @param ctx Context for rendering - may be null if only doing layout without actual rendering
|
2014-08-22 11:19:45 +07:00
|
|
|
* @param itemHeight Minimal height of the legend item - used for correct positioning when rendering
|
|
|
|
* @return Real size of the symbol (may be bigger than "normal" symbol size from settings)
|
|
|
|
*/
|
|
|
|
virtual QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws label on the right side of the item
|
2014-09-01 11:05:51 +07:00
|
|
|
* @param settings Legend layout configuration
|
|
|
|
* @param ctx Context for rendering - may be null if only doing layout without actual rendering
|
2014-08-22 11:19:45 +07:00
|
|
|
* @param symbolSize Real size of the associated symbol - used for correct positioning when rendering
|
|
|
|
* @return Size of the label (may span multiple lines)
|
|
|
|
*/
|
|
|
|
virtual QSizeF drawSymbolText( const QgsLegendSettings& settings, ItemContext* ctx, const QSizeF& symbolSize ) const;
|
|
|
|
|
2014-09-05 11:28:08 +07:00
|
|
|
signals:
|
|
|
|
//! Emitted on internal data change so the layer tree model can forward the signal to views
|
|
|
|
void dataChanged();
|
|
|
|
|
2014-08-12 11:01:48 +07:00
|
|
|
protected:
|
|
|
|
/** Construct the node with pointer to its parent layer node */
|
2014-08-22 11:19:45 +07:00
|
|
|
explicit QgsLayerTreeModelLegendNode( QgsLayerTreeLayer* nodeL, QObject* parent /TransferThis/ = 0 );
|
|
|
|
|
|
|
|
private:
|
|
|
|
QgsLayerTreeModelLegendNode(const QgsLayerTreeModelLegendNode &);
|
2014-08-12 11:01:48 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of legend node interface for displaying preview of vector symbols and their labels
|
|
|
|
* and allowing interaction with the symbol / renderer.
|
|
|
|
*
|
|
|
|
* @note added in 2.6
|
|
|
|
*/
|
|
|
|
class QgsSymbolV2LegendNode : QgsLayerTreeModelLegendNode
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgslayertreemodellegendnode.h>
|
|
|
|
%End
|
|
|
|
public:
|
2014-09-25 12:00:45 +02:00
|
|
|
QgsSymbolV2LegendNode( QgsLayerTreeLayer* nodeLayer, const QgsLegendSymbolItemV2& item, QObject* parent /TransferThis/ = 0 );
|
2014-08-22 11:19:45 +07:00
|
|
|
~QgsSymbolV2LegendNode();
|
2014-08-12 11:01:48 +07:00
|
|
|
|
|
|
|
virtual Qt::ItemFlags flags() const;
|
|
|
|
virtual QVariant data( int role ) const;
|
|
|
|
virtual bool setData( const QVariant& value, int role );
|
2014-08-22 11:19:45 +07:00
|
|
|
|
|
|
|
QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
|
|
|
|
|
|
|
|
virtual void setEmbeddedInParent( bool embedded );
|
|
|
|
|
|
|
|
void setUserLabel( const QString& userLabel );
|
|
|
|
|
|
|
|
virtual bool isScaleOK( double scale ) const;
|
2014-09-25 12:00:45 +02:00
|
|
|
|
|
|
|
virtual void invalidateMapBasedData();
|
2015-05-08 07:00:58 +10:00
|
|
|
|
|
|
|
//! Set the icon size
|
|
|
|
//! @note added in 2.10
|
|
|
|
void setIconSize( const QSize& sz );
|
|
|
|
//! @note added in 2.10
|
|
|
|
QSize iconSize() const;
|
|
|
|
|
|
|
|
//! Get the minimum icon size to prevent cropping
|
|
|
|
//! @note added in 2.10
|
|
|
|
QSize minimumIconSize() const;
|
2015-12-07 07:39:20 +11:00
|
|
|
|
2015-12-08 06:32:23 +11:00
|
|
|
/** Returns the symbol used by the legend node.
|
|
|
|
* @see setSymbol()
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
const QgsSymbolV2* symbol() const;
|
|
|
|
|
|
|
|
/** Sets the symbol to be used by the legend node. The symbol change is also propagated
|
|
|
|
* to the associated vector layer's renderer.
|
|
|
|
* @param symbol new symbol for node. Ownership is transferred.
|
|
|
|
* @see symbol()
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
*/
|
|
|
|
void setSymbol( QgsSymbolV2* symbol /Transfer/ );
|
|
|
|
|
2015-12-07 07:39:20 +11:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
/** Checks all items belonging to the same layer as this node.
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see uncheckAllItems()
|
|
|
|
*/
|
|
|
|
void checkAllItems();
|
|
|
|
|
|
|
|
/** Unchecks all items belonging to the same layer as this node.
|
|
|
|
* @note added in QGIS 2.14
|
|
|
|
* @see checkAllItems()
|
|
|
|
*/
|
|
|
|
void uncheckAllItems();
|
|
|
|
|
2014-08-22 11:19:45 +07:00
|
|
|
};
|
2014-08-12 11:01:48 +07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of legend node interface for displaying arbitrary label with icon.
|
|
|
|
*
|
|
|
|
* @note added in 2.6
|
|
|
|
*/
|
|
|
|
class QgsSimpleLegendNode : QgsLayerTreeModelLegendNode
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgslayertreemodellegendnode.h>
|
|
|
|
%End
|
|
|
|
public:
|
2015-05-04 16:34:30 +10:00
|
|
|
QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon = QIcon(), QObject* parent /TransferThis/ = 0, const QString& key = QString() );
|
2014-08-12 11:01:48 +07:00
|
|
|
|
|
|
|
virtual QVariant data( int role ) const;
|
|
|
|
};
|
|
|
|
|
2014-08-22 11:19:45 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of legend node interface for displaying arbitrary raster image
|
|
|
|
*
|
|
|
|
* @note added in 2.6
|
|
|
|
*/
|
|
|
|
class QgsImageLegendNode : QgsLayerTreeModelLegendNode
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgslayertreemodellegendnode.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
QgsImageLegendNode( QgsLayerTreeLayer* nodeLayer, const QImage& img, QObject* parent /TransferThis/ = 0 );
|
|
|
|
|
|
|
|
virtual QVariant data( int role ) const;
|
|
|
|
|
|
|
|
QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of legend node interface for displaying raster legend entries
|
|
|
|
*
|
|
|
|
* @note added in 2.6
|
|
|
|
*/
|
|
|
|
class QgsRasterSymbolLegendNode : QgsLayerTreeModelLegendNode
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgslayertreemodellegendnode.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
QgsRasterSymbolLegendNode( QgsLayerTreeLayer* nodeLayer, const QColor& color, const QString& label, QObject* parent /TransferThis/ = 0 );
|
|
|
|
|
|
|
|
virtual QVariant data( int role ) const;
|
|
|
|
|
|
|
|
QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
|
|
|
|
};
|
2016-01-04 22:51:18 +11:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of legend node interface for displaying WMS legend entries
|
|
|
|
*
|
|
|
|
* @note added in 2.8
|
|
|
|
*/
|
|
|
|
class QgsWMSLegendNode : QgsLayerTreeModelLegendNode
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgslayertreemodellegendnode.h>
|
|
|
|
%End
|
|
|
|
public:
|
|
|
|
QgsWMSLegendNode( QgsLayerTreeLayer* nodeLayer, QObject* parent /TransferThis/ = nullptr );
|
|
|
|
|
|
|
|
virtual QVariant data( int role ) const;
|
|
|
|
|
|
|
|
virtual QSizeF drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const;
|
|
|
|
|
|
|
|
virtual void invalidateMapBasedData();
|
|
|
|
|
|
|
|
};
|