1 /* 2 * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 3 * 4 * This file is part of the KD Chart library. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef KCHARTDATAVALUEATTRIBUTES_H 21 #define KCHARTDATAVALUEATTRIBUTES_H 22 23 #include <Qt> 24 #include <QMetaType> 25 #include "KChartGlobal.h" 26 #include "KChartEnums.h" 27 #include "KChartRelativePosition.h" 28 29 /** \file KChartDataValueAttributes.h 30 * \brief Declaring the class KChart::DataValueAttributes. 31 * 32 * 33 */ 34 35 36 namespace KChart { 37 38 class TextAttributes; 39 class BackgroundAttributes; 40 class FrameAttributes; 41 class MarkerAttributes; 42 43 /** 44 * \class DataValueAttributes KChartDataValueAttributes.h KChartDataValueAttributes 45 * \brief Diagram attributes dealing with data value labels. 46 * 47 * The DataValueAttributes group all properties that can be set 48 * wrt data value labels and if and how they are displayed. This 49 * includes things like the text attributes (font, color), what 50 * markers are used, how many decimal digits are displayed, etc. 51 */ 52 class KCHART_EXPORT DataValueAttributes 53 { 54 public: 55 DataValueAttributes(); 56 DataValueAttributes( const DataValueAttributes& ); 57 DataValueAttributes &operator= ( const DataValueAttributes& ); 58 bool operator==( const DataValueAttributes& ) const; 59 inline bool operator!=( const DataValueAttributes& other ) const { return !operator==(other); } 60 61 ~DataValueAttributes(); 62 63 static const DataValueAttributes& defaultAttributes(); 64 static const QVariant& defaultAttributesAsVariant(); 65 66 /** Set whether data value labels should be displayed. 67 * \param visible Whether data value labels should be displayed. 68 */ 69 void setVisible( bool visible ); 70 71 /** 72 * @return Whether data value labels should be displayed. 73 */ 74 bool isVisible() const; 75 76 /** 77 * Set the text attributes to use for the data value labels. 78 * \param a The text attributes to set. 79 * \see TextAttributes 80 */ 81 void setTextAttributes( const TextAttributes &a ); 82 83 /** 84 * \return The text attributes used for painting data value labels. 85 */ 86 TextAttributes textAttributes() const; 87 88 /** 89 * If true, rotation of negative value labels is negated, so that negative 90 * values are rotated in opposite direction of textAttributes().rotation(), 91 * and in this sense appear "mirrored" to positive value labels, though the 92 * text itself is *not* mirrored, only its rotation. 93 */ 94 bool mirrorNegativeValueTextRotation() const; 95 96 /** 97 * \see mirrorNegativeValueTextRotation() 98 */ 99 void setMirrorNegativeValueTextRotation( bool enable ); 100 101 /** 102 * Set the frame attributes to use for the data value labels area. 103 * \param a The frame attributes to set. 104 * \see FrameAttributes 105 */ 106 void setFrameAttributes( const FrameAttributes &a ); 107 108 /** 109 * \return The frame attributes used for painting the data 110 * value labels area. 111 * \see FrameAttributes 112 */ 113 FrameAttributes frameAttributes() const; 114 115 /** 116 * Set the background attributes to use for the data value labels area. 117 * \param a The background attributes to set. 118 * \see BackgroundAttributes 119 */ 120 void setBackgroundAttributes( const BackgroundAttributes &a ); 121 122 /** 123 * \return The background attributes used for painting the data 124 * value labels area. 125 * \see BackgroundAttributes 126 */ 127 BackgroundAttributes backgroundAttributes() const; 128 129 /** 130 * Set the marker attributes to use for the data values. This includes 131 * the marker type. 132 * \param a The marker attributes to set. 133 * \see MarkerAttributes 134 */ 135 void setMarkerAttributes( const MarkerAttributes &a ); 136 137 /** 138 * \return The marker attributes used for decorating the data 139 * values. 140 * \see MarkerAttributes 141 */ 142 MarkerAttributes markerAttributes() const; 143 144 /** 145 * Specify whether to use percentages instead of actual data point values when no 146 * specific label is set. In a bar or cartesian diagram, this means that the value 147 * will be shown in % in relation to the sum of all values in the same category, in 148 * a polar diagram in relation to the sum of all values in a data set. 149 * 150 * When this is turned on, the value will \b not automatically have the '%' postfix. 151 * \param enable Whether to enable percentage values 152 */ 153 void setUsePercentage( bool enable ); 154 155 /** 156 * \return Whether to use percentage values 157 * \see setUsePercentage 158 */ 159 bool usePercentage() const; 160 161 /** 162 * Set how many decimal digits to display when rendering the data value 163 * labels. If there are no decimal digits it will not be displayed. 164 * \param digits The number of decimal digits to use. 165 */ 166 void setDecimalDigits( int digits ); 167 168 /** 169 * \return The number of decimal digits displayed. 170 */ 171 int decimalDigits() const; 172 173 /** 174 * \brief Prepend a prefix string to the data value label 175 * \sa prefix 176 */ 177 void setPrefix( const QString prefix ); 178 179 /** 180 * \brief Returns the string used as a prefix to the data value text. 181 * \sa setPrefix 182 */ 183 QString prefix() const; 184 185 /** 186 * \brief Append a suffix string to the data value label 187 * \sa suffix 188 */ 189 void setSuffix( const QString suffix ); 190 191 /** 192 * \brief Returns the string used as a suffix to the data value text. 193 * \sa setSuffix 194 */ 195 QString suffix() const; 196 197 /** 198 * \brief display a string label instead of the original data value label 199 * Supports HTML code. 200 * \sa dataLabel 201 */ 202 void setDataLabel( const QString label ); 203 204 /** 205 * \brief Returns the string displayed instead of the data value label 206 * \sa setDataLabel 207 */ 208 QString dataLabel() const; 209 210 /** 211 * \return Whether data values not different from their predecessors are drawn. 212 */ 213 bool showRepetitiveDataLabels() const; 214 215 /** 216 * 217 * Set whether data value labels not different from their predecessors should be drawn. 218 * \param showRepetitiveDataLabels Whether data value not different from their predecessors are drawn. 219 */ 220 void setShowRepetitiveDataLabels( bool showRepetitiveDataLabels ); 221 222 /** 223 * \return Whether data value texts overlapping other data value texts of the same diagram are drawn. 224 */ 225 bool showOverlappingDataLabels() const; 226 227 /** 228 * 229 * Set whether data value texts overlapping other data value texts of the same diagram should be drawn. 230 * \param showOverlappingDataLabels Whether data texts overlapping other data value texts of the same diagram are drawn. 231 */ 232 void setShowOverlappingDataLabels( bool showOverlappingDataLabels ); 233 234 /** 235 * \cond PLANNED_FOR_FUTURE 236 * 237 * These method are planned for future versions of KD Chart, 238 * so they are not part of the documented API yet. 239 * 240 */ 241 void setPowerOfTenDivisor( int powerOfTenDivisor ); 242 int powerOfTenDivisor() const; 243 /** 244 * \endcond 245 */ 246 247 248 /** 249 * \cond PLANNED_FOR_FUTURE 250 * 251 * These method are planned for future versions of KD Chart, 252 * so they are not part of the documented API yet. 253 */ 254 void setShowInfinite( bool infinite ); 255 bool showInfinite() const; 256 /** 257 * \endcond 258 */ 259 260 /** 261 * \brief Defines the relative positioning of the data value labels for negative values. 262 * 263 * The position is specified in relation to the respective data value point, or in 264 * relation to the respective data representation area, that's one area segment in 265 * a LineDiagram showing areas, or one bar in a BarDiagram, one pie slice ... 266 * 267 * See detailed description of \a KChart::Position for an illustration of the 268 * different possible reference positions. 269 * 270 * \sa negativePosition 271 */ 272 void setNegativePosition( const RelativePosition& relPosition ); 273 274 /** 275 * \brief Return the relative positioning of the data value labels 276 * \sa setNegativePosition 277 */ 278 const RelativePosition negativePosition() const; 279 280 /** 281 * \brief Defines the relative position of the data value labels for positive values. 282 * 283 * The position is specified in relation to the respective data value point, or in 284 * relation to the respective data representation area, that's one area segment in 285 * a LineDiagram showing areas, or one bar in a BarDiagram, one pie slice ... 286 * 287 * See detailed description of \a KChart::Position for an illustration of the 288 * different possible reference positions. 289 * 290 * \sa positivePosition 291 */ 292 void setPositivePosition( const RelativePosition& relPosition ); 293 294 /** 295 * \brief Return the relative positioning of the data value labels 296 * \sa setPositivePosition 297 */ 298 const RelativePosition positivePosition() const; 299 position(bool positive)300 const RelativePosition position( bool positive ) const 301 { 302 return positive ? positivePosition() : negativePosition(); 303 } 304 305 private: 306 KCHART_DECLARE_PRIVATE_BASE_VALUE( DataValueAttributes ) 307 308 }; // End of class DataValueAttributes 309 310 } 311 312 #if !defined(QT_NO_DEBUG_STREAM) 313 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::DataValueAttributes& ); 314 #endif /* QT_NO_DEBUG_STREAM */ 315 316 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::DataValueAttributes ) 317 318 QT_BEGIN_NAMESPACE 319 Q_DECLARE_TYPEINFO( KChart::DataValueAttributes, Q_MOVABLE_TYPE ); 320 QT_END_NAMESPACE 321 322 Q_DECLARE_METATYPE( KChart::DataValueAttributes ) 323 324 #endif // KCHARTDATAVALUEATTRIBUTES_H 325