KChart

KChartGridAttributes.cpp
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 "KChartGridAttributes.h"
21 
22 #include "KChartMath_p.h"
23 
24 #include <QPen>
25 #include <QDebug>
26 
27 #define d d_func()
28 
29 using namespace KChart;
30 
31 class Q_DECL_HIDDEN GridAttributes::Private
32 {
33  friend class GridAttributes;
34 public:
35  Private();
36 private:
37  bool visible;
39  bool linesOnAnnotations;
40  qreal stepWidth;
41  qreal subStepWidth;
42  bool adjustLower;
43  bool adjustUpper;
44  QPen pen;
45  bool subVisible;
46  QPen subPen;
47  bool outerVisible;
48  QPen zeroPen;
49 };
50 
51 GridAttributes::Private::Private()
52  : visible( true ),
53  sequence( KChartEnums::GranularitySequence_10_20 ),
54  linesOnAnnotations( false ),
55  stepWidth( 0.0 ),
56  subStepWidth( 0.0 ),
57  adjustLower( true ),
58  adjustUpper( true ),
59  pen( QColor(0xa0, 0xa0, 0xa0 ) ),
60  subVisible( true ),
61  subPen( QColor(0xd0, 0xd0, 0xd0 ) ),
62  outerVisible( true ),
63  zeroPen( QColor( 0x00, 0x00, 0x80 ) )
64 {
65  pen.setCapStyle( Qt::FlatCap );
66  subPen.setCapStyle( Qt::FlatCap );
67  zeroPen.setCapStyle( Qt::FlatCap );
68 }
69 
70 
71 GridAttributes::GridAttributes()
72  : _d( new Private() )
73 {
74  // this bloc left empty intentionally
75 }
76 
77 GridAttributes::GridAttributes( const GridAttributes& r )
78  : _d( new Private( *r.d ) )
79 {
80 }
81 
82 GridAttributes & GridAttributes::operator=( const GridAttributes& r )
83 {
84  if ( this == &r )
85  return *this;
86 
87  *d = *r.d;
88 
89  return *this;
90 }
91 
92 GridAttributes::~GridAttributes()
93 {
94  delete _d; _d = nullptr;
95 }
96 
97 
98 bool GridAttributes::operator==( const GridAttributes& r ) const
99 {
100  return isGridVisible() == r.isGridVisible() &&
101  gridGranularitySequence() == r.gridGranularitySequence() &&
102  linesOnAnnotations() == r.linesOnAnnotations() &&
103  adjustLowerBoundToGrid() == r.adjustLowerBoundToGrid() &&
104  adjustUpperBoundToGrid() == r.adjustUpperBoundToGrid() &&
105  gridPen() == r.gridPen() &&
106  isSubGridVisible() == r.isSubGridVisible() &&
107  subGridPen() == r.subGridPen() &&
108  isOuterLinesVisible() == r.isOuterLinesVisible() &&
109  zeroLinePen() == r.zeroLinePen();
110 }
111 
112 
113 void GridAttributes::setGridVisible( bool visible )
114 {
115  d->visible = visible;
116 }
117 
118 bool GridAttributes::isGridVisible() const
119 {
120  return d->visible;
121 }
122 
124 {
125  d->linesOnAnnotations = b;
126 }
127 
128 bool GridAttributes::linesOnAnnotations() const
129 {
130  return d->linesOnAnnotations;
131 }
132 
133 void GridAttributes::setGridStepWidth( qreal stepWidth )
134 {
135  d->stepWidth = stepWidth;
136 }
137 
139 {
140  return d->stepWidth;
141 }
142 
143 
144 
145 void GridAttributes::setGridSubStepWidth( qreal subStepWidth )
146 {
147  d->subStepWidth = subStepWidth;
148 }
149 
151 {
152  return d->subStepWidth;
153 }
154 
156 {
157  d->sequence = sequence;
158 }
159 
161 {
162  return d->sequence;
163 }
164 
165 void GridAttributes::setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper )
166 {
167  d->adjustLower = adjustLower;
168  d->adjustUpper = adjustUpper;
169 }
170 bool GridAttributes::adjustLowerBoundToGrid() const
171 {
172  return d->adjustLower;
173 }
174 bool GridAttributes::adjustUpperBoundToGrid() const
175 {
176  return d->adjustUpper;
177 }
178 
179 void GridAttributes::setGridPen( const QPen & pen )
180 {
181  d->pen = pen;
182  d->pen.setCapStyle( Qt::FlatCap );
183 }
184 
185 QPen GridAttributes::gridPen() const
186 {
187  return d->pen;
188 }
189 
190 void GridAttributes::setSubGridVisible( bool visible )
191 {
192  d->subVisible = visible;
193 }
194 
195 bool GridAttributes::isSubGridVisible() const
196 {
197  return d->subVisible;
198 }
199 
200 void GridAttributes::setSubGridPen( const QPen & pen )
201 {
202  d->subPen = pen;
203  d->subPen.setCapStyle( Qt::FlatCap );
204 }
205 
206 QPen GridAttributes::subGridPen() const
207 {
208  return d->subPen;
209 }
210 
211 void GridAttributes::setOuterLinesVisible( bool visible )
212 {
213  d->outerVisible = visible;
214 }
215 
216 bool GridAttributes::isOuterLinesVisible() const
217 {
218  return d->outerVisible;
219 }
220 
221 void GridAttributes::setZeroLinePen( const QPen & pen )
222 {
223  d->zeroPen = pen;
224  d->zeroPen.setCapStyle( Qt::FlatCap );
225 }
226 
227 QPen GridAttributes::zeroLinePen() const
228 {
229  return d->zeroPen;
230 }
231 
232 #if !defined(QT_NO_DEBUG_STREAM)
234 {
235  dbg << "KChart::GridAttributes("
236  << "visible="<<a.isGridVisible()
237  << "subVisible="<<a.isSubGridVisible()
238  // KChartEnums::GranularitySequence sequence;
239  << "stepWidth=" << a.gridStepWidth()
240  << "subStepWidth=" << a.gridSubStepWidth()
241  << "pen="<<a.gridPen()
242  << "subPen="<<a.subGridPen()
243  << "zeroPen="<<a.zeroLinePen()
244  << ")";
245  return dbg;
246 }
247 #endif /* QT_NO_DEBUG_STREAM */
248 
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:37
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:89
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 Sat Jan 16 2021 22:38:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.