KDChartDataValueAttributes.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2007 Klarälvdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Chart library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Chart licenses may use this file in
00012  ** accordance with the KD Chart Commercial License Agreement provided with
00013  ** the Software.
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  ** See http://www.kdab.net/kdchart for
00019  **   information about KDChart Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
00023  **
00024  **********************************************************************/
00025 
00026 #include "KDChartDataValueAttributes.h"
00027 
00028 #include <QVariant>
00029 #include <QDebug>
00030 #include "KDChartRelativePosition.h"
00031 #include "KDChartPosition.h"
00032 #include <KDChartTextAttributes.h>
00033 #include <KDChartFrameAttributes.h>
00034 #include <KDChartBackgroundAttributes.h>
00035 #include <KDChartMarkerAttributes.h>
00036 
00037 #include <KDABLibFakes>
00038 
00039 // FIXME till
00040 #define KDCHART_DATA_VALUE_AUTO_DIGITS 4
00041 
00042 
00043 #define d d_func()
00044 
00045 using namespace KDChart;
00046 
00047 class DataValueAttributes::Private
00048 {
00049     friend class DataValueAttributes;
00050 public:
00051     Private();
00052 private:
00053     bool visible;
00054     TextAttributes textAttributes;
00055     FrameAttributes frameAttributes;
00056     BackgroundAttributes backgroundAttributes;
00057     MarkerAttributes markerAttributes;
00058     int decimalDigits;
00059     QString prefix;
00060     QString suffix;
00061     QString dataLabel;
00062     int powerOfTenDivisor;
00063     bool showInfinite;
00064     RelativePosition negativeRelPos;
00065     RelativePosition positiveRelPos;
00066     bool showRepetitiveDataLabels;
00067     bool showOverlappingDataLabels;
00068 };
00069 
00070 DataValueAttributes::Private::Private() :
00071     visible( false ),
00072     decimalDigits( KDCHART_DATA_VALUE_AUTO_DIGITS ),
00073     powerOfTenDivisor( 0 ),
00074     showInfinite( true )
00075 {
00076     Measure me( 25.0,
00077                 KDChartEnums::MeasureCalculationModeAuto,
00078                 KDChartEnums::MeasureOrientationAuto );
00079     textAttributes.setFontSize( me );
00080     me.setValue( 8.0 );
00081     me.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
00082     textAttributes.setMinimalFontSize( me );
00083     textAttributes.setRotation( -45 );
00084 
00085     // we set the Position to unknown: so the diagrams can take their own decisions
00086     positiveRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::NorthWest
00087     negativeRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::SouthEast
00088 
00089     positiveRelPos.setAlignment( Qt::AlignLeft  | Qt::AlignBottom );
00090     negativeRelPos.setAlignment( Qt::AlignRight | Qt::AlignTop );
00091 
00092     showRepetitiveDataLabels = false;
00093     showOverlappingDataLabels = false;
00094 
00095     // By default use 0.4 (or 0.5, resp.) of the font height as horizontal distance between
00096     // the data and their respective data value texts,
00097     // and use 0.75 as the vertical distance.
00098     const double posHoriPadding =  400.0; const double posVertPadding = -75.0;
00099     const double negHoriPadding = -500.0; const double negVertPadding =  75.0;
00100     Measure m( posHoriPadding, KDChartEnums::MeasureCalculationModeAuto );
00101     positiveRelPos.setHorizontalPadding( m );
00102     m.setValue( posVertPadding );
00103     positiveRelPos.setVerticalPadding( m );
00104     m.setValue( negHoriPadding );
00105     negativeRelPos.setHorizontalPadding( m );
00106     m.setValue( negVertPadding );
00107     negativeRelPos.setVerticalPadding( m );
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 }
00173 
00174 /*static*/
00175 const DataValueAttributes& DataValueAttributes::defaultAttributes()
00176 {
00177     static const DataValueAttributes theDefaultDataValueAttributes;
00178     return theDefaultDataValueAttributes;
00179 }
00180 
00181 /*static*/
00182 const QVariant& DataValueAttributes::defaultAttributesAsVariant()
00183 {
00184     static const QVariant theDefaultDataValueAttributesVariant = qVariantFromValue(defaultAttributes());
00185     return theDefaultDataValueAttributesVariant;
00186 }
00187 
00188 
00189 void DataValueAttributes::setVisible( bool visible )
00190 {
00191     d->visible = visible;
00192 }
00193 
00194 bool DataValueAttributes::isVisible() const
00195 {
00196     return d->visible;
00197 }
00198 
00199 void DataValueAttributes::setTextAttributes( const TextAttributes &a )
00200 {
00201     d->textAttributes = a;
00202 }
00203 
00204 TextAttributes DataValueAttributes::textAttributes() const
00205 {
00206     return d->textAttributes;
00207 }
00208 
00209 void DataValueAttributes::setFrameAttributes( const FrameAttributes &a )
00210 {
00211     d->frameAttributes = a;
00212 }
00213 
00214 FrameAttributes DataValueAttributes::frameAttributes() const
00215 {
00216     return d->frameAttributes;
00217 }
00218 
00219 void DataValueAttributes::setBackgroundAttributes( const BackgroundAttributes &a )
00220 {
00221     d->backgroundAttributes = a;
00222 }
00223 
00224 BackgroundAttributes DataValueAttributes::backgroundAttributes() const
00225 {
00226     return d->backgroundAttributes;
00227 }
00228 
00229 void DataValueAttributes::setMarkerAttributes( const MarkerAttributes &a )
00230 {
00231     d->markerAttributes = a;
00232 }
00233 
00234 MarkerAttributes DataValueAttributes::markerAttributes() const
00235 {
00236     return d->markerAttributes;
00237 }
00238 
00239 
00240 void DataValueAttributes::setDecimalDigits( int digits )
00241 {
00242     d->decimalDigits = digits;
00243 }
00244 
00245 int DataValueAttributes::decimalDigits() const
00246 {
00247     return d->decimalDigits;
00248 }
00249 
00250 void DataValueAttributes::setPrefix( const QString prefixString )
00251 {
00252     d->prefix = prefixString;
00253 }
00254 
00255 QString DataValueAttributes::prefix() const
00256 {
00257     return d->prefix;
00258 }
00259 
00260 void DataValueAttributes::setSuffix( const QString suffixString )
00261 {
00262     d->suffix  = suffixString;
00263 }
00264 
00265 QString DataValueAttributes::suffix() const
00266 {
00267     return d->suffix;
00268 }
00269 
00270 void DataValueAttributes::setDataLabel( const QString label )
00271 {
00272     d->dataLabel =  label;
00273 }
00274 
00275 QString DataValueAttributes::dataLabel() const
00276 {
00277     return d->dataLabel;
00278 }
00279 
00280 bool DataValueAttributes::showRepetitiveDataLabels() const
00281 {
00282     return d->showRepetitiveDataLabels;
00283 }
00284 
00285 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels )
00286 {
00287     d->showRepetitiveDataLabels = showRepetitiveDataLabels;
00288 }
00289 
00290 bool DataValueAttributes::showOverlappingDataLabels() const
00291 {
00292     return d->showOverlappingDataLabels;
00293 }
00294 
00295 void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels )
00296 {
00297     d->showOverlappingDataLabels = showOverlappingDataLabels;
00298 }
00299 
00300 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor )
00301 {
00302     d->powerOfTenDivisor = powerOfTenDivisor;
00303 }
00304 
00305 int DataValueAttributes::powerOfTenDivisor() const
00306 {
00307     return d->powerOfTenDivisor;
00308 }
00309 
00310 void DataValueAttributes::setShowInfinite( bool infinite )
00311 {
00312     d->showInfinite = infinite;
00313 }
00314 
00315 bool DataValueAttributes::showInfinite() const
00316 {
00317     return d->showInfinite;
00318 }
00319 
00320 void DataValueAttributes::setNegativePosition( const RelativePosition& relPosition )
00321 {
00322     d->negativeRelPos = relPosition;
00323 }
00324 
00325 const RelativePosition DataValueAttributes::negativePosition() const
00326 {
00327     return d->negativeRelPos;
00328 }
00329 
00330 void DataValueAttributes::setPositivePosition( const RelativePosition& relPosition )
00331 {
00332     d->positiveRelPos = relPosition;
00333 }
00334 
00335 const RelativePosition DataValueAttributes::positivePosition() const
00336 {
00337     return d->positiveRelPos;
00338 }
00339 
00340 #if !defined(QT_NO_DEBUG_STREAM)
00341 QDebug operator<<(QDebug dbg, const KDChart::DataValueAttributes& val )
00342 {
00343     dbg << "RelativePosition DataValueAttributes("
00344         << "visible="<<val.isVisible()
00345         << "textattributes="<<val.textAttributes()
00346         << "frameattributes="<<val.frameAttributes()
00347         << "backgroundattributes="<<val.backgroundAttributes()
00348         << "decimaldigits="<<val.decimalDigits()
00349         << "poweroftendivisor="<<val.powerOfTenDivisor()
00350         << "showinfinite="<<val.showInfinite()
00351         << "negativerelativeposition="<<val.negativePosition()
00352         << "positiverelativeposition="<<val.positivePosition()
00353     << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels()
00354     << "showOverlappingDataLabels="<<val.showOverlappingDataLabels()
00355     <<")";
00356     return dbg;
00357 }
00358 #endif /* QT_NO_DEBUG_STREAM */

Generated on Thu Mar 4 23:19:11 2010 for KD Chart 2 by  doxygen 1.5.4