QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
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 constexpr double p1() const noexcept;
79 constexpr double p2() const noexcept;
80
82 constexpr double s1() const noexcept;
84 constexpr double s2() const noexcept;
85
87 double pDist() const;
89 double sDist() const;
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 constexpr bool isLinear() const noexcept;
108
110 constexpr bool isInverting() const noexcept;
111
113 constexpr double cnv() const noexcept;
114
116 constexpr double ts1() const noexcept;
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
135inline constexpr double QwtScaleMap::s1() const noexcept
136{
137 return m_s1;
138}
139
143inline constexpr double QwtScaleMap::s2() const noexcept
144{
145 return m_s2;
146}
147
151inline constexpr double QwtScaleMap::p1() const noexcept
152{
153 return m_p1;
154}
155
159inline constexpr double QwtScaleMap::p2() const noexcept
160{
161 return m_p2;
162}
163
167inline double QwtScaleMap::pDist() const
168{
169 return qAbs(m_p2 - m_p1);
170}
171
175inline double QwtScaleMap::sDist() const
176{
177 return qAbs(m_s2 - m_s1);
178}
179
186inline double QwtScaleMap::transform(double s) const
187{
188 if (m_transform)
189 s = m_transform->transform(s);
190
191 return m_p1 + (s - m_ts1) * m_cnv;
192}
193
200inline double QwtScaleMap::invTransform(double p) const
201{
202 double s = m_ts1 + (p - m_p1) / m_cnv;
203 if (m_transform)
204 s = m_transform->invTransform(s);
205
206 return s;
207}
208
210inline constexpr bool QwtScaleMap::isInverting() const noexcept
211{
212 return ((m_p1 < m_p2) != (m_s1 < m_s2));
213}
214
216inline constexpr bool QwtScaleMap::isLinear() const noexcept
217{
218 return m_transform == nullptr;
219}
220
222inline constexpr double QwtScaleMap::cnv() const noexcept
223{
224 return m_cnv;
225}
226
228inline constexpr double QwtScaleMap::ts1() const noexcept
229{
230 return m_ts1;
231}
232
233#ifndef QT_NO_DEBUG_STREAM
234QWTCORE_EXPORT QDebug operator<<(QDebug, const QwtScaleMap&);
235#endif
236
237#endif
A scale map
Definition qwt_scale_map.h:44
constexpr bool isLinear() const noexcept
Check if this scale has no nonlinear transformation
Definition qwt_scale_map.h:216
constexpr double p2() const noexcept
Return second border of paint interval
Definition qwt_scale_map.h:159
constexpr bool isInverting() const noexcept
Check if the mapping direction is inverted
Definition qwt_scale_map.h:210
double pDist() const
Return distance between paint interval boundaries
Definition qwt_scale_map.h:167
double transform(double s) const
Transform a scale value to paint device coordinate
Definition qwt_scale_map.h:186
constexpr double s2() const noexcept
Return second border of scale interval
Definition qwt_scale_map.h:143
constexpr double ts1() const noexcept
Transformed scale origin for linear fast-path
Definition qwt_scale_map.h:228
double sDist() const
Return distance between scale interval boundaries
Definition qwt_scale_map.h:175
constexpr double s1() const noexcept
Return first border of scale interval
Definition qwt_scale_map.h:135
double invTransform(double p) const
Transform a paint device coordinate to scale value
Definition qwt_scale_map.h:200
constexpr double p1() const noexcept
Return first border of paint interval
Definition qwt_scale_map.h:151
constexpr double cnv() const noexcept
Conversion factor for linear fast-path: result = p1() + (value - ts1()) * cnv()
Definition qwt_scale_map.h:222
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