QGIS API Documentation  2.12.0-Lyon
qgslegendsymbolitemv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslegendsymbolitemv2.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 "qgslegendsymbolitemv2.h"
17 
18 #include "qgssymbolv2.h"
19 
21  : mSymbol( 0 )
22  , mCheckable( false )
23  , mOriginalSymbolPointer( 0 )
24  , mScaleMinDenom( -1 )
25  , mScaleMaxDenom( -1 )
26  , mLevel( 0 )
27 {
28 }
29 
30 QgsLegendSymbolItemV2::QgsLegendSymbolItemV2( QgsSymbolV2* symbol, const QString& label, const QString& ruleKey, bool checkable, int scaleMinDenom, int scaleMaxDenom, int level, const QString& parentRuleKey )
31  : mSymbol( symbol ? symbol->clone() : 0 )
32  , mLabel( label )
33  , mKey( ruleKey )
34  , mCheckable( checkable )
35  , mOriginalSymbolPointer( symbol )
36  , mScaleMinDenom( scaleMinDenom )
37  , mScaleMaxDenom( scaleMaxDenom )
38  , mLevel( level )
39  , mParentKey( parentRuleKey )
40 {
41 }
42 
44  : mSymbol( 0 )
45  , mOriginalSymbolPointer( 0 )
46 {
47  *this = other;
48 }
49 
51 {
52  delete mSymbol;
53 }
54 
56 {
57  if ( this == &other )
58  return *this;
59 
60  setSymbol( other.mSymbol );
61  mLabel = other.mLabel;
62  mKey = other.mKey;
63  mCheckable = other.mCheckable;
64  mOriginalSymbolPointer = other.mOriginalSymbolPointer;
65  mScaleMinDenom = other.mScaleMinDenom;
66  mScaleMaxDenom = other.mScaleMaxDenom;
67  mLevel = other.mLevel;
68  mParentKey = other.mParentKey;
69 
70  return *this;
71 }
72 
73 bool QgsLegendSymbolItemV2::isScaleOK( double scale ) const
74 {
75  if ( scale <= 0 )
76  return true;
77  if ( mScaleMinDenom <= 0 && mScaleMaxDenom <= 0 )
78  return true;
79  if ( mScaleMinDenom > 0 && mScaleMinDenom > scale )
80  return false;
81  if ( mScaleMaxDenom > 0 && mScaleMaxDenom < scale )
82  return false;
83  return true;
84 }
85 
87 {
88  delete mSymbol;
89  mSymbol = s ? s->clone() : 0;
90  mOriginalSymbolPointer = s;
91 }
virtual QgsSymbolV2 * clone() const =0
QgsLegendSymbolItemV2 & operator=(const QgsLegendSymbolItemV2 &other)
void setSymbol(QgsSymbolV2 *s)
Set symbol of the item. Takes ownership of symbol.
bool isScaleOK(double scale) const
Determine whether given scale is within the scale range. Returns true if scale or scale range is inva...
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...