QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
21QgsLegendSymbolItem::QgsLegendSymbolItem( QgsSymbol *symbol, const QString &label, const QString &ruleKey, bool checkable, int scaleMinDenom, int scaleMaxDenom, int level, const QString &parentRuleKey )
22 : mSymbol( symbol ? symbol->clone() : nullptr )
23 , mLabel( label )
24 , mKey( ruleKey )
25 , mCheckable( checkable )
26 , mOriginalSymbolPointer( symbol )
27 , mScaleMinDenom( scaleMinDenom )
28 , mScaleMaxDenom( scaleMaxDenom )
29 , mLevel( level )
30 , mParentKey( parentRuleKey )
31{
32}
33
35{
36 *this = other;
37}
38
40{
41 delete mSymbol;
42 delete mDataDefinedSizeLegendSettings;
43}
44
46{
47 if ( this == &other )
48 return *this;
49
50 delete mSymbol;
51 mSymbol = other.mSymbol ? other.mSymbol->clone() : nullptr;
52 mLabel = other.mLabel;
53 mKey = other.mKey;
54 mCheckable = other.mCheckable;
55 delete mDataDefinedSizeLegendSettings;
56 mDataDefinedSizeLegendSettings = other.mDataDefinedSizeLegendSettings ? new QgsDataDefinedSizeLegend( *other.mDataDefinedSizeLegendSettings ) : nullptr;
57 mOriginalSymbolPointer = other.mOriginalSymbolPointer;
58 mScaleMinDenom = other.mScaleMinDenom;
59 mScaleMaxDenom = other.mScaleMaxDenom;
60 mLevel = other.mLevel;
61 mParentKey = other.mParentKey;
62 mUserData = other.mUserData;
63
64 return *this;
65}
66
67bool QgsLegendSymbolItem::isScaleOK( double scale ) const
68{
69 if ( scale <= 0 )
70 return true;
71 if ( mScaleMinDenom <= 0 && mScaleMaxDenom <= 0 )
72 return true;
73 if ( mScaleMinDenom > 0 && mScaleMinDenom > scale )
74 return false;
75 if ( mScaleMaxDenom > 0 && mScaleMaxDenom < scale )
76 return false;
77 return true;
78}
79
81{
82 delete mSymbol;
83 mSymbol = s ? s->clone() : nullptr;
84 mOriginalSymbolPointer = s;
85}
86
88{
89 delete mDataDefinedSizeLegendSettings;
90 mDataDefinedSizeLegendSettings = settings;
91}
92
94{
95 return mDataDefinedSizeLegendSettings;
96}
97
98void QgsLegendSymbolItem::setUserData( int key, QVariant &value )
99{
100 mUserData.insert( key, value );
101}
102
103QVariant QgsLegendSymbolItem::userData( int key ) const
104{
105 return mUserData.value( key, QVariant() );
106}
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
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.
void setUserData(int key, QVariant &value)
Adds a key - value pair to the item's user data.
void setDataDefinedSizeLegendSettings(QgsDataDefinedSizeLegend *settings)
Sets extra information about data-defined size.
void setSymbol(QgsSymbol *s)
Sets the symbol of the item.
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...
QgsLegendSymbolItem()=default
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.