00001 /**************************************************************************** 00002 ** Copyright (C) 2006 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 00027 #include <QVariant> 00028 #include <QDebug> 00029 #include "KDChartDataValueAttributes.h" 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 }; 00068 00069 DataValueAttributes::Private::Private() : 00070 visible( false ), 00071 decimalDigits( KDCHART_DATA_VALUE_AUTO_DIGITS ), 00072 powerOfTenDivisor( 0 ), 00073 showInfinite( true ) 00074 { 00075 Measure me( 25.0, 00076 KDChartEnums::MeasureCalculationModeAuto, 00077 KDChartEnums::MeasureOrientationAuto ); 00078 textAttributes.setFontSize( me ); 00079 me.setValue( 8.0 ); 00080 me.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute ); 00081 textAttributes.setMinimalFontSize( me ); 00082 textAttributes.setRotation( -45 ); 00083 00084 // we set the Position to unknown: so the diagrams can take their own decisions 00085 positiveRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::NorthWest 00086 negativeRelPos.setReferencePosition( Position::Unknown ); // a bar diagram will use: Position::SouthEast 00087 00088 positiveRelPos.setAlignment( Qt::AlignLeft | Qt::AlignBottom ); 00089 negativeRelPos.setAlignment( Qt::AlignRight | Qt::AlignTop ); 00090 00091 showRepetitiveDataLabels = false; 00092 00093 // By default use 0.25 of the font height as horizontal distance between 00094 // the data and their respective data value texts, 00095 // and use 0.33 as the vertical distance. 00096 Measure m( 250.0, KDChartEnums::MeasureCalculationModeAuto ); 00097 positiveRelPos.setHorizontalPadding( m ); 00098 m.setValue( -333.3 ); positiveRelPos.setVerticalPadding( m ); 00099 00100 m.setValue( -250.0 ); negativeRelPos.setHorizontalPadding( m ); 00101 m.setValue( 100.0 ); negativeRelPos.setVerticalPadding( m ); 00102 // note: we use a smaller default vertical gap, because the fonts have top leading anyway 00103 } 00104 00105 00106 DataValueAttributes::DataValueAttributes() 00107 : _d( new Private() ) 00108 { 00109 } 00110 00111 DataValueAttributes::DataValueAttributes( const DataValueAttributes& r ) 00112 : _d( new Private( *r.d ) ) 00113 { 00114 } 00115 00116 DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r ) 00117 { 00118 if( this == &r ) 00119 return *this; 00120 00121 *d = *r.d; 00122 00123 return *this; 00124 } 00125 00126 DataValueAttributes::~DataValueAttributes() 00127 { 00128 delete _d; _d = 0; 00129 } 00130 00131 00132 bool DataValueAttributes::operator==( const DataValueAttributes& r ) const 00133 { 00134 /* 00135 qDebug() << "DataValueAttributes::operator== finds" 00136 << "b" << (isVisible() == r.isVisible()) 00137 << "c" << (textAttributes() == r.textAttributes()) 00138 << "d" << (frameAttributes() == r.frameAttributes()) 00139 << "e" << (backgroundAttributes() == r.backgroundAttributes()) 00140 << "f" << (markerAttributes() == r.markerAttributes()) 00141 << "g" << (decimalDigits() == r.decimalDigits()) 00142 << "h" << (prefix() == r.prefix()) 00143 << "i" << (suffix() == r.suffix()) 00144 << "j" << (dataLabel() == r.dataLabel()) 00145 << "k" << (powerOfTenDivisor() == r.powerOfTenDivisor()) 00146 << "l" << (showInfinite() == r.showInfinite()) 00147 << "m" << (negativePosition() == r.negativePosition()) 00148 << "n" << (positivePosition() == r.positivePosition()) 00149 << "o" << (showRepetitiveDataLabels() == r.showRepetitiveDataLabels()); 00150 */ 00151 return ( isVisible() == r.isVisible() && 00152 textAttributes() == r.textAttributes() && 00153 frameAttributes() == r.frameAttributes() && 00154 backgroundAttributes() == r.backgroundAttributes() && 00155 markerAttributes() == r.markerAttributes() && 00156 decimalDigits() == r.decimalDigits() && 00157 prefix() == r.prefix() && 00158 suffix() == r.suffix() && 00159 dataLabel() == r.dataLabel() && 00160 powerOfTenDivisor() == r.powerOfTenDivisor() && 00161 showInfinite() == r.showInfinite() && 00162 negativePosition() == r.negativePosition() && 00163 positivePosition() == r.positivePosition() && 00164 showRepetitiveDataLabels() == r.showRepetitiveDataLabels() ); 00165 } 00166 00167 /*static*/ 00168 const DataValueAttributes& DataValueAttributes::defaultAttributes() 00169 { 00170 static const DataValueAttributes theDefaultDataValueAttributes; 00171 return theDefaultDataValueAttributes; 00172 } 00173 00174 /*static*/ 00175 const QVariant& DataValueAttributes::defaultAttributesAsVariant() 00176 { 00177 static const QVariant theDefaultDataValueAttributesVariant = qVariantFromValue(defaultAttributes()); 00178 return theDefaultDataValueAttributesVariant; 00179 } 00180 00181 00182 void DataValueAttributes::setVisible( bool visible ) 00183 { 00184 d->visible = visible; 00185 } 00186 00187 bool DataValueAttributes::isVisible() const 00188 { 00189 return d->visible; 00190 } 00191 00192 void DataValueAttributes::setTextAttributes( const TextAttributes &a ) 00193 { 00194 d->textAttributes = a; 00195 } 00196 00197 TextAttributes DataValueAttributes::textAttributes() const 00198 { 00199 return d->textAttributes; 00200 } 00201 00202 void DataValueAttributes::setFrameAttributes( const FrameAttributes &a ) 00203 { 00204 d->frameAttributes = a; 00205 } 00206 00207 FrameAttributes DataValueAttributes::frameAttributes() const 00208 { 00209 return d->frameAttributes; 00210 } 00211 00212 void DataValueAttributes::setBackgroundAttributes( const BackgroundAttributes &a ) 00213 { 00214 d->backgroundAttributes = a; 00215 } 00216 00217 BackgroundAttributes DataValueAttributes::backgroundAttributes() const 00218 { 00219 return d->backgroundAttributes; 00220 } 00221 00222 void DataValueAttributes::setMarkerAttributes( const MarkerAttributes &a ) 00223 { 00224 d->markerAttributes = a; 00225 } 00226 00227 MarkerAttributes DataValueAttributes::markerAttributes() const 00228 { 00229 return d->markerAttributes; 00230 } 00231 00232 00233 void DataValueAttributes::setDecimalDigits( int digits ) 00234 { 00235 d->decimalDigits = digits; 00236 } 00237 00238 int DataValueAttributes::decimalDigits() const 00239 { 00240 return d->decimalDigits; 00241 } 00242 00243 void DataValueAttributes::setPrefix( const QString prefixString ) 00244 { 00245 d->prefix = prefixString; 00246 } 00247 00248 QString DataValueAttributes::prefix() const 00249 { 00250 return d->prefix; 00251 } 00252 00253 void DataValueAttributes::setSuffix( const QString suffixString ) 00254 { 00255 d->suffix = suffixString; 00256 } 00257 00258 QString DataValueAttributes::suffix() const 00259 { 00260 return d->suffix; 00261 } 00262 00263 void DataValueAttributes::setDataLabel( const QString label ) 00264 { 00265 d->dataLabel = label; 00266 } 00267 00268 QString DataValueAttributes::dataLabel() const 00269 { 00270 return d->dataLabel; 00271 } 00272 00273 bool DataValueAttributes::showRepetitiveDataLabels() const 00274 { 00275 return d->showRepetitiveDataLabels; 00276 } 00277 00278 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels ) 00279 { 00280 d->showRepetitiveDataLabels = showRepetitiveDataLabels; 00281 } 00282 00283 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor ) 00284 { 00285 d->powerOfTenDivisor = powerOfTenDivisor; 00286 } 00287 00288 int DataValueAttributes::powerOfTenDivisor() const 00289 { 00290 return d->powerOfTenDivisor; 00291 } 00292 00293 void DataValueAttributes::setShowInfinite( bool infinite ) 00294 { 00295 d->showInfinite = infinite; 00296 } 00297 00298 bool DataValueAttributes::showInfinite() const 00299 { 00300 return d->showInfinite; 00301 } 00302 00303 void DataValueAttributes::setNegativePosition( const RelativePosition& relPosition ) 00304 { 00305 d->negativeRelPos = relPosition; 00306 } 00307 00308 const RelativePosition DataValueAttributes::negativePosition() const 00309 { 00310 return d->negativeRelPos; 00311 } 00312 00313 void DataValueAttributes::setPositivePosition( const RelativePosition& relPosition ) 00314 { 00315 d->positiveRelPos = relPosition; 00316 } 00317 00318 const RelativePosition DataValueAttributes::positivePosition() const 00319 { 00320 return d->positiveRelPos; 00321 } 00322 00323 #if !defined(QT_NO_DEBUG_STREAM) 00324 QDebug operator<<(QDebug dbg, const KDChart::DataValueAttributes& val ) 00325 { 00326 dbg << "RelativePosition DataValueAttributes(" 00327 << "visible="<<val.isVisible() 00328 << "textattributes="<<val.textAttributes() 00329 << "frameattributes="<<val.frameAttributes() 00330 << "backgroundattributes="<<val.backgroundAttributes() 00331 << "decimaldigits="<<val.decimalDigits() 00332 << "poweroftendivisor="<<val.powerOfTenDivisor() 00333 << "showinfinite="<<val.showInfinite() 00334 << "negativerelativeposition="<<val.negativePosition() 00335 << "positiverelativeposition="<<val.positivePosition() 00336 << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels() 00337 <<")"; 00338 return dbg; 00339 } 00340 #endif /* QT_NO_DEBUG_STREAM */