File indexing completed on 2024-12-15 04:02:32

0001 /*
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "KChartLeveyJenningsGridAttributes.h"
0010 
0011 #include "KChartMath_p.h"
0012 
0013 #include <QBrush>
0014 #include <QMap>
0015 #include <QPen>
0016 
0017 #define d d_func()
0018 
0019 using namespace KChart;
0020 
0021 class Q_DECL_HIDDEN LeveyJenningsGridAttributes::Private
0022 {
0023     friend class LeveyJenningsGridAttributes;
0024 public:
0025     Private();
0026 private:
0027     QMap< GridType, bool > visible;
0028     QMap< GridType, QPen > pens;
0029     QMap< LeveyJenningsGridAttributes::Range, QBrush > rangeBrushes;
0030 };
0031 
0032 LeveyJenningsGridAttributes::Private::Private()
0033 {
0034     pens[ Calculated ].setCapStyle( Qt::FlatCap );
0035     pens[ Calculated ].setColor( Qt::blue );
0036     pens[ Expected ].setCapStyle( Qt::FlatCap );
0037     pens[ Expected ].setColor( Qt::black );
0038     
0039     visible[ Calculated ] = true;
0040     visible[ Expected ] = true;
0041     
0042     rangeBrushes[ LeveyJenningsGridAttributes::CriticalRange ] = QBrush( QColor( 255, 255, 192 ) );
0043     rangeBrushes[ LeveyJenningsGridAttributes::OutOfRange ]    = QBrush( QColor( 255, 128, 128 ) );
0044 }
0045 
0046 
0047 LeveyJenningsGridAttributes::LeveyJenningsGridAttributes()
0048     : _d( new Private() )
0049 {
0050     // this block left empty intentionally
0051 }
0052 
0053 LeveyJenningsGridAttributes::LeveyJenningsGridAttributes( const LeveyJenningsGridAttributes& r )
0054     : _d( new Private( *r.d ) )
0055 {
0056 }
0057 
0058 LeveyJenningsGridAttributes & LeveyJenningsGridAttributes::operator=( const LeveyJenningsGridAttributes& r )
0059 {
0060     if ( this == &r )
0061         return *this;
0062 
0063     *d = *r.d;
0064 
0065     return *this;
0066 }
0067 
0068 LeveyJenningsGridAttributes::~LeveyJenningsGridAttributes()
0069 {
0070     delete _d; _d = nullptr;
0071 }
0072 
0073 
0074 bool LeveyJenningsGridAttributes::operator==( const LeveyJenningsGridAttributes& r ) const
0075 {
0076     return  isGridVisible( Expected ) == r.isGridVisible( Expected ) &&
0077             isGridVisible( Calculated ) == r.isGridVisible( Calculated ) &&
0078             gridPen( Expected ) == r.gridPen( Expected ) &&
0079             gridPen( Calculated ) == r.gridPen( Calculated );
0080 }
0081 
0082 void LeveyJenningsGridAttributes::setRangeBrush( Range range, const QBrush& brush )
0083 {
0084     d->rangeBrushes[ range ] = brush;
0085 }
0086 
0087 QBrush LeveyJenningsGridAttributes::rangeBrush( Range range ) const
0088 {
0089     return d->rangeBrushes[ range ];
0090 }
0091 
0092 
0093 void LeveyJenningsGridAttributes::setGridVisible( GridType type, bool visible )
0094 {
0095     d->visible[ type ] = visible;
0096 }
0097 
0098 bool LeveyJenningsGridAttributes::isGridVisible( GridType type ) const
0099 {
0100     return d->visible[ type ];
0101 }
0102 
0103 void LeveyJenningsGridAttributes::setGridPen( GridType type, const QPen& pen )
0104 {
0105     d->pens[ type ] = pen;
0106     d->pens[ type ].setCapStyle( Qt::FlatCap );
0107 }
0108 
0109 QPen LeveyJenningsGridAttributes::gridPen( GridType type ) const
0110 {
0111     return d->pens[ type ];
0112 }