KChart

KChartMeasure.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#ifndef KCHARTMEASURE_H
10#define KCHARTMEASURE_H
11
12#include <QDebug>
13#include <Qt>
14#include <QStack>
15#include "KChartGlobal.h"
16#include "KChartEnums.h"
17
18/** \file KChartMeasure.h
19 * \brief Declaring the class KChart::Measure.
20 *
21 *
22 */
23
24QT_BEGIN_NAMESPACE
25class QObject;
26class QPaintDevice;
27QT_END_NAMESPACE
28
29namespace KChart {
30
31/**
32 * \class Measure KChartMeasure.h KChartMeasure
33 * \brief Measure is used to specify relative and absolute sizes in KChart, e.g. font sizes.
34 *
35 */
36
37class KCHART_EXPORT Measure
38{
39public:
40 Measure();
41 /*implicit*/ Measure( qreal value,
42 KChartEnums::MeasureCalculationMode mode = KChartEnums::MeasureCalculationModeAuto,
43 KChartEnums::MeasureOrientation orientation = KChartEnums::MeasureOrientationAuto );
44 Measure( const Measure& );
45 Measure &operator= ( const Measure& );
46
47 void setValue( qreal val ) { mValue = val; }
48 qreal value() const { return mValue; }
49
50 void setCalculationMode( KChartEnums::MeasureCalculationMode mode ) { mMode = mode; }
51 KChartEnums::MeasureCalculationMode calculationMode() const { return mMode; }
52
53 /**
54 * The reference area must either be derived from AbstractArea
55 * or from QWidget, so it can also be derived from AbstractAreaWidget.
56 */
57 void setRelativeMode( const QObject * area,
59 {
60 mMode = KChartEnums::MeasureCalculationModeRelative;
61 mArea = area;
62 mOrientation = orientation;
63 }
64
65 /**
66 * \brief This is a convenience method for specifying a value,
67 * implicitly setting the calculation mode to MeasureCalculationModeAbsolute.
68 *
69 * Calling setAbsoluteValue( value ) is the same as calling
70\verbatim
71 setValue( value );
72 setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
73\endverbatim
74 */
75 void setAbsoluteValue( qreal val )
76 {
77 mMode = KChartEnums::MeasureCalculationModeAbsolute;
78 mValue = val;
79 }
80
81 /**
82 * The reference area must either be derived from AbstractArea
83 * or from QWidget, so it can also be derived from AbstractAreaWidget.
84 */
85 void setReferenceArea( const QObject * area ) { mArea = area; }
86 /**
87 * The returned reference area will be derived from AbstractArea
88 * or QWidget or both.
89 */
90 const QObject * referenceArea() const { return mArea; }
91
92 void setReferenceOrientation( KChartEnums::MeasureOrientation orientation ) { mOrientation = orientation; }
93 KChartEnums::MeasureOrientation referenceOrientation() const { return mOrientation; }
94
95 /**
96 * The reference area must either be derived from AbstractArea
97 * or from QWidget, so it can also be derived from AbstractAreaWidget.
98 */
99 qreal calculatedValue( const QObject * autoArea, KChartEnums::MeasureOrientation autoOrientation ) const;
100 qreal calculatedValue( const QSizeF& autoSize, KChartEnums::MeasureOrientation autoOrientation ) const;
101 const QSizeF sizeOfArea( const QObject* area ) const;
102
103 bool operator==( const Measure& ) const;
104 bool operator!=( const Measure& other ) const { return !operator==(other); }
105
106private:
107 qreal mValue;
109 const QObject* mArea;
111}; // End of class Measure
112
113
114
115/**
116 * Auxiliary class used by the KChart::Measure and KChart::Chart class.
117 *
118 * Normally there should be no need to call any of these methods yourself.
119 *
120 * They are used by KChart::Chart::paint( QPainter*, const QRect& )
121 * to adjust all of the relative Measures according to the target
122 * rectangle's size.
123 *
124 * Default factors are (1.0, 1.0)
125 */
127{
128public:
129 static GlobalMeasureScaling* instance();
130
132 virtual ~GlobalMeasureScaling();
133
134public:
135 /**
136 * Set new factors to be used by all Measure objects from now on.
137 * Previous values will be saved on a stack internally.
138 */
139 static void setFactors(qreal factorX, qreal factorY);
140
141 /**
142 * Restore factors to the values before the previous call to
143 * setFactors. The current values are popped off a stack internally.
144 */
145 static void resetFactors();
146
147 /**
148 * Return the currently active factors.
149 */
150 static const QPair< qreal, qreal > currentFactors();
151
152 /**
153 * Set the paint device to use for calculating font metrics.
154 */
156
157 /**
158 * Return the paint device to use for calculating font metrics.
159 */
160 static QPaintDevice* paintDevice();
161
162private:
164 QPaintDevice* m_paintDevice;
165};
166
167}
168
169#if !defined(QT_NO_DEBUG_STREAM)
170KCHART_EXPORT QDebug operator<<(QDebug, const KChart::Measure& );
171#endif /* QT_NO_DEBUG_STREAM */
172
173#endif // KCHARTMEASURE_H
Definition of global enums.
Contains KChart macros.
MeasureCalculationMode
Measure calculation mode: the way how the absolute value of a KChart::Measure is determined during KC...
MeasureOrientation
Measure orientation mode: the way how the absolute value of a KChart::Measure is determined during KC...
Auxiliary class used by the KChart::Measure and KChart::Chart class.
static const QPair< qreal, qreal > currentFactors()
Return the currently active factors.
static void resetFactors()
Restore factors to the values before the previous call to setFactors.
static QPaintDevice * paintDevice()
Return the paint device to use for calculating font metrics.
static void setPaintDevice(QPaintDevice *paintDevice)
Set the paint device to use for calculating font metrics.
static void setFactors(qreal factorX, qreal factorY)
Set new factors to be used by all Measure objects from now on.
Measure is used to specify relative and absolute sizes in KChart, e.g.
const QObject * referenceArea() const
The returned reference area will be derived from AbstractArea or QWidget or both.
void setRelativeMode(const QObject *area, KChartEnums::MeasureOrientation orientation)
The reference area must either be derived from AbstractArea or from QWidget, so it can also be derive...
void setAbsoluteValue(qreal val)
void setReferenceArea(const QObject *area)
The reference area must either be derived from AbstractArea or from QWidget, so it can also be derive...
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
bool operator!=(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:51:58 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.