KD Chart 2  [rev.2.7]
KDChartGridAttributes.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include "KDChartGridAttributes.h"
24 
25 #include <QPen>
26 #include <QDebug>
27 
28 #include <KDABLibFakes>
29 
30 #define d d_func()
31 
32 using namespace KDChart;
33 
34 class GridAttributes::Private
35 {
36  friend class GridAttributes;
37 public:
38  Private();
39 private:
40  bool visible;
42  bool linesOnAnnotations;
43  qreal stepWidth;
44  qreal subStepWidth;
45  bool adjustLower;
46  bool adjustUpper;
47  QPen pen;
48  bool subVisible;
49  QPen subPen;
50  bool outerVisible;
51  QPen zeroPen;
52 };
53 
54 GridAttributes::Private::Private()
55  : visible( true ),
57  linesOnAnnotations( false ),
58  stepWidth( 0.0 ),
59  subStepWidth( 0.0 ),
60  adjustLower( true ),
61  adjustUpper( true ),
62  pen( QColor(0xa0, 0xa0, 0xa0 ) ),
63  subVisible( true ),
64  subPen( QColor(0xd0, 0xd0, 0xd0 ) ),
65  outerVisible( true ),
66  zeroPen( QColor( 0x00, 0x00, 0x80 ) )
67 {
68  pen.setCapStyle( Qt::FlatCap );
69  subPen.setCapStyle( Qt::FlatCap );
70  zeroPen.setCapStyle( Qt::FlatCap );
71 }
72 
73 
75  : _d( new Private() )
76 {
77  // this bloc left empty intentionally
78 }
79 
81  : _d( new Private( *r.d ) )
82 {
83 }
84 
86 {
87  if ( this == &r )
88  return *this;
89 
90  *d = *r.d;
91 
92  return *this;
93 }
94 
96 {
97  delete _d; _d = 0;
98 }
99 
100 
102 {
103  return isGridVisible() == r.isGridVisible() &&
108  gridPen() == r.gridPen() &&
110  subGridPen() == r.subGridPen() &&
112  zeroLinePen() == r.zeroLinePen();
113 }
114 
115 
116 void GridAttributes::setGridVisible( bool visible )
117 {
118  d->visible = visible;
119 }
120 
122 {
123  return d->visible;
124 }
125 
127 {
128  d->linesOnAnnotations = b;
129 }
130 
132 {
133  return d->linesOnAnnotations;
134 }
135 
154 void GridAttributes::setGridStepWidth( qreal stepWidth )
155 {
156  d->stepWidth = stepWidth;
157 }
158 
166 {
167  return d->stepWidth;
168 }
169 
170 
185 void GridAttributes::setGridSubStepWidth( qreal subStepWidth )
186 {
187  d->subStepWidth = subStepWidth;
188 }
189 
197 {
198  return d->subStepWidth;
199 }
200 
219 {
220  d->sequence = sequence;
221 }
222 
230 {
231  return d->sequence;
232 }
233 
234 void GridAttributes::setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper )
235 {
236  d->adjustLower = adjustLower;
237  d->adjustUpper = adjustUpper;
238 }
240 {
241  return d->adjustLower;
242 }
244 {
245  return d->adjustUpper;
246 }
247 
248 void GridAttributes::setGridPen( const QPen & pen )
249 {
250  d->pen = pen;
251  d->pen.setCapStyle( Qt::FlatCap );
252 }
253 
255 {
256  return d->pen;
257 }
258 
260 {
261  d->subVisible = visible;
262 }
263 
265 {
266  return d->subVisible;
267 }
268 
269 void GridAttributes::setSubGridPen( const QPen & pen )
270 {
271  d->subPen = pen;
272  d->subPen.setCapStyle( Qt::FlatCap );
273 }
274 
276 {
277  return d->subPen;
278 }
279 
281 {
282  d->outerVisible = visible;
283 }
284 
286 {
287  return d->outerVisible;
288 }
289 
290 void GridAttributes::setZeroLinePen( const QPen & pen )
291 {
292  d->zeroPen = pen;
293  d->zeroPen.setCapStyle( Qt::FlatCap );
294 }
295 
297 {
298  return d->zeroPen;
299 }
300 
301 #if !defined(QT_NO_DEBUG_STREAM)
302 QDebug operator<<(QDebug dbg, const KDChart::GridAttributes& a)
303 {
304  dbg << "KDChart::GridAttributes("
305  << "visible="<<a.isGridVisible()
306  << "subVisible="<<a.isSubGridVisible()
307  // KDChartEnums::GranularitySequence sequence;
308  << "stepWidth=" << a.gridStepWidth()
309  << "subStepWidth=" << a.gridSubStepWidth()
310  << "pen="<<a.gridPen()
311  << "subPen="<<a.subGridPen()
312  << "zeroPen="<<a.zeroLinePen()
313  << ")";
314  return dbg;
315 }
316 #endif /* QT_NO_DEBUG_STREAM */
317 
void setSubGridVisible(bool visible)
qreal gridSubStepWidth() const
Returns the sub-step width to be used for calculating the sub-grid lines.
void setSubGridPen(const QPen &pen)
void setGridSubStepWidth(qreal subStepWidth=0.0)
Specifies the sub-step width to be used for calculating the grid sub-lines.
void setAdjustBoundsToGrid(bool adjustLower, bool adjustUpper)
By default visible bounds of the data area are adjusted to match a main grid line.
GridAttributes & operator=(const GridAttributes &)
qreal gridStepWidth() const
Returns the step width to be used for calculating the grid lines.
GranularitySequence
GranularitySequence specifies the values, that may be applied, to determine a step width within a giv...
Definition: KDChartEnums.h:95
void setGridPen(const QPen &pen)
void setLinesOnAnnotations(bool)
When this is enabled, grid lines are drawn only where axis annotations are.
void setGridStepWidth(qreal stepWidth=0.0)
Specifies the step width to be used for calculating the grid lines.
bool operator==(const GridAttributes &) const
void setOuterLinesVisible(bool visible)
void setZeroLinePen(const QPen &pen)
KDChartEnums::GranularitySequence gridGranularitySequence() const
Returns the granularity sequence to be used for calculating the grid lines.
A set of attributes controlling the appearance of grids.
QDebug operator<<(QDebug stream, const DataDimension &r)
void setGridGranularitySequence(KDChartEnums::GranularitySequence sequence)
Specify which granularity sequence is to be used to find a matching grid granularity.
#define d

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/