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

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 "KChartDataValueAttributes.h"
0021 
0022 #include <QVariant>
0023 #include <QDebug>
0024 #include "KChartRelativePosition.h"
0025 #include "KChartPosition.h"
0026 #include "KChartMath_p.h"
0027 #include <KChartTextAttributes.h>
0028 #include <KChartFrameAttributes.h>
0029 #include <KChartBackgroundAttributes.h>
0030 #include <KChartMarkerAttributes.h>
0031 
0032 // FIXME till
0033 #define KCHART_DATA_VALUE_AUTO_DIGITS 4
0034 
0035 
0036 #define d d_func()
0037 
0038 using namespace KChart;
0039 
0040 class Q_DECL_HIDDEN DataValueAttributes::Private
0041 {
0042     friend class DataValueAttributes;
0043 public:
0044     Private();
0045 private:
0046     TextAttributes textAttributes;
0047     FrameAttributes frameAttributes;
0048     BackgroundAttributes backgroundAttributes;
0049     MarkerAttributes markerAttributes;
0050     QString prefix;
0051     QString suffix;
0052     QString dataLabel;
0053     RelativePosition negativeRelPos;
0054     RelativePosition positiveRelPos;
0055     qint16 decimalDigits;
0056     qint16 powerOfTenDivisor;
0057     bool visible : 1;
0058     bool showInfinite : 1;
0059     bool showRepetitiveDataLabels : 1;
0060     bool showOverlappingDataLabels : 1;
0061     bool usePercentage : 1;
0062     bool mirrorNegativeValueTextRotation : 1;
0063 };
0064 
0065 DataValueAttributes::Private::Private() :
0066     decimalDigits( KCHART_DATA_VALUE_AUTO_DIGITS ),
0067     powerOfTenDivisor( 0 ),
0068     visible( false ),
0069     showInfinite( true )
0070 {
0071     Measure me( 20.0, KChartEnums::MeasureCalculationModeAuto, KChartEnums::MeasureOrientationAuto );
0072     textAttributes.setFontSize( me );
0073     me.setValue( 8.0 );
0074     me.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
0075     textAttributes.setMinimalFontSize( me );
0076     textAttributes.setRotation( -45 );
0077 
0078     // we set the Position to unknown: so the diagrams can take their own decisions
0079     positiveRelPos.setReferencePosition( Position::Unknown );
0080     negativeRelPos.setReferencePosition( Position::Unknown );
0081 
0082     positiveRelPos.setAlignment( Qt::AlignTop | Qt::AlignRight );
0083     negativeRelPos.setAlignment( Qt::AlignBottom | Qt::AlignRight );
0084 
0085     showRepetitiveDataLabels = false;
0086     showOverlappingDataLabels = false;
0087 
0088     usePercentage = false;
0089     mirrorNegativeValueTextRotation = false;
0090 }
0091 
0092 
0093 DataValueAttributes::DataValueAttributes()
0094     : _d( new Private() )
0095 {
0096 }
0097 
0098 DataValueAttributes::DataValueAttributes( const DataValueAttributes& r )
0099     : _d( new Private( *r.d ) )
0100 {
0101 }
0102 
0103 DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r )
0104 {
0105     if ( this == &r )
0106         return *this;
0107 
0108     *d = *r.d;
0109 
0110     return *this;
0111 }
0112 
0113 DataValueAttributes::~DataValueAttributes()
0114 {
0115     delete _d; _d = nullptr;
0116 }
0117 
0118 
0119 bool DataValueAttributes::operator==( const DataValueAttributes& r ) const
0120 {
0121     return  isVisible() == r.isVisible() &&
0122             textAttributes() == r.textAttributes() &&
0123             frameAttributes() == r.frameAttributes() &&
0124             backgroundAttributes() == r.backgroundAttributes() &&
0125             markerAttributes() == r.markerAttributes() &&
0126             decimalDigits() == r.decimalDigits() &&
0127             prefix() == r.prefix() &&
0128             suffix() == r.suffix() &&
0129             dataLabel() == r.dataLabel() &&
0130             powerOfTenDivisor() == r.powerOfTenDivisor() &&
0131             showInfinite() == r.showInfinite() &&
0132             negativePosition() == r.negativePosition() &&
0133             positivePosition() == r.positivePosition() &&
0134             showRepetitiveDataLabels() == r.showRepetitiveDataLabels() &&
0135             showOverlappingDataLabels() == r.showOverlappingDataLabels() &&
0136             usePercentage() == r.usePercentage() &&
0137             mirrorNegativeValueTextRotation() == r.mirrorNegativeValueTextRotation();
0138 }
0139 
0140 /*static*/
0141 const DataValueAttributes& DataValueAttributes::defaultAttributes()
0142 {
0143     static const DataValueAttributes theDefaultDataValueAttributes;
0144     return theDefaultDataValueAttributes;
0145 }
0146 
0147 /*static*/
0148 const QVariant& DataValueAttributes::defaultAttributesAsVariant()
0149 {
0150     static const QVariant theDefaultDataValueAttributesVariant = QVariant::fromValue(defaultAttributes());
0151     return theDefaultDataValueAttributesVariant;
0152 }
0153 
0154 
0155 void DataValueAttributes::setVisible( bool visible )
0156 {
0157     d->visible = visible;
0158 }
0159 
0160 bool DataValueAttributes::isVisible() const
0161 {
0162     return d->visible;
0163 }
0164 
0165 void DataValueAttributes::setTextAttributes( const TextAttributes &a )
0166 {
0167     d->textAttributes = a;
0168 }
0169 
0170 TextAttributes DataValueAttributes::textAttributes() const
0171 {
0172     return d->textAttributes;
0173 }
0174 
0175 void DataValueAttributes::setFrameAttributes( const FrameAttributes &a )
0176 {
0177     d->frameAttributes = a;
0178 }
0179 
0180 FrameAttributes DataValueAttributes::frameAttributes() const
0181 {
0182     return d->frameAttributes;
0183 }
0184 
0185 void DataValueAttributes::setBackgroundAttributes( const BackgroundAttributes &a )
0186 {
0187     d->backgroundAttributes = a;
0188 }
0189 
0190 BackgroundAttributes DataValueAttributes::backgroundAttributes() const
0191 {
0192     return d->backgroundAttributes;
0193 }
0194 
0195 void DataValueAttributes::setMarkerAttributes( const MarkerAttributes &a )
0196 {
0197     d->markerAttributes = a;
0198 }
0199 
0200 MarkerAttributes DataValueAttributes::markerAttributes() const
0201 {
0202     return d->markerAttributes;
0203 }
0204 
0205 void DataValueAttributes::setMirrorNegativeValueTextRotation( bool enable )
0206 {
0207     d->mirrorNegativeValueTextRotation = enable;
0208 }
0209 
0210 bool DataValueAttributes::mirrorNegativeValueTextRotation() const
0211 {
0212     return d->mirrorNegativeValueTextRotation;
0213 }
0214 
0215 void DataValueAttributes::setUsePercentage( bool enable )
0216 {
0217     d->usePercentage = enable;
0218 }
0219 
0220 bool DataValueAttributes::usePercentage() const
0221 {
0222     return d->usePercentage;
0223 }
0224 
0225 void DataValueAttributes::setDecimalDigits( int digits )
0226 {
0227     d->decimalDigits = digits;
0228 }
0229 
0230 int DataValueAttributes::decimalDigits() const
0231 {
0232     return d->decimalDigits;
0233 }
0234 
0235 void DataValueAttributes::setPrefix( const QString prefixString )
0236 {
0237     d->prefix = prefixString;
0238 }
0239 
0240 QString DataValueAttributes::prefix() const
0241 {
0242     return d->prefix;
0243 }
0244 
0245 void DataValueAttributes::setSuffix( const QString suffixString )
0246 {
0247     d->suffix  = suffixString;
0248 }
0249 
0250 QString DataValueAttributes::suffix() const
0251 {
0252     return d->suffix;
0253 }
0254 
0255 void DataValueAttributes::setDataLabel( const QString label )
0256 {
0257     d->dataLabel =  label;
0258 }
0259 
0260 QString DataValueAttributes::dataLabel() const
0261 {
0262     return d->dataLabel;
0263 }
0264 
0265 bool DataValueAttributes::showRepetitiveDataLabels() const
0266 {
0267     return d->showRepetitiveDataLabels;
0268 }
0269 
0270 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
0271 {
0272     d->showRepetitiveDataLabels = showRepetitiveDataLabels;
0273 }
0274 
0275 bool DataValueAttributes::showOverlappingDataLabels() const
0276 {
0277     return d->showOverlappingDataLabels;
0278 }
0279 
0280 void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
0281 {
0282     d->showOverlappingDataLabels = showOverlappingDataLabels;
0283 }
0284 
0285 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
0286 {
0287     d->powerOfTenDivisor = powerOfTenDivisor;
0288 }
0289 
0290 int DataValueAttributes::powerOfTenDivisor() const
0291 {
0292     return d->powerOfTenDivisor;
0293 }
0294 
0295 void DataValueAttributes::setShowInfinite( bool infinite )
0296 {
0297     d->showInfinite = infinite;
0298 }
0299 
0300 bool DataValueAttributes::showInfinite() const
0301 {
0302     return d->showInfinite;
0303 }
0304 
0305 void DataValueAttributes::setNegativePosition( const RelativePosition& relPosition )
0306 {
0307     d->negativeRelPos = relPosition;
0308 }
0309 
0310 const RelativePosition DataValueAttributes::negativePosition() const
0311 {
0312     return d->negativeRelPos;
0313 }
0314 
0315 void DataValueAttributes::setPositivePosition( const RelativePosition& relPosition )
0316 {
0317     d->positiveRelPos = relPosition;
0318 }
0319 
0320 const RelativePosition DataValueAttributes::positivePosition() const
0321 {
0322     return d->positiveRelPos;
0323 }
0324 
0325 #if !defined(QT_NO_DEBUG_STREAM)
0326 QDebug operator<<(QDebug dbg, const KChart::DataValueAttributes& val )
0327 {
0328     dbg << "RelativePosition DataValueAttributes("
0329     << "visible="<<val.isVisible()
0330     << "textattributes="<<val.textAttributes()
0331     << "frameattributes="<<val.frameAttributes()
0332     << "backgroundattributes="<<val.backgroundAttributes()
0333     << "decimaldigits="<<val.decimalDigits()
0334     << "poweroftendivisor="<<val.powerOfTenDivisor()
0335     << "showinfinite="<<val.showInfinite()
0336     << "negativerelativeposition="<<val.negativePosition()
0337     << "positiverelativeposition="<<val.positivePosition()
0338     << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels()
0339     << "showOverlappingDataLabels="<<val.showOverlappingDataLabels()
0340     <<")";
0341     return dbg;
0342 }
0343 #endif /* QT_NO_DEBUG_STREAM */