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