QGIS API Documentation 3.43.0-Master (370e002e726)
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.
Stores information about one class/rule of a vector layer renderer in a unified way that can be used ...
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...
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.