-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqwt_abstract_scale.cpp
157 lines (126 loc) · 3.86 KB
/
qwt_abstract_scale.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_abstract_scale.h"
#include "qwt_scale_engine.h"
#include "qwt_scale_draw.h"
#include "qwt_scale_div.h"
#include "qwt_scale_map.h"
#include "qwt_interval.h"
/*!
Constructor
Creates a default QwtScaleDraw and a QwtLinearScaleEngine.
*/
QwtAbstractScale::QwtAbstractScale():
stepSize( 0.0 )
{
scaleEngine = new QwtLinearScaleEngine;
scaleDraw = new QwtScaleDraw();
rescale( 0.0, 100.0 );
}
//! Destructor
QwtAbstractScale::~QwtAbstractScale()
{
delete scaleEngine;
delete scaleDraw;
}
/*!
\brief Specify a scale.
Disable autoscaling and define a scale by an interval and a step size
\param vmin lower limit of the scale interval
\param vmax upper limit of the scale interval
\param stepSize major step size
*/
void QwtAbstractScale::setScale( double vmin, double vmax, double _stepSize )
{
stepSize = _stepSize;
rescale( vmin, vmax, stepSize );
}
/*!
\brief Specify a scale.
Disable autoscaling and define a scale by an interval and a step size
\param interval Interval
\param stepSize major step size
*/
void QwtAbstractScale::setScale( const QwtInterval &interval, double stepSize )
{
setScale( interval.minValue(), interval.maxValue(), stepSize );
}
/*!
\brief Specify a scale.
Disable autoscaling and define a scale by a scale division
\param scaleDiv Scale division
*/
void QwtAbstractScale::setScale( const QwtScaleDiv &scaleDiv )
{
if ( scaleDiv != scaleDraw->scaleDiv() )
{
scaleDraw->setScaleDiv( scaleDiv );
scaleChange();
}
}
/*!
Recalculate the scale division and update the scale draw.
\param vmin Lower limit of the scale interval
\param vmax Upper limit of the scale interval
\param stepSize Major step size
\sa scaleChange()
*/
void QwtAbstractScale::rescale( double vmin, double vmax, double stepSize )
{
const QwtScaleDiv scaleDiv = scaleEngine->divideScale(
vmin, vmax, 5, 3, stepSize );
if ( scaleDiv != scaleDraw->scaleDiv() )
{
scaleDraw->setTransformation(
scaleEngine->transformation() );
scaleDraw->setScaleDiv( scaleDiv );
scaleChange();
}
}
/*!
\brief Set a scale draw
scaleDraw has to be created with new and will be deleted in
~QwtAbstractScale or the next call of setAbstractScaleDraw.
*/
void QwtAbstractScale::setAbstractScaleDraw( QwtScaleDraw *_scaleDraw )
{
if ( _scaleDraw == NULL || scaleDraw == _scaleDraw )
return;
if ( scaleDraw != NULL )
_scaleDraw->setScaleDiv( scaleDraw->scaleDiv() );
delete scaleDraw;
scaleDraw = _scaleDraw;
}
void QwtAbstractScale::updateScaleDraw()
{
rescale( scaleDraw->scaleDiv().lowerBound(),
scaleDraw->scaleDiv().upperBound(), stepSize );
}
/*!
\brief Set a scale engine
The scale engine is responsible for calculating the scale division,
and in case of auto scaling how to align the scale.
scaleEngine has to be created with new and will be deleted in
~QwtAbstractScale or the next call of setScaleEngine.
*/
void QwtAbstractScale::setScaleEngine( QwtScaleEngine *_scaleEngine )
{
if ( _scaleEngine != NULL && scaleEngine != _scaleEngine )
{
delete scaleEngine;
scaleEngine = _scaleEngine;
}
}
/*!
\brief Notify changed scale
Dummy empty implementation, intended to be overloaded by derived classes
*/
void QwtAbstractScale::scaleChange()
{
}