1 /*
2 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "KChartBarAttributes.h"
21
22 #include "KChartMath_p.h"
23
24 #include <qglobal.h>
25
26 #define d d_func()
27
28
29 using namespace KChart;
30
31 class Q_DECL_HIDDEN BarAttributes::Private
32 {
33 friend class BarAttributes;
34 public:
35 Private();
36
37 private:
38 qreal datasetGap;
39 bool useFixedDatasetGap;
40 qreal valueBlockGap;
41 bool useFixedValueBlockGap;
42 qreal barWidth;
43 bool useFixedBarWidth;
44 bool drawSolidExcessArrows;
45 qreal groupGapFactor;
46 qreal barGapFactor;
47 };
48
49
Private()50 BarAttributes::Private::Private()
51 :datasetGap( 6 ),
52 useFixedDatasetGap( false ),
53 valueBlockGap( 24 ),
54 useFixedValueBlockGap( false ),
55 barWidth( -1 ),
56 useFixedBarWidth( false ),
57 drawSolidExcessArrows( false ),
58 groupGapFactor( 2.0 ),
59 barGapFactor( 0.4 )
60 {
61 }
62
63
BarAttributes()64 BarAttributes::BarAttributes()
65 : _d( new Private() )
66 {
67 }
68
BarAttributes(const BarAttributes & r)69 BarAttributes::BarAttributes( const BarAttributes& r )
70 : _d( new Private( *r.d ) )
71 {
72 }
73
operator =(const BarAttributes & r)74 BarAttributes& BarAttributes::operator= ( const BarAttributes& r )
75 {
76 if ( this == &r )
77 return *this;
78
79 *d = *r.d;
80
81 return *this;
82 }
83
~BarAttributes()84 BarAttributes::~BarAttributes()
85 {
86 delete _d; _d = nullptr;
87 }
88
89
operator ==(const BarAttributes & r) const90 bool BarAttributes::operator==( const BarAttributes& r ) const
91 {
92 if ( fixedDataValueGap() == r.fixedDataValueGap() &&
93 useFixedDataValueGap() == r.useFixedDataValueGap() &&
94 fixedValueBlockGap() == r.fixedValueBlockGap() &&
95 useFixedValueBlockGap() == r.useFixedValueBlockGap() &&
96 fixedBarWidth() == r.fixedBarWidth() &&
97 useFixedBarWidth() == r.useFixedBarWidth() &&
98 groupGapFactor() == r.groupGapFactor() &&
99 barGapFactor() == r.barGapFactor() &&
100 drawSolidExcessArrows() == r.drawSolidExcessArrows() )
101 return true;
102 else
103 return false;
104 }
105
106
setFixedDataValueGap(qreal gap)107 void BarAttributes::setFixedDataValueGap( qreal gap )
108 {
109 d->datasetGap = gap;
110 }
111
fixedDataValueGap() const112 qreal BarAttributes::fixedDataValueGap() const
113 {
114 return d->datasetGap;
115 }
116
setUseFixedDataValueGap(bool gapIsFixed)117 void BarAttributes::setUseFixedDataValueGap( bool gapIsFixed )
118 {
119 d->useFixedDatasetGap = gapIsFixed;
120 }
121
useFixedDataValueGap() const122 bool BarAttributes::useFixedDataValueGap() const
123 {
124 return d->useFixedDatasetGap;
125 }
126
setFixedValueBlockGap(qreal gap)127 void BarAttributes::setFixedValueBlockGap( qreal gap )
128 {
129 d->valueBlockGap = gap;
130 }
131
fixedValueBlockGap() const132 qreal BarAttributes::fixedValueBlockGap() const
133 {
134 return d->valueBlockGap;
135 }
136
setUseFixedValueBlockGap(bool gapIsFixed)137 void BarAttributes::setUseFixedValueBlockGap( bool gapIsFixed )
138 {
139 d->useFixedValueBlockGap = gapIsFixed;
140 }
141
useFixedValueBlockGap() const142 bool BarAttributes::useFixedValueBlockGap() const
143 {
144 return d->useFixedValueBlockGap;
145 }
146
setFixedBarWidth(qreal width)147 void BarAttributes::setFixedBarWidth( qreal width )
148 {
149 d->barWidth = width;
150 }
151
fixedBarWidth() const152 qreal BarAttributes::fixedBarWidth() const
153 {
154
155 return d->barWidth;
156 }
157
setUseFixedBarWidth(bool useFixedBarWidth)158 void BarAttributes::setUseFixedBarWidth( bool useFixedBarWidth )
159 {
160 d->useFixedBarWidth = useFixedBarWidth;
161 }
162
useFixedBarWidth() const163 bool BarAttributes::useFixedBarWidth() const
164 {
165 return d->useFixedBarWidth;
166 }
167
setGroupGapFactor(qreal gapFactor)168 void BarAttributes::setGroupGapFactor( qreal gapFactor )
169 {
170 d->groupGapFactor = gapFactor;
171 }
172
groupGapFactor() const173 qreal BarAttributes::groupGapFactor() const
174 {
175 return d->groupGapFactor;
176 }
177
setBarGapFactor(qreal gapFactor)178 void BarAttributes::setBarGapFactor( qreal gapFactor )
179 {
180 d->barGapFactor = gapFactor;
181 }
182
barGapFactor() const183 qreal BarAttributes::barGapFactor() const
184 {
185 return d->barGapFactor;
186 }
187
setDrawSolidExcessArrows(bool solidArrows)188 void BarAttributes::setDrawSolidExcessArrows( bool solidArrows )
189 {
190 d->drawSolidExcessArrows = solidArrows;
191 }
192
drawSolidExcessArrows() const193 bool BarAttributes::drawSolidExcessArrows() const
194 {
195 return d->drawSolidExcessArrows;
196 }
197
198