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 "KChartMarkerAttributes.h"
21
22 #include "KChartMath_p.h"
23
24 #include <QColor>
25 #include <QMap>
26 #include <QPen>
27 #include <QPainterPath>
28 #include <QSizeF>
29 #include <QDebug>
30 #include <qglobal.h>
31
32 using namespace KChart;
33
34 class Q_DECL_HIDDEN MarkerAttributes::Private
35 {
36 friend class ::KChart::MarkerAttributes;
37 public:
38 Private();
39 private:
40 bool visible;
41 bool threeD;
42 QMap<uint,uint> markerStylesMap;
43 uint markerStyle;
44 MarkerSizeMode markerSizeMode;
45 QSizeF markerSize;
46 QColor markerColor;
47 QPainterPath customMarkerPath;
48 QPen markerPen;
49 };
50
Private()51 MarkerAttributes::Private::Private()
52 : visible( false ),
53 threeD( false ),
54 markerStyle( MarkerSquare ),
55 markerSizeMode( AbsoluteSize ),
56 markerSize( 10, 10 ),
57 markerPen( Qt::black )
58 {
59 }
60
61
MarkerAttributes()62 MarkerAttributes::MarkerAttributes()
63 : _d( new Private )
64 {
65
66 }
67
MarkerAttributes(const MarkerAttributes & r)68 MarkerAttributes::MarkerAttributes( const MarkerAttributes& r )
69 : _d( new Private( *r._d ) )
70 {
71
72 }
73
operator =(const MarkerAttributes & r)74 MarkerAttributes & MarkerAttributes::operator=( const MarkerAttributes& r )
75 {
76 MarkerAttributes copy( r );
77 copy.swap( *this );
78 return *this;
79 }
80
~MarkerAttributes()81 MarkerAttributes::~MarkerAttributes()
82 {
83 delete _d; _d = nullptr;
84 }
85
86 #define d d_func()
87
operator ==(const MarkerAttributes & r) const88 bool MarkerAttributes::operator==( const MarkerAttributes& r ) const
89 {
90 /*
91 qDebug() << "MarkerAttributes::operator== finds"
92 << "b" << (isVisible() == r.isVisible())
93 << "c" << (markerStylesMap() == r.markerStylesMap())
94 << "d" << (markerStyle() == r.markerStyle()) << markerStyle() <<r.markerStyle()
95 << "e" << (markerSize() == r.markerSize())
96 << "f" << (markerColor() == r.markerColor())
97 << "p" << (customMarkerPath() == r.customMarkerPath())
98 << "g" << (pen() == r.pen())
99 << "h" << (markerColor() == r.markerColor()) << markerColor() << r.markerColor();
100 */
101 return ( isVisible() == r.isVisible() &&
102 markerStylesMap() == r.markerStylesMap() &&
103 markerStyle() == r.markerStyle() &&
104 markerStyle() == r.markerStyle() &&
105 markerSizeMode() == r.markerSizeMode() &&
106 markerColor() == r.markerColor() &&
107 customMarkerPath() == r.customMarkerPath() &&
108 pen() == r.pen() );
109 }
110
111
112
setVisible(bool visible)113 void MarkerAttributes::setVisible( bool visible )
114 {
115 d->visible = visible;
116 }
117
isVisible() const118 bool MarkerAttributes::isVisible() const
119 {
120 return d->visible;
121 }
122
setThreeD(bool value)123 void MarkerAttributes::setThreeD( bool value )
124 {
125 d->threeD = value;
126 }
127
threeD() const128 bool MarkerAttributes::threeD() const
129 {
130 return d->threeD;
131 }
132
setMarkerStylesMap(const MarkerStylesMap & map)133 void MarkerAttributes::setMarkerStylesMap( const MarkerStylesMap & map )
134 {
135 d->markerStylesMap = map;
136 }
137
markerStylesMap() const138 MarkerAttributes::MarkerStylesMap MarkerAttributes::markerStylesMap() const
139 {
140 return d->markerStylesMap;
141 }
142
setMarkerStyle(uint style)143 void MarkerAttributes::setMarkerStyle( uint style )
144 {
145 d->markerStyle = style;
146 }
147
markerStyle() const148 uint MarkerAttributes::markerStyle() const
149 {
150 return d->markerStyle;
151 }
152
setMarkerSize(const QSizeF & size)153 void MarkerAttributes::setMarkerSize( const QSizeF& size )
154 {
155 d->markerSize = size;
156 }
157
markerSize() const158 QSizeF MarkerAttributes::markerSize() const
159 {
160 return d->markerSize;
161 }
162
setMarkerSizeMode(MarkerSizeMode mode)163 void MarkerAttributes::setMarkerSizeMode( MarkerSizeMode mode )
164 {
165 d->markerSizeMode = mode;
166 }
167
markerSizeMode() const168 MarkerAttributes::MarkerSizeMode MarkerAttributes::markerSizeMode() const
169 {
170 return d->markerSizeMode;
171 }
172
173
setMarkerColor(const QColor & color)174 void MarkerAttributes::setMarkerColor( const QColor& color )
175 {
176 d->markerColor = color;
177 }
178
markerColor() const179 QColor MarkerAttributes::markerColor() const
180 {
181 return d->markerColor;
182 }
183
setCustomMarkerPath(const QPainterPath & path)184 void MarkerAttributes::setCustomMarkerPath( const QPainterPath& path )
185 {
186 d->customMarkerPath = path;
187 }
188
customMarkerPath() const189 QPainterPath MarkerAttributes::customMarkerPath() const
190 {
191 return d->customMarkerPath;
192 }
193
setPen(const QPen & pen)194 void MarkerAttributes::setPen( const QPen& pen )
195 {
196 d->markerPen = pen;
197 }
198
pen() const199 QPen MarkerAttributes::pen() const
200 {
201 return d->markerPen;
202 }
203
204 #undef d
205
206 #ifndef QT_NO_DEBUG_STREAM
operator <<(QDebug dbg,const MarkerAttributes & ma)207 QDebug operator<<( QDebug dbg, const MarkerAttributes & ma ) {
208 return dbg << "KChart::MarkerAttributes("
209 << "visible=" << ma.isVisible()
210 << "markerStylesMap=" << ma.markerStylesMap()
211 << "markerStyle=" << ma.markerStyle()
212 << "markerColor=" << ma.markerColor()
213 << "customMarkerPath=" << ma.customMarkerPath()
214 << "pen=" << ma.pen()
215 << ")";
216 }
217 #endif
218
219