File indexing completed on 2024-05-12 04:20:32

0001 /*
0002  * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #ifndef KCHARTDATAVALUEATTRIBUTES_H
0010 #define KCHARTDATAVALUEATTRIBUTES_H
0011 
0012 #include <Qt>
0013 #include <QMetaType>
0014 #include "KChartGlobal.h"
0015 #include "KChartEnums.h"
0016 #include "KChartRelativePosition.h"
0017 
0018 /** \file KChartDataValueAttributes.h
0019  *  \brief Declaring the class KChart::DataValueAttributes.
0020  *
0021  *
0022  */
0023 
0024 
0025 namespace KChart {
0026 
0027   class TextAttributes;
0028   class BackgroundAttributes;
0029   class FrameAttributes;
0030   class MarkerAttributes;
0031 
0032   /**
0033    * \class DataValueAttributes KChartDataValueAttributes.h KChartDataValueAttributes
0034    * \brief Diagram attributes dealing with data value labels.
0035    *
0036    * The DataValueAttributes group all properties that can be set
0037    * wrt data value labels and if and how they are displayed. This
0038    * includes things like the text attributes (font, color), what
0039    * markers are used, how many decimal digits are displayed, etc.
0040    */
0041 class KCHART_EXPORT DataValueAttributes
0042 {
0043 public:
0044   DataValueAttributes();
0045   DataValueAttributes( const DataValueAttributes& );
0046   DataValueAttributes &operator= ( const DataValueAttributes& );
0047   bool operator==( const DataValueAttributes& ) const;
0048   inline bool operator!=( const DataValueAttributes& other ) const { return !operator==(other); }
0049 
0050   ~DataValueAttributes();
0051 
0052   static const DataValueAttributes& defaultAttributes();
0053   static const QVariant& defaultAttributesAsVariant();
0054 
0055   /** Set whether data value labels should be displayed.
0056    * \param visible Whether data value labels should be displayed.
0057    */
0058   void setVisible( bool visible );
0059 
0060   /**
0061    * @return Whether data value labels should be displayed.
0062    */
0063   bool isVisible() const;
0064 
0065   /**
0066    * Set the text attributes to use for the data value labels.
0067    * \param a The text attributes to set.
0068    * \see TextAttributes
0069    */
0070   void setTextAttributes( const TextAttributes &a );
0071 
0072   /**
0073    * \return The text attributes used for painting data value labels.
0074    */
0075   TextAttributes textAttributes() const;
0076 
0077   /**
0078    * If true, rotation of negative value labels is negated, so that negative
0079    * values are rotated in opposite direction of textAttributes().rotation(),
0080    * and in this sense appear "mirrored" to positive value labels, though the
0081    * text itself is *not* mirrored, only its rotation.
0082    */
0083   bool mirrorNegativeValueTextRotation() const;
0084 
0085   /**
0086    * \see mirrorNegativeValueTextRotation()
0087    */
0088   void setMirrorNegativeValueTextRotation( bool enable );
0089 
0090   /**
0091    * Set the frame attributes to use for the data value labels area.
0092    * \param a The frame attributes to set.
0093    * \see FrameAttributes
0094    */
0095   void setFrameAttributes( const FrameAttributes &a );
0096 
0097   /**
0098    * \return The frame attributes used for painting the data
0099    * value labels area.
0100    * \see FrameAttributes
0101    */
0102   FrameAttributes frameAttributes() const;
0103 
0104   /**
0105    * Set the background attributes to use for the data value labels area.
0106    * \param a The background attributes to set.
0107    * \see BackgroundAttributes
0108    */
0109   void setBackgroundAttributes( const BackgroundAttributes &a );
0110 
0111   /**
0112    * \return The background attributes used for painting the data
0113    * value labels area.
0114    * \see BackgroundAttributes
0115    */
0116   BackgroundAttributes backgroundAttributes() const;
0117 
0118   /**
0119    * Set the marker attributes to use for the data values. This includes
0120    * the marker type.
0121    * \param a The marker attributes to set.
0122    * \see MarkerAttributes
0123    */
0124   void setMarkerAttributes( const MarkerAttributes &a );
0125 
0126   /**
0127    * \return The marker attributes used for decorating the data
0128    * values.
0129    * \see MarkerAttributes
0130    */
0131   MarkerAttributes markerAttributes() const;
0132 
0133   /**
0134    * Specify whether to use percentages instead of actual data point values when no
0135    * specific label is set. In a bar or cartesian diagram, this means that the value
0136    * will be shown in % in relation to the sum of all values in the same category, in
0137    * a polar diagram in relation to the sum of all values in a data set.
0138    *
0139    * When this is turned on, the value will \b not automatically have the '%' postfix.
0140    * \param enable Whether to enable percentage values
0141    */
0142   void setUsePercentage( bool enable );
0143 
0144   /**
0145    * \return Whether to use percentage values
0146    * \see setUsePercentage
0147    */
0148   bool usePercentage() const;
0149 
0150   /**
0151    * Set how  many decimal digits to display when rendering the data value
0152    * labels. If there are no decimal digits it will not be displayed.
0153    * \param digits The number of decimal digits to use.
0154    */
0155   void setDecimalDigits( int digits );
0156 
0157   /**
0158    * \return The number of decimal digits displayed.
0159    */
0160   int decimalDigits() const;
0161 
0162   /**
0163    * \brief Prepend a prefix string to the data value label
0164    * \sa prefix
0165    */
0166   void setPrefix( const QString prefix );
0167 
0168  /**
0169    * \brief Returns the string used as a prefix to the data value text.
0170    * \sa setPrefix
0171    */
0172   QString prefix() const;
0173 
0174   /**
0175    * \brief Append a suffix string to the data value label
0176    * \sa suffix
0177    */
0178   void setSuffix( const QString suffix );
0179 
0180  /**
0181    * \brief Returns the string used as a suffix to the data value text.
0182    * \sa setSuffix
0183    */
0184   QString suffix() const;
0185 
0186  /**
0187    * \brief display a string label instead of the original data value label
0188    * Supports HTML code.
0189    * \sa dataLabel
0190    */
0191   void setDataLabel( const QString label );
0192 
0193  /**
0194    * \brief Returns the string displayed instead of the data value label
0195    * \sa setDataLabel
0196    */
0197   QString dataLabel() const;
0198 
0199  /**
0200    * \return Whether data values not different from their predecessors are drawn.
0201   */
0202   bool showRepetitiveDataLabels() const;
0203 
0204  /**
0205    *
0206    * Set whether data value labels not different from their predecessors should be drawn.
0207    * \param showRepetitiveDataLabels Whether data value not different from their predecessors are drawn.
0208   */
0209   void setShowRepetitiveDataLabels( bool showRepetitiveDataLabels );
0210 
0211  /**
0212    * \return Whether data value texts overlapping other data value texts of the same diagram are drawn.
0213   */
0214   bool showOverlappingDataLabels() const;
0215 
0216  /**
0217    *
0218    * Set whether data value texts overlapping other data value texts of the same diagram should be drawn.
0219    * \param showOverlappingDataLabels Whether data texts overlapping other data value texts of the same diagram are drawn.
0220   */
0221   void setShowOverlappingDataLabels( bool showOverlappingDataLabels );
0222 
0223   /**
0224     * \cond PLANNED_FOR_FUTURE
0225     *
0226     * These method are planned for future versions of KD Chart,
0227     * so they are not part of the documented API yet.
0228     *
0229     */
0230   void setPowerOfTenDivisor( int powerOfTenDivisor );
0231   int powerOfTenDivisor() const;
0232    /**
0233    * \endcond
0234    */
0235 
0236 
0237   /**
0238    * \cond PLANNED_FOR_FUTURE
0239    *
0240    * These method are planned for future versions of KD Chart,
0241    * so they are not part of the documented API yet.
0242    */
0243   void setShowInfinite( bool infinite );
0244   bool showInfinite() const;
0245   /**
0246    * \endcond
0247    */
0248 
0249    /**
0250    * \brief Defines the relative positioning of the data value labels for negative values.
0251     *
0252     * The position is specified in relation to the respective data value point, or in
0253     * relation to the respective data representation area, that's one area segment in
0254     * a LineDiagram showing areas, or one bar in a BarDiagram, one pie slice ...
0255     *
0256     * See detailed description of \a KChart::Position for an illustration of the
0257     * different possible reference positions.
0258     *
0259    * \sa negativePosition
0260    */
0261   void setNegativePosition( const RelativePosition& relPosition );
0262 
0263    /**
0264    * \brief Return the relative positioning of the data value labels
0265    * \sa setNegativePosition
0266    */
0267   const RelativePosition negativePosition() const;
0268 
0269   /**
0270    * \brief Defines the relative position of the data value labels for positive values.
0271    *
0272    * The position is specified in relation to the respective data value point, or in
0273    * relation to the respective data representation area, that's one area segment in
0274    * a LineDiagram showing areas, or one bar in a BarDiagram, one pie slice ...
0275    *
0276    * See detailed description of \a KChart::Position for an illustration of the
0277    * different possible reference positions.
0278    *
0279    * \sa positivePosition
0280    */
0281   void setPositivePosition( const RelativePosition& relPosition );
0282 
0283    /**
0284    * \brief Return the relative positioning of the data value labels
0285    * \sa setPositivePosition
0286    */
0287   const RelativePosition positivePosition() const;
0288 
0289   const RelativePosition position( bool positive ) const
0290   {
0291     return positive ? positivePosition() : negativePosition();
0292   }
0293 
0294 private:
0295   KCHART_DECLARE_PRIVATE_BASE_VALUE( DataValueAttributes )
0296 
0297 }; // End of class DataValueAttributes
0298 
0299 }
0300 
0301 #if !defined(QT_NO_DEBUG_STREAM)
0302 KCHART_EXPORT QDebug operator<<(QDebug, const KChart::DataValueAttributes& );
0303 #endif /* QT_NO_DEBUG_STREAM */
0304 
0305 KCHART_DECLARE_SWAP_SPECIALISATION( KChart::DataValueAttributes )
0306 
0307 QT_BEGIN_NAMESPACE
0308 Q_DECLARE_TYPEINFO( KChart::DataValueAttributes, Q_MOVABLE_TYPE );
0309 QT_END_NAMESPACE
0310 
0311 Q_DECLARE_METATYPE( KChart::DataValueAttributes )
0312 
0313 #endif // KCHARTDATAVALUEATTRIBUTES_H