QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
qwt_scale_map.h
1/******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *
9 * Modified by ChenZongYan in 2024 <czy.t@163.com>
10 * Summary of major modifications (see ChangeLog.md for full history):
11 * 1. CMake build system & C++11 throughout.
12 * 2. Core panner/ zoomer refactored:
13 * - QwtPanner → QwtCachePanner (pixmap-cache version)
14 * - New real-time QwtPlotPanner derived from QwtPicker.
15 * 3. Zoomer supports multi-axis.
16 * 4. Parasite-plot framework:
17 * - QwtFigure, QwtPlotParasiteLayout, QwtPlotTransparentCanvas,
18 * - QwtPlotScaleEventDispatcher, built-in pan/zoom on axis.
19 * 5. New picker: QwtPlotSeriesDataPicker (works with date axis).
20 * 6. Raster & color-map extensions:
21 * - QwtGridRasterData (2-D table + interpolation)
22 * - QwtLinearColorMap::stopColors(), stopPos() API rename.
23 * 7. Bar-chart: expose pen/brush control.
24 * 8. Amalgamated build: single QwtPlot.h / QwtPlot.cpp pair in src-amalgamate.
25 *****************************************************************************/
26
27#ifndef QWT_SCALE_MAP_H
28#define QWT_SCALE_MAP_H
29
30#include "qwtcore_global.h"
31#include "qwt_transform.h"
32
33class QPointF;
34class QRectF;
35
43class QWTCORE_EXPORT QwtScaleMap
44{
45public:
52
55
57 QwtScaleMap& operator=(const QwtScaleMap&);
59 QwtScaleMap& operator=(QwtScaleMap&&);
60
62 void setTransformation(QwtTransform*);
64 const QwtTransform* transformation() const;
65
67 void setPaintInterval(double p1, double p2);
69 void setScaleInterval(double s1, double s2);
70
72 double transform(double s) const;
74 double invTransform(double p) const;
75
77 Q_DECL_CONSTEXPR double p1() const noexcept { return m_p1; }
79 Q_DECL_CONSTEXPR double p2() const noexcept { return m_p2; }
80
82 Q_DECL_CONSTEXPR double s1() const noexcept { return m_s1; }
84 Q_DECL_CONSTEXPR double s2() const noexcept { return m_s2; }
85
87 double pDist() const { return qAbs(m_p2 - m_p1); }
89 double sDist() const { return qAbs(m_s2 - m_s1); }
90
92 static QRectF transform(const QwtScaleMap&, const QwtScaleMap&, const QRectF&);
93
95 static QRectF invTransform(const QwtScaleMap&, const QwtScaleMap&, const QRectF&);
96
98 static QPointF transform(const QwtScaleMap&, const QwtScaleMap&, const QPointF&);
99
101 static QPointF invTransform(const QwtScaleMap&, const QwtScaleMap&, const QPointF&);
102
104 static bool isLinerScale(const QwtScaleMap& sm);
105
107 Q_DECL_CONSTEXPR bool isLinear() const noexcept { return m_transform == nullptr; }
108
110 Q_DECL_CONSTEXPR bool isInverting() const noexcept { return ((m_p1 < m_p2) != (m_s1 < m_s2)); }
111
113 Q_DECL_CONSTEXPR double cnv() const noexcept { return m_cnv; }
114
116 Q_DECL_CONSTEXPR double ts1() const noexcept { return m_ts1; }
117
118protected:
119 void swap(QwtScaleMap& other) noexcept; // helper
120private:
121 void updateFactor();
122
123 double m_s1 { 0.0 }, m_s2 { 1.0 }; // scale interval boundaries
124 double m_p1 { 0.0 }, m_p2 { 1.0 }; // paint device interval boundaries
125
126 double m_cnv { 1.0 }; // conversion factor
127 double m_ts1 { 0.0 };
128
129 QwtTransform* m_transform { nullptr };
130};
131
138inline double QwtScaleMap::transform(double s) const
139{
140 if (m_transform)
141 s = m_transform->transform(s);
142
143 return m_p1 + (s - m_ts1) * m_cnv;
144}
145
152inline double QwtScaleMap::invTransform(double p) const
153{
154 double s = m_ts1 + (p - m_p1) / m_cnv;
155 if (m_transform)
156 s = m_transform->invTransform(s);
157
158 return s;
159}
160
161#ifndef QT_NO_DEBUG_STREAM
162QWTCORE_EXPORT QDebug operator<<(QDebug, const QwtScaleMap&);
163#endif
164
165#endif
A scale map.
Definition qwt_scale_map.h:44
Q_DECL_CONSTEXPR double p2() const noexcept
Return second border of paint interval.
Definition qwt_scale_map.h:79
Q_DECL_CONSTEXPR double s2() const noexcept
Return second border of scale interval.
Definition qwt_scale_map.h:84
Q_DECL_CONSTEXPR double p1() const noexcept
Return first border of paint interval.
Definition qwt_scale_map.h:77
double pDist() const
Return distance between paint interval boundaries.
Definition qwt_scale_map.h:87
double transform(double s) const
Transform a scale value to paint device coordinate.
Definition qwt_scale_map.h:138
Q_DECL_CONSTEXPR double ts1() const noexcept
Transformed scale origin for linear fast-path.
Definition qwt_scale_map.h:116
double sDist() const
Return distance between scale interval boundaries.
Definition qwt_scale_map.h:89
Q_DECL_CONSTEXPR double cnv() const noexcept
Conversion factor for linear fast-path: result = p1() + (value - ts1()) * cnv()
Definition qwt_scale_map.h:113
Q_DECL_CONSTEXPR bool isLinear() const noexcept
Check if this scale has no nonlinear transformation.
Definition qwt_scale_map.h:107
double invTransform(double p) const
Transform a paint device coordinate to scale value.
Definition qwt_scale_map.h:152
Q_DECL_CONSTEXPR double s1() const noexcept
Return first border of scale interval.
Definition qwt_scale_map.h:82
Q_DECL_CONSTEXPR bool isInverting() const noexcept
Check if the mapping direction is inverted.
Definition qwt_scale_map.h:110
A transformation between coordinate systems.
Definition qwt_transform.h:47
virtual double transform(double value) const =0
Transformation function.
virtual double invTransform(double value) const =0
Inverse transformation function.