KChart

KChartGridAttributes.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 "KChartGridAttributes.h"
10 
11 #include "KChartMath_p.h"
12 
13 #include <QPen>
14 #include <QDebug>
15 
16 #define d d_func()
17 
18 using namespace KChart;
19 
20 class Q_DECL_HIDDEN GridAttributes::Private
21 {
22  friend class GridAttributes;
23 public:
24  Private();
25 private:
26  bool visible;
28  bool linesOnAnnotations;
29  qreal stepWidth;
30  qreal subStepWidth;
31  bool adjustLower;
32  bool adjustUpper;
33  QPen pen;
34  bool subVisible;
35  QPen subPen;
36  bool outerVisible;
37  QPen zeroPen;
38 };
39 
40 GridAttributes::Private::Private()
41  : visible( true ),
42  sequence( KChartEnums::GranularitySequence_10_20 ),
43  linesOnAnnotations( false ),
44  stepWidth( 0.0 ),
45  subStepWidth( 0.0 ),
46  adjustLower( true ),
47  adjustUpper( true ),
48  pen( QColor(0xa0, 0xa0, 0xa0 ) ),
49  subVisible( true ),
50  subPen( QColor(0xd0, 0xd0, 0xd0 ) ),
51  outerVisible( true ),
52  zeroPen( QColor( 0x00, 0x00, 0x80 ) )
53 {
54  pen.setCapStyle( Qt::FlatCap );
55  subPen.setCapStyle( Qt::FlatCap );
56  zeroPen.setCapStyle( Qt::FlatCap );
57 }
58 
59 
60 GridAttributes::GridAttributes()
61  : _d( new Private() )
62 {
63  // this block left empty intentionally
64 }
65 
66 GridAttributes::GridAttributes( const GridAttributes& r )
67  : _d( new Private( *r.d ) )
68 {
69 }
70 
71 GridAttributes & GridAttributes::operator=( const GridAttributes& r )
72 {
73  if ( this == &r )
74  return *this;
75 
76  *d = *r.d;
77 
78  return *this;
79 }
80 
81 GridAttributes::~GridAttributes()
82 {
83  delete _d; _d = nullptr;
84 }
85 
86 
87 bool GridAttributes::operator==( const GridAttributes& r ) const
88 {
89  return isGridVisible() == r.isGridVisible() &&
90  gridGranularitySequence() == r.gridGranularitySequence() &&
91  linesOnAnnotations() == r.linesOnAnnotations() &&
92  adjustLowerBoundToGrid() == r.adjustLowerBoundToGrid() &&
93  adjustUpperBoundToGrid() == r.adjustUpperBoundToGrid() &&
94  gridPen() == r.gridPen() &&
95  isSubGridVisible() == r.isSubGridVisible() &&
96  subGridPen() == r.subGridPen() &&
97  isOuterLinesVisible() == r.isOuterLinesVisible() &&
98  zeroLinePen() == r.zeroLinePen();
99 }
100 
101 
102 void GridAttributes::setGridVisible( bool visible )
103 {
104  d->visible = visible;
105 }
106 
107 bool GridAttributes::isGridVisible() const
108 {
109  return d->visible;
110 }
111 
113 {
114  d->linesOnAnnotations = b;
115 }
116 
117 bool GridAttributes::linesOnAnnotations() const
118 {
119  return d->linesOnAnnotations;
120 }
121 
122 void GridAttributes::setGridStepWidth( qreal stepWidth )
123 {
124  d->stepWidth = stepWidth;
125 }
126 
128 {
129  return d->stepWidth;
130 }
131 
132 
133 
134 void GridAttributes::setGridSubStepWidth( qreal subStepWidth )
135 {
136  d->subStepWidth = subStepWidth;
137 }
138 
140 {
141  return d->subStepWidth;
142 }
143 
145 {
146  d->sequence = sequence;
147 }
148 
150 {
151  return d->sequence;
152 }
153 
154 void GridAttributes::setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper )
155 {
156  d->adjustLower = adjustLower;
157  d->adjustUpper = adjustUpper;
158 }
159 bool GridAttributes::adjustLowerBoundToGrid() const
160 {
161  return d->adjustLower;
162 }
163 bool GridAttributes::adjustUpperBoundToGrid() const
164 {
165  return d->adjustUpper;
166 }
167 
168 void GridAttributes::setGridPen( const QPen & pen )
169 {
170  d->pen = pen;
171  d->pen.setCapStyle( Qt::FlatCap );
172 }
173 
174 QPen GridAttributes::gridPen() const
175 {
176  return d->pen;
177 }
178 
179 void GridAttributes::setSubGridVisible( bool visible )
180 {
181  d->subVisible = visible;
182 }
183 
184 bool GridAttributes::isSubGridVisible() const
185 {
186  return d->subVisible;
187 }
188 
189 void GridAttributes::setSubGridPen( const QPen & pen )
190 {
191  d->subPen = pen;
192  d->subPen.setCapStyle( Qt::FlatCap );
193 }
194 
195 QPen GridAttributes::subGridPen() const
196 {
197  return d->subPen;
198 }
199 
200 void GridAttributes::setOuterLinesVisible( bool visible )
201 {
202  d->outerVisible = visible;
203 }
204 
205 bool GridAttributes::isOuterLinesVisible() const
206 {
207  return d->outerVisible;
208 }
209 
210 void GridAttributes::setZeroLinePen( const QPen & pen )
211 {
212  d->zeroPen = pen;
213  d->zeroPen.setCapStyle( Qt::FlatCap );
214 }
215 
216 QPen GridAttributes::zeroLinePen() const
217 {
218  return d->zeroPen;
219 }
220 
221 #if !defined(QT_NO_DEBUG_STREAM)
223 {
224  dbg << "KChart::GridAttributes("
225  << "visible="<<a.isGridVisible()
226  << "subVisible="<<a.isSubGridVisible()
227  // KChartEnums::GranularitySequence sequence;
228  << "stepWidth=" << a.gridStepWidth()
229  << "subStepWidth=" << a.gridSubStepWidth()
230  << "pen="<<a.gridPen()
231  << "subPen="<<a.subGridPen()
232  << "zeroPen="<<a.zeroLinePen()
233  << ")";
234  return dbg;
235 }
236 #endif /* QT_NO_DEBUG_STREAM */
237 
qreal gridSubStepWidth() const
Returns the sub-step width to be used for calculating the sub-grid lines.
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.
Project global class providing some enums needed both by KChartParams and by KChartCustomBox.
Definition: KChartEnums.h:26
qreal gridStepWidth() const
Returns the step width to be used for calculating the grid lines.
void setCapStyle(Qt::PenCapStyle style)
GranularitySequence
GranularitySequence specifies the values, that may be applied, to determine a step width within a giv...
Definition: KChartEnums.h:78
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
void setLinesOnAnnotations(bool)
When this is enabled, grid lines are drawn only where axis annotations are.
A set of attributes controlling the appearance of grids.
void setGridStepWidth(qreal stepWidth=0.0)
Specifies the step width to be used for calculating the grid lines.
void setGridGranularitySequence(KChartEnums::GranularitySequence sequence)
Specifies the granularity sequence to be used for calculating the grid lines.
Global namespace.
KChartEnums::GranularitySequence gridGranularitySequence() const
Returns the granularity sequence to be used for calculating the grid lines.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 22:33:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.