File indexing completed on 2024-05-12 15:54:18

0001 /*
0002  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "KChartMarkerAttributes.h"
0021 
0022 #include "KChartMath_p.h"
0023 
0024 #include <QColor>
0025 #include <QMap>
0026 #include <QPen>
0027 #include <QPainterPath>
0028 #include <QSizeF>
0029 #include <QDebug>
0030 #include <qglobal.h>
0031 
0032 using namespace KChart;
0033 
0034 class Q_DECL_HIDDEN MarkerAttributes::Private
0035 {
0036     friend class ::KChart::MarkerAttributes;
0037 public:
0038     Private();
0039 private:
0040     bool visible;
0041     bool threeD;
0042     QMap<uint,uint> markerStylesMap;
0043     uint markerStyle;
0044     MarkerSizeMode markerSizeMode;
0045     QSizeF markerSize;
0046     QColor markerColor;
0047     QPainterPath customMarkerPath;
0048     QPen markerPen;
0049 };
0050 
0051 MarkerAttributes::Private::Private()
0052     : visible( false ),
0053       threeD( false ),
0054       markerStyle( MarkerSquare ),
0055       markerSizeMode( AbsoluteSize ),
0056       markerSize( 10, 10 ),
0057       markerPen( Qt::black )
0058 {
0059 }
0060 
0061 
0062 MarkerAttributes::MarkerAttributes()
0063     : _d( new Private )
0064 {
0065 
0066 }
0067 
0068 MarkerAttributes::MarkerAttributes( const MarkerAttributes& r )
0069     : _d( new Private( *r._d ) )
0070 {
0071 
0072 }
0073 
0074 MarkerAttributes & MarkerAttributes::operator=( const MarkerAttributes& r )
0075 {
0076     MarkerAttributes copy( r );
0077     copy.swap( *this );
0078     return *this;
0079 }
0080 
0081 MarkerAttributes::~MarkerAttributes()
0082 {
0083     delete _d; _d = nullptr;
0084 }
0085 
0086 #define d d_func()
0087 
0088 bool MarkerAttributes::operator==( const MarkerAttributes& r ) const
0089 {
0090     /*
0091     qDebug() << "MarkerAttributes::operator== finds"
0092             << "b" << (isVisible() == r.isVisible())
0093             << "c" << (markerStylesMap() == r.markerStylesMap())
0094             << "d" << (markerStyle() == r.markerStyle()) << markerStyle() <<r.markerStyle()
0095             << "e" << (markerSize() == r.markerSize())
0096             << "f" << (markerColor() == r.markerColor())
0097             << "p" << (customMarkerPath() == r.customMarkerPath())
0098             << "g" << (pen() == r.pen())
0099             << "h" << (markerColor() == r.markerColor()) << markerColor() << r.markerColor();
0100     */
0101     return ( isVisible() == r.isVisible() &&
0102             markerStylesMap() == r.markerStylesMap() &&
0103             markerStyle() == r.markerStyle() &&
0104             markerStyle() == r.markerStyle() &&
0105             markerSizeMode() == r.markerSizeMode() &&
0106             markerColor() == r.markerColor() &&
0107             customMarkerPath() == r.customMarkerPath() &&
0108             pen() == r.pen() );
0109 }
0110 
0111 
0112 
0113 void MarkerAttributes::setVisible( bool visible )
0114 {
0115     d->visible = visible;
0116 }
0117 
0118 bool MarkerAttributes::isVisible() const
0119 {
0120     return d->visible;
0121 }
0122 
0123 void MarkerAttributes::setThreeD( bool value )
0124 {
0125     d->threeD = value;
0126 }
0127 
0128 bool MarkerAttributes::threeD() const
0129 {
0130     return d->threeD;
0131 }
0132 
0133 void MarkerAttributes::setMarkerStylesMap( const MarkerStylesMap & map )
0134 {
0135     d->markerStylesMap = map;
0136 }
0137 
0138 MarkerAttributes::MarkerStylesMap MarkerAttributes::markerStylesMap() const
0139 {
0140     return d->markerStylesMap;
0141 }
0142 
0143 void MarkerAttributes::setMarkerStyle( uint style )
0144 {
0145     d->markerStyle = style;
0146 }
0147 
0148 uint MarkerAttributes::markerStyle() const
0149 {
0150     return d->markerStyle;
0151 }
0152 
0153 void MarkerAttributes::setMarkerSize( const QSizeF& size )
0154 {
0155     d->markerSize = size;
0156 }
0157 
0158 QSizeF MarkerAttributes::markerSize() const
0159 {
0160     return d->markerSize;
0161 }
0162 
0163 void MarkerAttributes::setMarkerSizeMode( MarkerSizeMode mode )
0164 {
0165     d->markerSizeMode = mode;
0166 }
0167 
0168 MarkerAttributes::MarkerSizeMode MarkerAttributes::markerSizeMode() const
0169 {
0170     return d->markerSizeMode;
0171 }
0172 
0173 
0174 void MarkerAttributes::setMarkerColor( const QColor& color )
0175 {
0176     d->markerColor = color;
0177 }
0178 
0179 QColor MarkerAttributes::markerColor() const
0180 {
0181     return d->markerColor;
0182 }
0183 
0184 void MarkerAttributes::setCustomMarkerPath( const QPainterPath& path )
0185 {
0186     d->customMarkerPath = path;
0187 }
0188 
0189 QPainterPath MarkerAttributes::customMarkerPath() const
0190 {
0191     return d->customMarkerPath;
0192 }
0193 
0194 void MarkerAttributes::setPen( const QPen& pen )
0195 {
0196     d->markerPen = pen;
0197 }
0198 
0199 QPen MarkerAttributes::pen() const
0200 {
0201     return d->markerPen;
0202 }
0203 
0204 #undef d
0205 
0206 #ifndef QT_NO_DEBUG_STREAM
0207 QDebug operator<<( QDebug dbg, const MarkerAttributes & ma ) {
0208     return dbg << "KChart::MarkerAttributes("
0209                << "visible=" << ma.isVisible()
0210                << "markerStylesMap=" << ma.markerStylesMap()
0211                << "markerStyle=" << ma.markerStyle()
0212                << "markerColor=" << ma.markerColor()
0213                << "customMarkerPath=" << ma.customMarkerPath()
0214                << "pen=" << ma.pen()
0215                << ")";
0216 }
0217 #endif
0218