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

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 __KChartEnums_H__
0010 #define __KChartEnums_H__
0011 
0012 #include "KChartGlobal.h"
0013 
0014 #include <QRectF>
0015 #include <QObject>
0016 #include <QVector>
0017 
0018 /** \file KChartEnums.h
0019   \brief Definition of global enums.
0020   */
0021 
0022 /**
0023   Project global class providing some enums needed both by KChartParams
0024   and by KChartCustomBox.
0025   */
0026 class KCHART_EXPORT KChartEnums :public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     /**
0032       GranularitySequence specifies the values, that may be applied,
0033       to determine a step width within a given data range.
0034 
0035       \note Granularity with can be set for Linear axis calculation mode only,
0036       there is no way to specify a step width for Logarithmic axes.
0037 
0038       Value occurring in the GranularitySequence names only are showing
0039       their respective relation ship.  For real data they will most times not
0040       be used directly, but be multiplied by positive (or negative, resp.)
0041       powers of ten.
0042 
0043       A granularity sequence is a sequence of values from the following set:
0044       1, 1.25, 2, 2.5, 5.
0045 
0046       The reason for using one of the following three pre-defined granularity
0047       sequences (instead of just using the best matching step width) is to
0048       follow a simple rule: If scaling becomes finer (== smaller step width)
0049       no value, that has been on a grid line before, shall loose its line
0050       and be NOT on a grid line anymore!
0051 
0052       This means: Smaller step width may not remove any grid lines, but it
0053       may add additional lines in between.
0054 
0055       \li \c GranularitySequence_10_20 Step widths can be 1, or 2, but they never can be 2.5 nor 5, nor 1.25.
0056       \li \c GranularitySequence_10_50 Step widths can be 1, or 5, but they never can be 2, nor 2.5, nor 1.25.
0057       \li \c GranularitySequence_25_50 Step widths can be 2.5, or 5, but they never can be 1, nor 2, nor 1.25.
0058       \li \c GranularitySequence_125_25 Step widths can be 1.25 or 2.5 but they never can be 1, nor 2, nor 5.
0059       \li \c GranularitySequenceIrregular Step widths can be all of these values: 1, or 1.25, or 2, or 2.5, or 5.
0060 
0061       \note When ever possible, try to avoid using GranularitySequenceIrregular!
0062       Allowing all possible step values, using this granularity sequence involves a
0063       serious risk: Your users might be irritated due to 'jumping' grid lines, when step size
0064       is changed from 2.5 to 2 (or vice versa, resp.).
0065       In case you still want to use GranularitySequenceIrregular just make sure to NOT draw
0066       any sub-grid lines, because in most cases you will get not-matching step widths for
0067       the sub-grid.
0068       In short: GranularitySequenceIrregular can safely be used if your data range is not
0069       changing at all AND (b) you will not allow the coordinate plane to be zoomed
0070       AND (c) you are not displaying any sub-grid lines.
0071 
0072       Since you probably like having the value 1 as an allowed step width,
0073       the granularity sequence decision boils down to a boolean question:
0074       \li To get ten divided by five you use GranularitySequence_10_20, while
0075       \li for having it divided by two GranularitySequence_10_50 is your choice.
0076 
0077       */
0078     enum GranularitySequence {
0079         GranularitySequence_10_20,
0080         GranularitySequence_10_50,
0081         GranularitySequence_25_50,
0082         GranularitySequence_125_25,
0083         GranularitySequenceIrregular
0084     };
0085     Q_ENUM(GranularitySequence)
0086 
0087 
0088     /**
0089       Converts the specified granularity sequence enum to a
0090       string representation.
0091 
0092       \param sequence the granularity sequence enum to convert
0093       \return the string representation of the granularity sequence
0094       */
0095     static QString granularitySequenceToString( GranularitySequence sequence ) {
0096         switch ( sequence ) {
0097             case GranularitySequence_10_20:
0098                 return QString::fromLatin1("GranularitySequence_10_20");
0099             case GranularitySequence_10_50:
0100                 return QString::fromLatin1("GranularitySequence_10_50");
0101             case GranularitySequence_25_50:
0102                 return QString::fromLatin1("GranularitySequence_25_50");
0103             case GranularitySequence_125_25:
0104                 return QString::fromLatin1("GranularitySequence_125_25");
0105             case GranularitySequenceIrregular:
0106                 return QString::fromLatin1("GranularitySequenceIrregular");
0107         }
0108         Q_ASSERT( !"Unknown GranularitySequenceValue" );
0109         return QString::fromLatin1("GranularitySequence_10_20");
0110     }
0111 
0112 
0113     /**
0114       Converts the specified string to a granularity sequence enum value.
0115 
0116       \param string the string to convert
0117       \return the granularity sequence enum value
0118       */
0119     static GranularitySequence stringToGranularitySequence( const QString& string ) {
0120       if ( string == QString::fromLatin1("GranularitySequence_10_20") )
0121           return GranularitySequence_10_20;
0122       if ( string == QString::fromLatin1("GranularitySequence_10_50") )
0123           return GranularitySequence_10_50;
0124       if ( string == QString::fromLatin1("GranularitySequence_25_50") )
0125           return GranularitySequence_25_50;
0126       if ( string == QString::fromLatin1("GranularitySequence_125") )
0127           return GranularitySequence_125_25;
0128       if ( string == QString::fromLatin1("GranularitySequenceIrregular") )
0129           return GranularitySequenceIrregular;
0130       // default, should not happen
0131       return GranularitySequence_10_20;
0132     }
0133 
0134 
0135     /**
0136       Text layout policy: what to do if text that is to be drawn would
0137       cover neighboring text or neighboring areas.
0138 
0139       \li \c LayoutJustOverwrite Just ignore the layout collision and write the text nevertheless.
0140       \li \c LayoutPolicyRotate Try counter-clockwise rotation to make the text fit into the space.
0141       \li \c LayoutPolicyShiftVertically Shift the text baseline upwards (or downwards, resp.) and draw a connector line between the text and its anchor.
0142       \li \c LayoutPolicyShiftHorizontally Shift the text baseline to the left (or to the right, resp.) and draw a connector line between the text and its anchor.
0143       \li \c LayoutPolicyShrinkFontSize Reduce the text font size.
0144 
0145       \sa KChartParams::setPrintDataValues
0146       */
0147     enum TextLayoutPolicy { LayoutJustOverwrite,
0148         LayoutPolicyRotate,
0149         LayoutPolicyShiftVertically,
0150         LayoutPolicyShiftHorizontally,
0151         LayoutPolicyShrinkFontSize
0152     };
0153     Q_ENUM( TextLayoutPolicy )
0154 
0155     /**
0156       Converts the specified text layout policy enum to a
0157       string representation.
0158 
0159       \param type the text layout policy to convert
0160       \return the string representation of the text layout policy enum
0161       */
0162     static QString layoutPolicyToString( TextLayoutPolicy type );
0163 
0164 
0165     /**
0166       Converts the specified string to a text layout policy enum value.
0167 
0168       \param string the string to convert
0169       \return the text layout policy enum value
0170       */
0171     static TextLayoutPolicy stringToLayoutPolicy( const QString& string );
0172 
0173 
0174     /**
0175         Numerical values of the static KChart::Position instances,
0176         for using a Position::value() with a switch () statement.
0177 
0178         \sa Position
0179     */
0180     enum PositionValue {
0181         PositionUnknown   = 0,
0182         PositionCenter    = 1,
0183         PositionNorthWest = 2,
0184         PositionNorth     = 3,
0185         PositionNorthEast = 4,
0186         PositionEast      = 5,
0187         PositionSouthEast = 6,
0188         PositionSouth     = 7,
0189         PositionSouthWest = 8,
0190         PositionWest      = 9,
0191         PositionFloating  =10
0192     };
0193     Q_ENUM( PositionValue )
0194 
0195 
0196     /**
0197       Measure calculation mode: the way how the absolute value of a KChart::Measure is determined during KChart's internal geometry calculation time.
0198 
0199       KChart::Measure values either are relative (calculated in relation to a given AbstractArea), or they are absolute (used as fixed values).
0200 
0201       Values stored in relative measure always are interpreted as per-mille of a reference area's height (or width, resp.) depending on the orientation set for the KChart::Measure.
0202 
0203       \li \c MeasureCalculationModeAbsolute Value set by setValue() is absolute, to be used unchanged.
0204       \li \c MeasureCalculationModeRelative Value is relative, the reference area is specified by setReferenceArea(), and orientation specified by setOrientation().
0205       \li \c MeasureCalculationModeAuto Value is relative, KChart will automatically determine which reference area to use, and it will determine the orientation too.
0206       \li \c MeasureCalculationModeAutoArea Value is relative, Orientation is specified by setOrientation(), and KChart will automatically determine which reference area to use.
0207       \li \c MeasureCalculationModeAutoOrientation Value is relative, Area is specified by setReferenceArea(), and KChart will automatically determine which orientation to use.
0208 
0209       \sa KChart::Measure::setCalculationMode
0210       */
0211     enum MeasureCalculationMode {
0212         MeasureCalculationModeAbsolute,
0213         MeasureCalculationModeRelative,
0214         MeasureCalculationModeAuto,
0215         MeasureCalculationModeAutoArea,
0216         MeasureCalculationModeAutoOrientation
0217     };
0218     Q_ENUM( MeasureCalculationMode )
0219 
0220     /**
0221       Converts the specified measure calculation mode enum to a
0222       string representation.
0223 
0224       \param mode the measure calculation mode to convert
0225       \return the string representation of the Measure calculation mode enum
0226       */
0227     static QString measureCalculationModeToString( MeasureCalculationMode mode ) {
0228         switch ( mode ) {
0229             case MeasureCalculationModeAbsolute:
0230                 return QString::fromLatin1("MeasureCalculationModeAbsolute");
0231             case MeasureCalculationModeAuto:
0232                 return QString::fromLatin1("MeasureCalculationModeAuto");
0233             case MeasureCalculationModeAutoArea:
0234                 return QString::fromLatin1("MeasureCalculationModeAutoArea");
0235             case MeasureCalculationModeAutoOrientation:
0236                 return QString::fromLatin1("MeasureCalculationModeAutoOrientation");
0237             case MeasureCalculationModeRelative:
0238                 return QString::fromLatin1("MeasureCalculationModeRelative");
0239         }
0240         Q_ASSERT( !"unhandled MeasureCalculationMode" );
0241         return QString::fromLatin1("MeasureCalculationModeAuto");
0242     }
0243 
0244 
0245     /**
0246       Converts the specified string to a measure calculation mode enum value.
0247 
0248       \param string the string to convert
0249       \return the measure calculation mode enum value
0250       */
0251     static MeasureCalculationMode stringToMeasureCalculationMode( const QString& string ) {
0252       if ( string == QString::fromLatin1("MeasureCalculationModeAbsolute") )
0253           return MeasureCalculationModeAbsolute;
0254       if ( string == QString::fromLatin1("MeasureCalculationModeAuto") )
0255           return MeasureCalculationModeAuto;
0256       if ( string == QString::fromLatin1("MeasureCalculationModeAutoArea") )
0257           return MeasureCalculationModeAutoArea;
0258       if ( string == QString::fromLatin1("MeasureCalculationModeAutoOrientation") )
0259           return MeasureCalculationModeAutoOrientation;
0260       if ( string == QString::fromLatin1("MeasureCalculationModeRelative") )
0261           return MeasureCalculationModeRelative;
0262       // default, should not happen
0263       return MeasureCalculationModeAuto;
0264     }
0265 
0266     /**
0267       Measure orientation mode: the way how the absolute value of a KChart::Measure is determined during KChart's internal geometry calculation time.
0268 
0269       KChart::Measure values either are relative (calculated in relation to a given AbstractArea), or they are absolute (used as fixed values).
0270 
0271       Values stored in relative measure take into account the width (and/or the height, resp.) of a so-called reference area,
0272       that is either specified by KChart::Measure::setReferenceArea, or determined by KChart automatically, respectively.
0273 
0274       \li \c MeasureOrientationAuto Value is calculated, based upon the width (or on the height, resp.) of the reference area: KChart will automatically determie an appropriate way.
0275       \li \c MeasureOrientationHorizontal Value is calculated, based upon the width of the reference area.
0276       \li \c MeasureOrientationVertical Value is calculated, based upon the height of the reference area.
0277       \li \c MeasureOrientationMinimum Value is calculated, based upon the width (or on the height, resp.) of the reference area - which ever is smaller.
0278       \li \c MeasureOrientationMaximum Value is calculated, based upon the width (or on the height, resp.) of the reference area - which ever is smaller.
0279 
0280       \sa KChart::Measure::setOrientationMode
0281       */
0282     enum MeasureOrientation {
0283         MeasureOrientationAuto,
0284         MeasureOrientationHorizontal,
0285         MeasureOrientationVertical,
0286         MeasureOrientationMinimum,
0287         MeasureOrientationMaximum
0288     };
0289     Q_ENUM( MeasureOrientation )
0290 
0291     /**
0292       Converts the specified measure orientation enum to a
0293       string representation.
0294 
0295       \param mode the measure orientation to convert
0296       \return the string representation of the measure orientation enum
0297       */
0298     static QString measureOrientationToString( MeasureOrientation mode ) {
0299         switch ( mode ) {
0300             case MeasureOrientationAuto:
0301                 return QString::fromLatin1("MeasureOrientationAuto");
0302             case MeasureOrientationHorizontal:
0303                 return QString::fromLatin1("MeasureOrientationHorizontal");
0304             case MeasureOrientationVertical:
0305                 return QString::fromLatin1("MeasureOrientationVertical");
0306             case MeasureOrientationMinimum:
0307                 return QString::fromLatin1("MeasureOrientationMinimum");
0308             case MeasureOrientationMaximum:
0309                 return QString::fromLatin1("MeasureOrientationMaximum");
0310         }
0311         Q_ASSERT( !"Unknown MeasureOrientation value" );
0312         return QString::fromLatin1("MeasureOrientationAuto");
0313     }
0314 
0315 
0316     /**
0317       Converts the specified string to a measure orientation enum value.
0318 
0319       \param string the string to convert
0320       \return the measure orientation enum value
0321       */
0322     static MeasureOrientation stringToMeasureOrientation( const QString& string ) {
0323       if ( string == QString::fromLatin1("MeasureOrientationAuto") )
0324           return MeasureOrientationAuto;
0325       if ( string == QString::fromLatin1("MeasureOrientationHorizontal") )
0326           return MeasureOrientationHorizontal;
0327       if ( string == QString::fromLatin1("MeasureOrientationVertical") )
0328           return MeasureOrientationVertical;
0329       if ( string == QString::fromLatin1("MeasureOrientationMinimum") )
0330           return MeasureOrientationMinimum;
0331       if ( string == QString::fromLatin1("MeasureOrientationMaximum") )
0332           return MeasureOrientationMaximum;
0333       // default, should not happen
0334       return MeasureOrientationAuto;
0335     }
0336 
0337 
0338 };
0339 
0340 
0341 #endif