KD Chart 2
[rev.2.5]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 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.txt 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 TextAttributes textAttributes; 00051 FrameAttributes frameAttributes; 00052 BackgroundAttributes backgroundAttributes; 00053 MarkerAttributes markerAttributes; 00054 QString prefix; 00055 QString suffix; 00056 QString dataLabel; 00057 RelativePosition negativeRelPos; 00058 RelativePosition positiveRelPos; 00059 qint16 decimalDigits; 00060 qint16 powerOfTenDivisor; 00061 bool visible : 1; 00062 bool showInfinite : 1; 00063 bool showRepetitiveDataLabels : 1; 00064 bool showOverlappingDataLabels : 1; 00065 bool usePercentage : 1; 00066 bool mirrorNegativeValueTextRotation : 1; 00067 }; 00068 00069 DataValueAttributes::Private::Private() : 00070 decimalDigits( KDCHART_DATA_VALUE_AUTO_DIGITS ), 00071 powerOfTenDivisor( 0 ), 00072 visible( false ), 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 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::AlignTop | Qt::AlignRight ); 00088 negativeRelPos.setAlignment( Qt::AlignBottom | Qt::AlignRight ); 00089 00090 showRepetitiveDataLabels = false; 00091 showOverlappingDataLabels = false; 00092 00093 #if 0 00094 // By default use 0.4 (or 0.5, resp.) of the font height as horizontal distance between 00095 // the data and their respective data value texts, 00096 // and use 0.75 as the vertical distance. 00097 const qreal posHoriPadding = 400.0; const qreal posVertPadding = -75.0; 00098 const qreal negHoriPadding = -500.0; const qreal negVertPadding = 75.0; 00099 Measure m( posHoriPadding, KDChartEnums::MeasureCalculationModeAuto ); 00100 positiveRelPos.setHorizontalPadding( m ); 00101 m.setValue( posVertPadding ); 00102 positiveRelPos.setVerticalPadding( m ); 00103 m.setValue( negHoriPadding ); 00104 negativeRelPos.setHorizontalPadding( m ); 00105 m.setValue( negVertPadding ); 00106 negativeRelPos.setVerticalPadding( m ); 00107 #endif 00108 00109 usePercentage = false; 00110 mirrorNegativeValueTextRotation = true; 00111 } 00112 00113 00114 DataValueAttributes::DataValueAttributes() 00115 : _d( new Private() ) 00116 { 00117 } 00118 00119 DataValueAttributes::DataValueAttributes( const DataValueAttributes& r ) 00120 : _d( new Private( *r.d ) ) 00121 { 00122 } 00123 00124 DataValueAttributes & DataValueAttributes::operator=( const DataValueAttributes& r ) 00125 { 00126 if( this == &r ) 00127 return *this; 00128 00129 *d = *r.d; 00130 00131 return *this; 00132 } 00133 00134 DataValueAttributes::~DataValueAttributes() 00135 { 00136 delete _d; _d = 0; 00137 } 00138 00139 00140 bool DataValueAttributes::operator==( const DataValueAttributes& r ) const 00141 { 00142 return ( isVisible() == r.isVisible() && 00143 textAttributes() == r.textAttributes() && 00144 frameAttributes() == r.frameAttributes() && 00145 backgroundAttributes() == r.backgroundAttributes() && 00146 markerAttributes() == r.markerAttributes() && 00147 decimalDigits() == r.decimalDigits() && 00148 prefix() == r.prefix() && 00149 suffix() == r.suffix() && 00150 dataLabel() == r.dataLabel() && 00151 powerOfTenDivisor() == r.powerOfTenDivisor() && 00152 showInfinite() == r.showInfinite() && 00153 negativePosition() == r.negativePosition() && 00154 positivePosition() == r.positivePosition() && 00155 showRepetitiveDataLabels() == r.showRepetitiveDataLabels() && 00156 showOverlappingDataLabels() == r.showOverlappingDataLabels() && 00157 usePercentage() == r.usePercentage() ); 00158 } 00159 00160 /*static*/ 00161 const DataValueAttributes& DataValueAttributes::defaultAttributes() 00162 { 00163 static const DataValueAttributes theDefaultDataValueAttributes; 00164 return theDefaultDataValueAttributes; 00165 } 00166 00167 /*static*/ 00168 const QVariant& DataValueAttributes::defaultAttributesAsVariant() 00169 { 00170 static const QVariant theDefaultDataValueAttributesVariant = qVariantFromValue(defaultAttributes()); 00171 return theDefaultDataValueAttributesVariant; 00172 } 00173 00174 00175 void DataValueAttributes::setVisible( bool visible ) 00176 { 00177 d->visible = visible; 00178 } 00179 00180 bool DataValueAttributes::isVisible() const 00181 { 00182 return d->visible; 00183 } 00184 00185 void DataValueAttributes::setTextAttributes( const TextAttributes &a ) 00186 { 00187 d->textAttributes = a; 00188 } 00189 00190 TextAttributes DataValueAttributes::textAttributes() const 00191 { 00192 return d->textAttributes; 00193 } 00194 00195 void DataValueAttributes::setFrameAttributes( const FrameAttributes &a ) 00196 { 00197 d->frameAttributes = a; 00198 } 00199 00200 FrameAttributes DataValueAttributes::frameAttributes() const 00201 { 00202 return d->frameAttributes; 00203 } 00204 00205 void DataValueAttributes::setBackgroundAttributes( const BackgroundAttributes &a ) 00206 { 00207 d->backgroundAttributes = a; 00208 } 00209 00210 BackgroundAttributes DataValueAttributes::backgroundAttributes() const 00211 { 00212 return d->backgroundAttributes; 00213 } 00214 00215 void DataValueAttributes::setMarkerAttributes( const MarkerAttributes &a ) 00216 { 00217 d->markerAttributes = a; 00218 } 00219 00220 MarkerAttributes DataValueAttributes::markerAttributes() const 00221 { 00222 return d->markerAttributes; 00223 } 00224 00225 void DataValueAttributes::setMirrorNegativeValueTextRotation( bool enable ) 00226 { 00227 d->mirrorNegativeValueTextRotation = enable; 00228 } 00229 00230 bool DataValueAttributes::mirrorNegativeValueTextRotation() const 00231 { 00232 return d->mirrorNegativeValueTextRotation; 00233 } 00234 00235 void DataValueAttributes::setUsePercentage( bool enable ) 00236 { 00237 d->usePercentage = enable; 00238 } 00239 00240 bool DataValueAttributes::usePercentage() const 00241 { 00242 return d->usePercentage; 00243 } 00244 00245 void DataValueAttributes::setDecimalDigits( int digits ) 00246 { 00247 d->decimalDigits = digits; 00248 } 00249 00250 int DataValueAttributes::decimalDigits() const 00251 { 00252 return d->decimalDigits; 00253 } 00254 00255 void DataValueAttributes::setPrefix( const QString prefixString ) 00256 { 00257 d->prefix = prefixString; 00258 } 00259 00260 QString DataValueAttributes::prefix() const 00261 { 00262 return d->prefix; 00263 } 00264 00265 void DataValueAttributes::setSuffix( const QString suffixString ) 00266 { 00267 d->suffix = suffixString; 00268 } 00269 00270 QString DataValueAttributes::suffix() const 00271 { 00272 return d->suffix; 00273 } 00274 00275 void DataValueAttributes::setDataLabel( const QString label ) 00276 { 00277 d->dataLabel = label; 00278 } 00279 00280 QString DataValueAttributes::dataLabel() const 00281 { 00282 return d->dataLabel; 00283 } 00284 00285 bool DataValueAttributes::showRepetitiveDataLabels() const 00286 { 00287 return d->showRepetitiveDataLabels; 00288 } 00289 00290 void DataValueAttributes::setShowRepetitiveDataLabels( bool showRepetitiveDataLabels ) 00291 { 00292 d->showRepetitiveDataLabels = showRepetitiveDataLabels; 00293 } 00294 00295 bool DataValueAttributes::showOverlappingDataLabels() const 00296 { 00297 return d->showOverlappingDataLabels; 00298 } 00299 00300 void DataValueAttributes::setShowOverlappingDataLabels( bool showOverlappingDataLabels ) 00301 { 00302 d->showOverlappingDataLabels = showOverlappingDataLabels; 00303 } 00304 00305 void DataValueAttributes::setPowerOfTenDivisor( int powerOfTenDivisor ) 00306 { 00307 d->powerOfTenDivisor = powerOfTenDivisor; 00308 } 00309 00310 int DataValueAttributes::powerOfTenDivisor() const 00311 { 00312 return d->powerOfTenDivisor; 00313 } 00314 00315 void DataValueAttributes::setShowInfinite( bool infinite ) 00316 { 00317 d->showInfinite = infinite; 00318 } 00319 00320 bool DataValueAttributes::showInfinite() const 00321 { 00322 return d->showInfinite; 00323 } 00324 00325 void DataValueAttributes::setNegativePosition( const RelativePosition& relPosition ) 00326 { 00327 d->negativeRelPos = relPosition; 00328 } 00329 00330 const RelativePosition DataValueAttributes::negativePosition() const 00331 { 00332 return d->negativeRelPos; 00333 } 00334 00335 void DataValueAttributes::setPositivePosition( const RelativePosition& relPosition ) 00336 { 00337 d->positiveRelPos = relPosition; 00338 } 00339 00340 const RelativePosition DataValueAttributes::positivePosition() const 00341 { 00342 return d->positiveRelPos; 00343 } 00344 00345 #if !defined(QT_NO_DEBUG_STREAM) 00346 QDebug operator<<(QDebug dbg, const KDChart::DataValueAttributes& val ) 00347 { 00348 dbg << "RelativePosition DataValueAttributes(" 00349 << "visible="<<val.isVisible() 00350 << "textattributes="<<val.textAttributes() 00351 << "frameattributes="<<val.frameAttributes() 00352 << "backgroundattributes="<<val.backgroundAttributes() 00353 << "decimaldigits="<<val.decimalDigits() 00354 << "poweroftendivisor="<<val.powerOfTenDivisor() 00355 << "showinfinite="<<val.showInfinite() 00356 << "negativerelativeposition="<<val.negativePosition() 00357 << "positiverelativeposition="<<val.positivePosition() 00358 << "showRepetitiveDataLabels="<<val.showRepetitiveDataLabels() 00359 << "showOverlappingDataLabels="<<val.showOverlappingDataLabels() 00360 <<")"; 00361 return dbg; 00362 } 00363 #endif /* QT_NO_DEBUG_STREAM */