File indexing completed on 2024-05-12 15:54:15

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