QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
21 QgsLegendSymbolItem::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 
63  return *this;
64 }
65 
66 bool QgsLegendSymbolItem::isScaleOK( double scale ) const
67 {
68  if ( scale <= 0 )
69  return true;
70  if ( mScaleMinDenom <= 0 && mScaleMaxDenom <= 0 )
71  return true;
72  if ( mScaleMinDenom > 0 && mScaleMinDenom > scale )
73  return false;
74  if ( mScaleMaxDenom > 0 && mScaleMaxDenom < scale )
75  return false;
76  return true;
77 }
78 
80 {
81  delete mSymbol;
82  mSymbol = s ? s->clone() : nullptr;
83  mOriginalSymbolPointer = s;
84 }
85 
87 {
88  delete mDataDefinedSizeLegendSettings;
89  mDataDefinedSizeLegendSettings = settings;
90 }
91 
93 {
94  return mDataDefinedSizeLegendSettings;
95 }
QgsLegendSymbolItem::setDataDefinedSizeLegendSettings
void setDataDefinedSizeLegendSettings(QgsDataDefinedSizeLegend *settings)
Sets extra information about data-defined size.
Definition: qgslegendsymbolitem.cpp:86
QgsLegendSymbolItem::setSymbol
void setSymbol(QgsSymbol *s)
Sets the symbol of the item.
Definition: qgslegendsymbolitem.cpp:79
QgsDataDefinedSizeLegend
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Definition: qgsdatadefinedsizelegend.h:42
QgsLegendSymbolItem::isScaleOK
bool isScaleOK(double scale) const
Determine whether given scale is within the scale range. Returns true if scale or scale range is inva...
Definition: qgslegendsymbolitem.cpp:66
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsLegendSymbolItem
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Definition: qgslegendsymbolitem.h:37
QgsLegendSymbolItem::~QgsLegendSymbolItem
~QgsLegendSymbolItem()
Definition: qgslegendsymbolitem.cpp:39
qgslegendsymbolitem.h
QgsSymbol::clone
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
QgsLegendSymbolItem::QgsLegendSymbolItem
QgsLegendSymbolItem()=default
Constructor for QgsLegendSymbolItem.
QgsLegendSymbolItem::dataDefinedSizeLegendSettings
QgsDataDefinedSizeLegend * dataDefinedSizeLegendSettings() const
Returns extra information for data-defined size legend rendering.
Definition: qgslegendsymbolitem.cpp:92
qgsdatadefinedsizelegend.h
qgssymbol.h
QgsLegendSymbolItem::operator=
QgsLegendSymbolItem & operator=(const QgsLegendSymbolItem &other)
Definition: qgslegendsymbolitem.cpp:45