File indexing completed on 2024-05-12 15:54:16
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 "KChartGridAttributes.h" 0021 0022 #include "KChartMath_p.h" 0023 0024 #include <QPen> 0025 #include <QDebug> 0026 0027 #define d d_func() 0028 0029 using namespace KChart; 0030 0031 class Q_DECL_HIDDEN GridAttributes::Private 0032 { 0033 friend class GridAttributes; 0034 public: 0035 Private(); 0036 private: 0037 bool visible; 0038 KChartEnums::GranularitySequence sequence; 0039 bool linesOnAnnotations; 0040 qreal stepWidth; 0041 qreal subStepWidth; 0042 bool adjustLower; 0043 bool adjustUpper; 0044 QPen pen; 0045 bool subVisible; 0046 QPen subPen; 0047 bool outerVisible; 0048 QPen zeroPen; 0049 }; 0050 0051 GridAttributes::Private::Private() 0052 : visible( true ), 0053 sequence( KChartEnums::GranularitySequence_10_20 ), 0054 linesOnAnnotations( false ), 0055 stepWidth( 0.0 ), 0056 subStepWidth( 0.0 ), 0057 adjustLower( true ), 0058 adjustUpper( true ), 0059 pen( QColor(0xa0, 0xa0, 0xa0 ) ), 0060 subVisible( true ), 0061 subPen( QColor(0xd0, 0xd0, 0xd0 ) ), 0062 outerVisible( true ), 0063 zeroPen( QColor( 0x00, 0x00, 0x80 ) ) 0064 { 0065 pen.setCapStyle( Qt::FlatCap ); 0066 subPen.setCapStyle( Qt::FlatCap ); 0067 zeroPen.setCapStyle( Qt::FlatCap ); 0068 } 0069 0070 0071 GridAttributes::GridAttributes() 0072 : _d( new Private() ) 0073 { 0074 // this bloc left empty intentionally 0075 } 0076 0077 GridAttributes::GridAttributes( const GridAttributes& r ) 0078 : _d( new Private( *r.d ) ) 0079 { 0080 } 0081 0082 GridAttributes & GridAttributes::operator=( const GridAttributes& r ) 0083 { 0084 if ( this == &r ) 0085 return *this; 0086 0087 *d = *r.d; 0088 0089 return *this; 0090 } 0091 0092 GridAttributes::~GridAttributes() 0093 { 0094 delete _d; _d = nullptr; 0095 } 0096 0097 0098 bool GridAttributes::operator==( const GridAttributes& r ) const 0099 { 0100 return isGridVisible() == r.isGridVisible() && 0101 gridGranularitySequence() == r.gridGranularitySequence() && 0102 linesOnAnnotations() == r.linesOnAnnotations() && 0103 adjustLowerBoundToGrid() == r.adjustLowerBoundToGrid() && 0104 adjustUpperBoundToGrid() == r.adjustUpperBoundToGrid() && 0105 gridPen() == r.gridPen() && 0106 isSubGridVisible() == r.isSubGridVisible() && 0107 subGridPen() == r.subGridPen() && 0108 isOuterLinesVisible() == r.isOuterLinesVisible() && 0109 zeroLinePen() == r.zeroLinePen(); 0110 } 0111 0112 0113 void GridAttributes::setGridVisible( bool visible ) 0114 { 0115 d->visible = visible; 0116 } 0117 0118 bool GridAttributes::isGridVisible() const 0119 { 0120 return d->visible; 0121 } 0122 0123 void GridAttributes::setLinesOnAnnotations( bool b ) 0124 { 0125 d->linesOnAnnotations = b; 0126 } 0127 0128 bool GridAttributes::linesOnAnnotations() const 0129 { 0130 return d->linesOnAnnotations; 0131 } 0132 0133 void GridAttributes::setGridStepWidth( qreal stepWidth ) 0134 { 0135 d->stepWidth = stepWidth; 0136 } 0137 0138 qreal GridAttributes::gridStepWidth() const 0139 { 0140 return d->stepWidth; 0141 } 0142 0143 0144 0145 void GridAttributes::setGridSubStepWidth( qreal subStepWidth ) 0146 { 0147 d->subStepWidth = subStepWidth; 0148 } 0149 0150 qreal GridAttributes::gridSubStepWidth() const 0151 { 0152 return d->subStepWidth; 0153 } 0154 0155 void GridAttributes::setGridGranularitySequence( KChartEnums::GranularitySequence sequence ) 0156 { 0157 d->sequence = sequence; 0158 } 0159 0160 KChartEnums::GranularitySequence GridAttributes::gridGranularitySequence() const 0161 { 0162 return d->sequence; 0163 } 0164 0165 void GridAttributes::setAdjustBoundsToGrid( bool adjustLower, bool adjustUpper ) 0166 { 0167 d->adjustLower = adjustLower; 0168 d->adjustUpper = adjustUpper; 0169 } 0170 bool GridAttributes::adjustLowerBoundToGrid() const 0171 { 0172 return d->adjustLower; 0173 } 0174 bool GridAttributes::adjustUpperBoundToGrid() const 0175 { 0176 return d->adjustUpper; 0177 } 0178 0179 void GridAttributes::setGridPen( const QPen & pen ) 0180 { 0181 d->pen = pen; 0182 d->pen.setCapStyle( Qt::FlatCap ); 0183 } 0184 0185 QPen GridAttributes::gridPen() const 0186 { 0187 return d->pen; 0188 } 0189 0190 void GridAttributes::setSubGridVisible( bool visible ) 0191 { 0192 d->subVisible = visible; 0193 } 0194 0195 bool GridAttributes::isSubGridVisible() const 0196 { 0197 return d->subVisible; 0198 } 0199 0200 void GridAttributes::setSubGridPen( const QPen & pen ) 0201 { 0202 d->subPen = pen; 0203 d->subPen.setCapStyle( Qt::FlatCap ); 0204 } 0205 0206 QPen GridAttributes::subGridPen() const 0207 { 0208 return d->subPen; 0209 } 0210 0211 void GridAttributes::setOuterLinesVisible( bool visible ) 0212 { 0213 d->outerVisible = visible; 0214 } 0215 0216 bool GridAttributes::isOuterLinesVisible() const 0217 { 0218 return d->outerVisible; 0219 } 0220 0221 void GridAttributes::setZeroLinePen( const QPen & pen ) 0222 { 0223 d->zeroPen = pen; 0224 d->zeroPen.setCapStyle( Qt::FlatCap ); 0225 } 0226 0227 QPen GridAttributes::zeroLinePen() const 0228 { 0229 return d->zeroPen; 0230 } 0231 0232 #if !defined(QT_NO_DEBUG_STREAM) 0233 QDebug operator<<(QDebug dbg, const KChart::GridAttributes& a) 0234 { 0235 dbg << "KChart::GridAttributes(" 0236 << "visible="<<a.isGridVisible() 0237 << "subVisible="<<a.isSubGridVisible() 0238 // KChartEnums::GranularitySequence sequence; 0239 << "stepWidth=" << a.gridStepWidth() 0240 << "subStepWidth=" << a.gridSubStepWidth() 0241 << "pen="<<a.gridPen() 0242 << "subPen="<<a.subGridPen() 0243 << "zeroPen="<<a.zeroLinePen() 0244 << ")"; 0245 return dbg; 0246 } 0247 #endif /* QT_NO_DEBUG_STREAM */ 0248