KChart

KChartRulerAttributes.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "KChartRulerAttributes.h"
10
11#include "KChartMath_p.h"
12
13#include <QPen>
14#include <QDebug>
15
16#define d d_func()
17
18using namespace KChart;
19
20class Q_DECL_HIDDEN RulerAttributes::Private
21{
22 friend class RulerAttributes;
23public:
24 Private();
25private:
26 QPen tickMarkPen;
27 QPen majorTickMarkPen;
28 QPen minorTickMarkPen;
29 QPen rulerLinePen;
30
31 bool majorTickMarkPenIsSet : 1;
32 bool minorTickMarkPenIsSet : 1;
33
34 bool showMajorTickMarks : 1;
35 bool showMinorTickMarks : 1;
36
37 bool showRulerLine : 1;
38
39 bool majorTickLengthIsSet : 1;
40 bool minorTickLengthIsSet : 1;
41
42 bool showFirstTick : 1;
43
44 int labelMargin;
45 int majorTickLength;
46 int minorTickLength;
47
48 RulerAttributes::TickMarkerPensMap customTickMarkPens;
49};
50
51RulerAttributes::Private::Private()
52 : tickMarkPen( Qt::black )
53 , majorTickMarkPen( Qt::black )
54 , minorTickMarkPen( Qt::black )
55 , majorTickMarkPenIsSet( false )
56 , minorTickMarkPenIsSet( false )
57 , showMajorTickMarks( true )
58 , showMinorTickMarks( true )
59 , showRulerLine( false )
60 , majorTickLengthIsSet( false )
61 , minorTickLengthIsSet( false )
62 , showFirstTick( true )
63 , labelMargin( -1 )
64 , majorTickLength( 3 )
65 , minorTickLength( 2 )
66{
67 tickMarkPen.setCapStyle( Qt::FlatCap );
68 majorTickMarkPen.setCapStyle( Qt::FlatCap );
69 minorTickMarkPen.setCapStyle( Qt::FlatCap );
70}
71
72RulerAttributes::RulerAttributes()
73 : _d( new Private() )
74{
75 // this block left empty intentionally
76}
77
78RulerAttributes::RulerAttributes( const RulerAttributes& r )
79 : _d( new Private( *r.d ) )
80{
81}
82
84{
85 d->tickMarkPen = pen;
86}
87
88QPen RulerAttributes::tickMarkPen() const
89{
90 return d->tickMarkPen;
91}
92
94{
95 d->majorTickMarkPen = pen;
96 d->majorTickMarkPenIsSet = true;
97}
98
99bool RulerAttributes::majorTickMarkPenIsSet() const
100{
101 return d->majorTickMarkPenIsSet;
102}
103
104QPen RulerAttributes::majorTickMarkPen() const
105{
106 return d->majorTickMarkPenIsSet ? d->majorTickMarkPen : d->tickMarkPen;
107}
108
110{
111 d->minorTickMarkPen = pen;
112 d->minorTickMarkPenIsSet = true;
113}
114
115bool RulerAttributes::minorTickMarkPenIsSet() const
116{
117 return d->minorTickMarkPenIsSet;
118}
119
120QPen RulerAttributes::minorTickMarkPen() const
121{
122 return d->minorTickMarkPenIsSet ? d->minorTickMarkPen : d->tickMarkPen;
123}
124
125void RulerAttributes::setTickMarkPen( qreal value, const QPen& pen )
126{
127 if ( !d->customTickMarkPens.contains( value ) )
128 d->customTickMarkPens.insert( value, pen );
129}
130
131QPen RulerAttributes::tickMarkPen( qreal value ) const
132{
133 QMapIterator<qreal, QPen> it( d->customTickMarkPens );
134 while ( it.hasNext() ) {
135 it.next();
136 if ( qAbs( value - it.key() ) < std::numeric_limits< float >::epsilon() )
137 return it.value();
138 }
139 return d->tickMarkPen;
140}
141
142RulerAttributes::TickMarkerPensMap RulerAttributes::tickMarkPens() const
143{
144 return d->customTickMarkPens;
145}
146
147bool RulerAttributes::hasTickMarkPenAt( qreal value ) const
148{
149 QMapIterator<qreal, QPen> it( d->customTickMarkPens );
150 while ( it.hasNext() ) {
151 it.next();
152 if ( qAbs( value - it.key() ) < std::numeric_limits< float >::epsilon() )
153 return true;
154 }
155 return false;
156}
157
159{
160 d->tickMarkPen.setColor( color );
161}
162
163QColor RulerAttributes::tickMarkColor() const
164{
165 return d->tickMarkPen.color();
166}
167
169{
170 d->showMajorTickMarks = show;
171}
172
173bool RulerAttributes::showMajorTickMarks() const
174{
175 return d->showMajorTickMarks;
176}
177
179{
180 d->showMinorTickMarks = show;
181}
182
183bool RulerAttributes::showMinorTickMarks() const
184{
185 return d->showMinorTickMarks;
186}
187
189{
190 d->labelMargin = margin;
191}
192
193int RulerAttributes::labelMargin() const
194{
195 return d->labelMargin;
196}
197
199{
200 d->majorTickLength = length;
201 d->majorTickLengthIsSet = true;
202}
203
204int RulerAttributes::majorTickMarkLength() const
205{
206 return d->majorTickLength;
207}
208
209bool RulerAttributes::majorTickMarkLengthIsSet() const
210{
211 return d->majorTickLengthIsSet;
212}
213
215{
216 d->minorTickLength = length;
217 d->minorTickLengthIsSet = true;
218}
219
220int RulerAttributes::minorTickMarkLength() const
221{
222 return d->minorTickLength;
223}
224
225bool RulerAttributes::minorTickMarkLengthIsSet() const
226{
227 return d->minorTickLengthIsSet;
228}
229
231{
232 d->showFirstTick = show;
233}
234
235bool RulerAttributes::showFirstTick() const
236{
237 return d->showFirstTick;
238}
239
240RulerAttributes & RulerAttributes::operator=( const RulerAttributes& r )
241{
242 if ( this == &r )
243 return *this;
244
245 *d = *r.d;
246
247 return *this;
248}
249
250RulerAttributes::~RulerAttributes()
251{
252 delete _d; _d = nullptr;
253}
254
255bool RulerAttributes::operator==( const RulerAttributes& r ) const
256{
257 bool isEqual = tickMarkPen() == r.tickMarkPen() &&
258 majorTickMarkPen() == r.majorTickMarkPen() &&
259 minorTickMarkPen() == r.minorTickMarkPen() &&
260 majorTickMarkPenIsSet() == r.majorTickMarkPenIsSet() &&
261 minorTickMarkPenIsSet() == r.minorTickMarkPenIsSet() &&
262 showMajorTickMarks() == r.showMajorTickMarks() &&
263 showMinorTickMarks() == r.showMinorTickMarks() &&
264 rulerLinePen() == r.rulerLinePen() &&
265 showRulerLine() == r.showRulerLine() &&
266 majorTickMarkLengthIsSet() == r.majorTickMarkLengthIsSet() &&
267 minorTickMarkLengthIsSet() == r.minorTickMarkLengthIsSet() &&
268 showFirstTick() == r.showFirstTick() &&
269 d->customTickMarkPens.size() == r.d->customTickMarkPens.size();
270 if ( !isEqual ) {
271 return false;
272 }
273 QMap< qreal, QPen >::ConstIterator it = d->customTickMarkPens.constBegin();
274 QMap< qreal, QPen >::ConstIterator it2 = r.d->customTickMarkPens.constBegin();
275 for ( ; it != d->customTickMarkPens.constEnd(); ++it, ++it2 ) {
276 if ( it.key() != it2.key() || it.value() != it2.value() ) {
277 return false;
278 }
279 }
280 return true;
281}
282
284{
285 d->rulerLinePen = pen;
286}
287
289{
290 return d->rulerLinePen;
291}
292
293void RulerAttributes::setShowRulerLine( bool show )
294{
295 d->showRulerLine = show;
296}
297
298bool RulerAttributes::showRulerLine() const
299{
300 return d->showRulerLine;
301}
302
303#if !defined( QT_NO_DEBUG_STREAM )
304QDebug operator << ( QDebug dbg, const KChart::RulerAttributes& a )
305{
306 dbg << "KChart::RulerAttributes("
307 << "tickMarkPen=" << a.tickMarkPen()
308 << "majorTickMarkPen=" << a.majorTickMarkPen()
309 << "minorTickMarkPen=" << a.minorTickMarkPen();
310 const RulerAttributes::TickMarkerPensMap pens( a.tickMarkPens() );
311 QMapIterator<qreal, QPen> it( pens );
312 while ( it.hasNext() ) {
313 it.next();
314 dbg << "customTickMarkPen=(" << it.value() << " : " << it.key() << ")";
315 }
316 dbg << ")";
317 return dbg;
318}
319#endif /* QT_NO_DEBUG_STREAM */
320
A set of attributes controlling the appearance of axis rulers.
void setLabelMargin(int margin)
Set margin that should be used between the labels and the ticks.
void setTickMarkColor(const QColor &color)
Color setter method provided for convenience.
void setShowMinorTickMarks(bool show)
Shows or hides minor tick marks.
void setMinorTickMarkLength(int length)
Sets the length of minor tick marks.
void setRulerLinePen(const QPen &pen)
Set the ruler line pen to pen.
void setShowFirstTick(bool show)
Shows or hides the first tick.
void setMajorTickMarkPen(const QPen &pen)
Sets the pen used to draw major tick marks.
void setMajorTickMarkLength(int length)
Sets the length of major tick marks.
void setMinorTickMarkPen(const QPen &pen)
Sets the pen used to draw minor tick marks.
void setShowMajorTickMarks(bool show)
Shows or hides major tick marks.
void setTickMarkPen(const QPen &pen)
Sets the pen used to draw the tick marks.
Key key(const T &value, const Key &defaultKey) const const
T value(const Key &key, const T &defaultValue) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.