KDChartDataValueAttributes.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB.  All rights reserved.
00003 **
00004 ** This file is part of the KD Chart library.
00005 **
00006 ** Licensees holding valid commercial KD Chart licenses may use this file in
00007 ** accordance with the KD Chart Commercial License Agreement provided with
00008 ** the Software.
00009 **
00010 **
00011 ** This file may be distributed and/or modified under the terms of the
00012 ** GNU General Public License version 2 and version 3 as published by the
00013 ** Free Software Foundation and appearing in the file LICENSE.GPL included.
00014 **
00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 **
00018 ** Contact info@kdab.com if any conditions of this licensing are not
00019 ** clear to you.
00020 **
00021 **********************************************************************/
00022 
00023 #include "KDChartDataValueAttributes.h"
00024 
00025 #include <QVariant>
00026 #include <QDebug>
00027 #include "KDChartRelativePosition.h"
00028 #include "KDChartPosition.h"
00029 #include <KDChartTextAttributes.h>
00030 #include <KDChartFrameAttributes.h>
00031 #include <KDChartBackgroundAttributes.h>
00032 #include <KDChartMarkerAttributes.h>
00033 
00034 #include <KDABLibFakes>
00035 
00036 // FIXME till
00037 #define KDCHART_DATA_VALUE_AUTO_DIGITS 4
00038 
00039 
00040 #define d d_func()
00041 
00042 using namespace KDChart;
00043 
00044 class DataValueAttributes::Private
00045 {
00046     friend class DataValueAttributes;
00047 public:
00048     Private();
00049 private:
00050     bool visible;
00051     TextAttributes textAttributes;
00052     FrameAttributes frameAttributes;
00053     BackgroundAttributes backgroundAttributes;
00054     MarkerAttributes markerAttributes;
00055     int decimalDigits;
00056     QString prefix;
00057     QString suffix;
00058     QString dataLabel;
00059     int powerOfTenDivisor;
00060     bool showInfinite;
00061     RelativePosition negativeRelPos;
00062     RelativePosition positiveRelPos;
00063     bool showRepetitiveDataLabels;
00064     bool showOverlappingDataLabels;
00065     bool usePercentage;
00066 };
00067 
00068 DataValueAttributes::Private::Private() :
00069     visible( false ),
00070     decimalDigits( KDCHART_DATA_VALUE_AUTO_DIGITS ),
00071     powerOfTenDivisor( 0 ),
00072     showInfinite( true )
00073 {
00074     Measure me( 25.0,
00075                 KDChartEnums::MeasureCalculationModeAuto,
00076                 KDChartEnums::MeasureOrientationAuto );
00077     textAttributes.setFontSize( me );
00078     me.setValue( 8.0 );
00079     me.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
00080     textAttributes.setMinimalFontSize( me );
00081     textAttributes.setRotation( -45 );
00082 
00083     // we set the Position to unknown: so the diagrams can take their own decisions
00084     positiveRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::NorthWest
00085     negativeRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::SouthEast
00086 
00087     positiveRelPos.setAlignment( Qt::AlignLeft  | Qt::AlignBottom );
00088     negativeRelPos.setAlignment( Qt::AlignRight | Qt::AlignTop );
00089 
00090     showRepetitiveDataLabels = false;
00091     showOverlappingDataLabels = false;
00092 
00093     // By default use 0.4 (or 0.5, resp.) of the font height as horizontal distance between
00094     // the data and their respective data value texts,
00095     // and use 0.75 as the vertical distance.
00096     const double posHoriPadding =  400.0; const double posVertPadding = -75.0;
00097     const double negHoriPadding = -500.0; const double negVertPadding =  75.0;
00098     Measure m( posHoriPadding, KDChartEnums::MeasureCalculationModeAuto );
00099     positiveRelPos.setHorizontalPadding( m );
00100     m.setValue( posVertPadding );
00101     positiveRelPos.setVerticalPadding( m );
00102     m.setValue( negHoriPadding );
00103     negativeRelPos.setHorizontalPadding( m );
00104     m.setValue( negVertPadding );
00105     negativeRelPos.setVerticalPadding( m );
00106 
00107     usePercentage = false;
00108 }
00109 
00110 
00111 DataValueAttributes::DataValueAttributes()
00112     : _d( new Private() )
00113 {
00114 }
00115 
00116 DataValueAttributes::DataValueAttributes( const DataValueAttributes& r )
00117     : _d( new Private( *r.d ) )
00118 {
00119 }
00120 
00121 DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r )
00122 {
00123     if( this == &r )
00124         return *this;
00125 
00126     *d = *r.d;
00127 
00128     return *this;
00129 }
00130 
00131 DataValueAttributes::~DataValueAttributes()
00132 {
00133     delete _d; _d = 0;
00134 }
00135 
00136 
00137 bool DataValueAttributes::operator==( const DataValueAttributes& r ) const
00138 {
00139     /*
00140     qDebug() << "DataValueAttributes::operator== finds"
00141             << "b" << (isVisible() == r.isVisible())
00142             << "c" << (textAttributes() == r.textAttributes())
00143             << "d" << (frameAttributes() == r.frameAttributes())
00144             << "e" << (backgroundAttributes() == r.backgroundAttributes())
00145             << "f" << (markerAttributes() == r.markerAttributes())
00146             << "g" << (decimalDigits() == r.decimalDigits())
00147             << "h" << (prefix() == r.prefix())
00148             << "i" << (suffix() == r.suffix())
00149             << "j" << (dataLabel() == r.dataLabel())
00150             << "k" << (powerOfTenDivisor() == r.powerOfTenDivisor())
00151             << "l" << (showInfinite() == r.showInfinite())
00152             << "m" << (negativePosition() == r.negativePosition())
00153             << "n" << (positivePosition() == r.positivePosition())
00154             << "o" << (showRepetitiveDataLabels() == r.showRepetitiveDataLabels())
00155             << "p" << (showOverlappingDataLabels() == r.showOverlappingDataLabels());
00156     */
00157     return ( isVisible() == r.isVisible() &&
00158             textAttributes() == r.textAttributes() &&
00159             frameAttributes() == r.frameAttributes() &&
00160             backgroundAttributes() == r.backgroundAttributes() &&
00161             markerAttributes() == r.markerAttributes() &&
00162             decimalDigits() == r.decimalDigits() &&
00163             prefix() == r.prefix() &&
00164             suffix() == r.suffix() &&
00165             dataLabel() == r.dataLabel() &&
00166             powerOfTenDivisor() == r.powerOfTenDivisor() &&
00167             showInfinite() == r.showInfinite() &&
00168             negativePosition() == r.negativePosition() &&
00169             positivePosition() == r.positivePosition() &&
00170             showRepetitiveDataLabels() == r.showRepetitiveDataLabels() &&
00171             showOverlappingDataLabels() == r.showOverlappingDataLabels() &&
00172             usePercentage() == r.usePercentage() );
00173 }
00174 
00175 /*static*/
00176 const DataValueAttributes& DataValueAttributes::defaultAttributes()
00177 {
00178     static const DataValueAttributes theDefaultDataValueAttributes;
00179     return theDefaultDataValueAttributes;
00180 }
00181 
00182 /*static*/
00183 const QVariant& DataValueAttributes::defaultAttributesAsVariant()
00184 {
00185     static const QVariant theDefaultDataValueAttributesVariant = qVariantFromValue(defaultAttributes());
00186     return theDefaultDataValueAttributesVariant;
00187 }
00188 
00189 
00190 void DataValueAttributes::setVisible( bool visible )
00191 {
00192     d->visible = visible;
00193 }
00194 
00195 bool DataValueAttributes::isVisible() const
00196 {
00197     return d->visible;
00198 }
00199 
00200 void DataValueAttributes::setTextAttributes( const TextAttributes &a )
00201 {
00202     d->textAttributes = a;
00203 }
00204 
00205 TextAttributes DataValueAttributes::textAttributes() const
00206 {
00207     return d->textAttributes;
00208 }
00209 
00210 void DataValueAttributes::setFrameAttributes( const FrameAttributes &a )
00211 {
00212     d->frameAttributes = a;
00213 }
00214 
00215 FrameAttributes DataValueAttributes::frameAttributes() const
00216 {
00217     return d->frameAttributes;
00218 }
00219 
00220 void DataValueAttributes::setBackgroundAttributes( const BackgroundAttributes &a )
00221 {
00222     d->backgroundAttributes = a;
00223 }
00224 
00225 BackgroundAttributes DataValueAttributes::backgroundAttributes() const
00226 {
00227     return d->backgroundAttributes;
00228 }
00229 
00230 void DataValueAttributes::setMarkerAttributes( const MarkerAttributes &a )
00231 {
00232     d->markerAttributes = a;
00233 }
00234 
00235 MarkerAttributes DataValueAttributes::markerAttributes() const
00236 {
00237     return d->markerAttributes;
00238 }
00239 
00240 void DataValueAttributes::setUsePercentage( bool enable )
00241 {
00242     d->usePercentage = enable;
00243 }
00244 
00245 bool DataValueAttributes::usePercentage() const
00246 {
00247     return d->usePercentage;
00248 }
00249 
00250 void DataValueAttributes::setDecimalDigits( int digits )
00251 {
00252     d->decimalDigits = digits;
00253 }
00254 
00255 int DataValueAttributes::decimalDigits() const
00256 {
00257     return d->decimalDigits;
00258 }
00259 
00260 void DataValueAttributes::setPrefix( const QString prefixString )
00261 {
00262     d->prefix = prefixString;
00263 }
00264 
00265 QString DataValueAttributes::prefix() const
00266 {
00267     return d->prefix;
00268 }
00269 
00270 void DataValueAttributes::setSuffix( const QString suffixString )
00271 {
00272     d->suffix  = suffixString;
00273 }
00274 
00275 QString DataValueAttributes::suffix() const
00276 {
00277     return d->suffix;
00278 }
00279 
00280 void DataValueAttributes::setDataLabel( const QString label )
00281 {
00282     d->dataLabel =  label;
00283 }
00284 
00285 QString DataValueAttributes::dataLabel() const
00286 {
00287     return d->dataLabel;
00288 }
00289 
00290 bool DataValueAttributes::showRepetitiveDataLabels() const
00291 {
00292     return d->showRepetitiveDataLabels;
00293 }
00294 
00295 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
00296 {
00297     d->showRepetitiveDataLabels = showRepetitiveDataLabels;
00298 }
00299 
00300 bool DataValueAttributes::showOverlappingDataLabels() const
00301 {
00302     return d->showOverlappingDataLabels;
00303 }
00304 
00305 void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
00306 {
00307     d->showOverlappingDataLabels = showOverlappingDataLabels;
00308 }
00309 
00310 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
00311 {
00312     d->powerOfTenDivisor = powerOfTenDivisor;
00313 }
00314 
00315 int DataValueAttributes::powerOfTenDivisor() const
00316 {
00317     return d->powerOfTenDivisor;
00318 }
00319 
00320 void DataValueAttributes::setShowInfinite( bool infinite )
00321 {
00322     d->showInfinite = infinite;
00323 }
00324 
00325 bool DataValueAttributes::showInfinite() const
00326 {
00327     return d->showInfinite;
00328 }
00329 
00330 void DataValueAttributes::setNegativePosition( const RelativePosition& relPosition )
00331 {
00332     d->negativeRelPos = relPosition;
00333 }
00334 
00335 const RelativePosition DataValueAttributes::negativePosition() const
00336 {
00337     return d->negativeRelPos;
00338 }
00339 
00340 void DataValueAttributes::setPositivePosition( const RelativePosition& relPosition )
00341 {
00342     d->positiveRelPos = relPosition;
00343 }
00344 
00345 const RelativePosition DataValueAttributes::positivePosition() const
00346 {
00347     return d->positiveRelPos;
00348 }
00349 
00350 #if !defined(QT_NO_DEBUG_STREAM)
00351 QDebug operator<<(QDebug dbg, const KDChart::DataValueAttributes& val )
00352 {
00353     dbg << "RelativePosition DataValueAttributes("
00354         << "visible="<<val.isVisible()
00355         << "textattributes="<<val.textAttributes()
00356         << "frameattributes="<<val.frameAttributes()
00357         << "backgroundattributes="<<val.backgroundAttributes()
00358         << "decimaldigits="<<val.decimalDigits()
00359         << "poweroftendivisor="<<val.powerOfTenDivisor()
00360         << "showinfinite="<<val.showInfinite()
00361         << "negativerelativeposition="<<val.negativePosition()
00362         << "positiverelativeposition="<<val.positivePosition()
00363     << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels()
00364     << "showOverlappingDataLabels="<<val.showOverlappingDataLabels()
00365     <<")";
00366     return dbg;
00367 }
00368 #endif /* QT_NO_DEBUG_STREAM */