KDChartMeasure.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** Copyright (C) 2001-2010 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 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 #ifndef KDCHARTMEASURE_H
00024 #define KDCHARTMEASURE_H
00025 
00026 #include <QDebug>
00027 #include <Qt>
00028 #include <QStack>
00029 #include "KDChartGlobal.h"
00030 #include "KDChartEnums.h"
00031 
00039 class QObject;
00040 class QPaintDevice;
00041 
00042 namespace KDChart {
00043 
00050 class KDCHART_EXPORT Measure
00051 {
00052 public:
00053     Measure();
00054     /*implicit*/ Measure( qreal value,
00055                           KDChartEnums::MeasureCalculationMode mode = KDChartEnums::MeasureCalculationModeAuto,
00056                           KDChartEnums::MeasureOrientation orientation = KDChartEnums::MeasureOrientationAuto );
00057     Measure( const Measure& );
00058     Measure &operator= ( const Measure& );
00059 
00060     void setValue( qreal val ){ mValue = val; }
00061     qreal value() const { return mValue; }
00062 
00063     void setCalculationMode( KDChartEnums::MeasureCalculationMode mode ){ mMode = mode; }
00064     KDChartEnums::MeasureCalculationMode calculationMode() const { return mMode; }
00065 
00071     void setRelativeMode( const QObject * area,
00072                           KDChartEnums::MeasureOrientation orientation )
00073     {
00074         mMode = KDChartEnums::MeasureCalculationModeRelative;
00075         mArea = area;
00076         mOrientation = orientation;
00077     }
00078 
00089     void setAbsoluteValue( qreal val )
00090     {
00091         mMode = KDChartEnums::MeasureCalculationModeAbsolute;
00092         mValue = val;
00093     }
00094 
00100     void setReferenceArea( const QObject * area ){ mArea = area; }
00105     const QObject * referenceArea() const { return mArea; }
00106 
00107     void setReferenceOrientation( KDChartEnums::MeasureOrientation orientation ){ mOrientation = orientation; }
00108     KDChartEnums::MeasureOrientation referenceOrientation() const { return mOrientation; }
00109 
00115     qreal calculatedValue( const QObject * autoArea, KDChartEnums::MeasureOrientation autoOrientation ) const;
00116     qreal calculatedValue( const QSizeF& autoSize, KDChartEnums::MeasureOrientation autoOrientation ) const;
00117     const QSizeF sizeOfArea( const QObject* area ) const;
00118 
00119     bool operator==( const Measure& ) const;
00120     bool operator!=( const Measure& other ) const { return !operator==(other); }
00121 
00122 private:
00123     qreal mValue;
00124     KDChartEnums::MeasureCalculationMode mMode;
00125     const QObject* mArea;
00126     KDChartEnums::MeasureOrientation mOrientation;
00127 }; // End of class Measure
00128 
00129 
00130 
00142 class GlobalMeasureScaling
00143 {
00144 public:
00145     static GlobalMeasureScaling* instance();
00146 
00147     GlobalMeasureScaling();
00148     virtual ~GlobalMeasureScaling();
00149 
00150 public:
00155     static void setFactors(qreal factorX, qreal factorY);
00156 
00163     static void resetFactors();
00164 
00168     static const QPair< qreal, qreal > currentFactors();
00169 
00173     static void setPaintDevice( QPaintDevice* paintDevice );
00174 
00178     static QPaintDevice* paintDevice();
00179 
00180 private:
00181     QStack< QPair< qreal, qreal > > mFactors;
00182     QPaintDevice* m_paintDevice;
00183 };
00184 
00185 }
00186 
00187 #if !defined(QT_NO_DEBUG_STREAM)
00188 KDCHART_EXPORT QDebug operator<<(QDebug, const KDChart::Measure& );
00189 #endif /* QT_NO_DEBUG_STREAM */
00190 
00191 #endif // KDCHARTMEASURE_H