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;
38     KChartEnums::GranularitySequence sequence;
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 
Private()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 
GridAttributes()71 GridAttributes::GridAttributes()
72     : _d( new Private() )
73 {
74     // this bloc left empty intentionally
75 }
76 
GridAttributes(const GridAttributes & r)77 GridAttributes::GridAttributes( const GridAttributes& r )
78     : _d( new Private( *r.d ) )
79 {
80 }
81 
operator =(const GridAttributes & r)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 
~GridAttributes()92 GridAttributes::~GridAttributes()
93 {
94     delete _d; _d = nullptr;
95 }
96 
97 
operator ==(const GridAttributes & r) const98 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 
setGridVisible(bool visible)113 void GridAttributes::setGridVisible( bool visible )
114 {
115     d->visible = visible;
116 }
117 
isGridVisible() const118 bool GridAttributes::isGridVisible() const
119 {
120     return d->visible;
121 }
122 
setLinesOnAnnotations(bool b)123 void GridAttributes::setLinesOnAnnotations( bool b )
124 {
125     d->linesOnAnnotations = b;
126 }
127 
linesOnAnnotations() const128 bool GridAttributes::linesOnAnnotations() const
129 {
130     return d->linesOnAnnotations;
131 }
132 
setGridStepWidth(qreal stepWidth)133 void GridAttributes::setGridStepWidth( qreal stepWidth )
134 {
135     d->stepWidth = stepWidth;
136 }
137 
gridStepWidth() const138 qreal GridAttributes::gridStepWidth() const
139 {
140     return d->stepWidth;
141 }
142 
143 
144 
setGridSubStepWidth(qreal subStepWidth)145 void GridAttributes::setGridSubStepWidth( qreal subStepWidth )
146 {
147     d->subStepWidth = subStepWidth;
148 }
149 
gridSubStepWidth() const150 qreal GridAttributes::gridSubStepWidth() const
151 {
152     return d->subStepWidth;
153 }
154 
setGridGranularitySequence(KChartEnums::GranularitySequence sequence)155 void GridAttributes::setGridGranularitySequence( KChartEnums::GranularitySequence sequence )
156 {
157     d->sequence = sequence;
158 }
159 
gridGranularitySequence() const160 KChartEnums::GranularitySequence GridAttributes::gridGranularitySequence() const
161 {
162     return d->sequence;
163 }
164 
setAdjustBoundsToGrid(bool adjustLower,bool adjustUpper)165 void GridAttributes::setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper )
166 {
167     d->adjustLower = adjustLower;
168     d->adjustUpper = adjustUpper;
169 }
adjustLowerBoundToGrid() const170 bool GridAttributes::adjustLowerBoundToGrid() const
171 {
172     return d->adjustLower;
173 }
adjustUpperBoundToGrid() const174 bool GridAttributes::adjustUpperBoundToGrid() const
175 {
176     return d->adjustUpper;
177 }
178 
setGridPen(const QPen & pen)179 void GridAttributes::setGridPen( const QPen & pen )
180 {
181     d->pen = pen;
182     d->pen.setCapStyle( Qt::FlatCap );
183 }
184 
gridPen() const185 QPen GridAttributes::gridPen() const
186 {
187     return d->pen;
188 }
189 
setSubGridVisible(bool visible)190 void GridAttributes::setSubGridVisible( bool visible )
191 {
192     d->subVisible = visible;
193 }
194 
isSubGridVisible() const195 bool GridAttributes::isSubGridVisible() const
196 {
197     return d->subVisible;
198 }
199 
setSubGridPen(const QPen & pen)200 void GridAttributes::setSubGridPen( const QPen & pen )
201 {
202     d->subPen = pen;
203     d->subPen.setCapStyle( Qt::FlatCap );
204 }
205 
subGridPen() const206 QPen GridAttributes::subGridPen() const
207 {
208     return d->subPen;
209 }
210 
setOuterLinesVisible(bool visible)211 void GridAttributes::setOuterLinesVisible( bool visible )
212 {
213     d->outerVisible = visible;
214 }
215 
isOuterLinesVisible() const216 bool GridAttributes::isOuterLinesVisible() const
217 {
218     return d->outerVisible;
219 }
220 
setZeroLinePen(const QPen & pen)221 void GridAttributes::setZeroLinePen( const QPen & pen )
222 {
223     d->zeroPen = pen;
224     d->zeroPen.setCapStyle( Qt::FlatCap );
225 }
226 
zeroLinePen() const227 QPen GridAttributes::zeroLinePen() const
228 {
229     return d->zeroPen;
230 }
231 
232 #if !defined(QT_NO_DEBUG_STREAM)
operator <<(QDebug dbg,const KChart::GridAttributes & a)233 QDebug operator<<(QDebug dbg, const KChart::GridAttributes& a)
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 
249