QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgslegendsymbolitem.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslegendsymbolitem.cpp
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#include "qgslegendsymbolitem.h"
17
19#include "qgssymbol.h"
20
22
23QgsLegendSymbolItem::QgsLegendSymbolItem( QgsSymbol *symbol, const QString &label, const QString &ruleKey, bool checkable, int scaleMinDenom, int scaleMaxDenom, int level, const QString &parentRuleKey )
24 : mSymbol( symbol ? symbol->clone() : nullptr )
25 , mLabel( label )
26 , mKey( ruleKey )
27 , mCheckable( checkable )
28 , mOriginalSymbolPointer( symbol )
29 , mScaleMinDenom( scaleMinDenom )
30 , mScaleMaxDenom( scaleMaxDenom )
31 , mLevel( level )
32 , mParentKey( parentRuleKey )
33{
34}
35
37{
38 *this = other;
39}
40
44
46{
47 if ( this == &other )
48 return *this;
49
50 mSymbol.reset( other.mSymbol ? other.mSymbol->clone() : nullptr );
51 mLabel = other.mLabel;
52 mKey = other.mKey;
53 mCheckable = other.mCheckable;
54 mDataDefinedSizeLegendSettings.reset( other.mDataDefinedSizeLegendSettings ? new QgsDataDefinedSizeLegend( *other.mDataDefinedSizeLegendSettings ) : nullptr );
55 mOriginalSymbolPointer = other.mOriginalSymbolPointer;
56 mScaleMinDenom = other.mScaleMinDenom;
57 mScaleMaxDenom = other.mScaleMaxDenom;
58 mLevel = other.mLevel;
59 mParentKey = other.mParentKey;
60 mUserData = other.mUserData;
61
62 return *this;
63}
64
65bool QgsLegendSymbolItem::isScaleOK( double scale ) const
66{
67 if ( scale <= 0 )
68 return true;
69 if ( mScaleMinDenom <= 0 && mScaleMaxDenom <= 0 )
70 return true;
71 if ( mScaleMinDenom > 0 && mScaleMinDenom > scale )
72 return false;
73 if ( mScaleMaxDenom > 0 && mScaleMaxDenom < scale )
74 return false;
75 return true;
76}
77
79{
80 mSymbol.reset( s ? s->clone() : nullptr );
81 mOriginalSymbolPointer = s;
82}
83
85{
86 mDataDefinedSizeLegendSettings.reset( settings );
87}
88
90{
91 return mDataDefinedSizeLegendSettings.get();
92}
93
94void QgsLegendSymbolItem::setUserData( int key, QVariant &value )
95{
96 mUserData.insert( key, value );
97}
98
99QVariant QgsLegendSymbolItem::userData( int key ) const
100{
101 return mUserData.value( key, QVariant() );
102}
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
QgsDataDefinedSizeLegend * dataDefinedSizeLegendSettings() const
Returns extra information for data-defined size legend rendering.
QVariant userData(int key) const
Retrieves the item's user data with the specified key.
QString parentRuleKey() const
Key of the parent legend node.
int level() const
Indentation level that tells how deep the item is in a hierarchy of items. For flat lists level is 0.
void setUserData(int key, QVariant &value)
Adds a key - value pair to the item's user data.
int scaleMaxDenom() const
Max scale denominator of the scale range.
void setDataDefinedSizeLegendSettings(QgsDataDefinedSizeLegend *settings)
Sets extra information about data-defined size.
void setSymbol(QgsSymbol *s)
Sets the symbol of the item.
int scaleMinDenom() const
Min scale denominator of the scale range.
QgsLegendSymbolItem & operator=(const QgsLegendSymbolItem &other)
bool isScaleOK(double scale) const
Determine whether given scale is within the scale range. Returns true if scale or scale range is inva...
QgsSymbol * symbol() const
Returns associated symbol. May be nullptr.
QString ruleKey() const
Returns unique identifier of the rule for identification of the item within renderer.
QString label() const
Returns text label.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.