1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
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
*****************************************************************************/
10
#include "qwt_scale_engine.h"
11
#include "qwt_scale_draw.h"
12
#include "qwt_scale_div.h"
13
#include "qwt_scale_map.h"
14
#include "qwt_double_interval.h"
15
#include "qwt_abstract_scale.h"
17
class QwtAbstractScale::PrivateData
26
scaleEngine = new QwtLinearScaleEngine;
27
scaleDraw = new QwtScaleDraw();
36
QwtScaleEngine *scaleEngine;
37
QwtAbstractScaleDraw *scaleDraw;
49
Creates a default QwtScaleDraw and a QwtLinearScaleEngine.
50
Autoscaling is enabled, and the stepSize is initialized by 0.0.
53
QwtAbstractScale::QwtAbstractScale()
55
d_data = new PrivateData;
60
QwtAbstractScale::~QwtAbstractScale()
66
\brief Specify a scale.
68
Disable autoscaling and define a scale by an interval and a step size
70
\param vmin lower limit of the scale interval
71
\param vmax upper limit of the scale interval
72
\param stepSize major step size
75
void QwtAbstractScale::setScale(double vmin, double vmax, double stepSize)
77
d_data->autoScale = false;
78
d_data->stepSize = stepSize;
80
rescale(vmin, vmax, stepSize);
84
\brief Specify a scale.
86
Disable autoscaling and define a scale by an interval and a step size
88
\param interval Interval
89
\param stepSize major step size
92
void QwtAbstractScale::setScale(const QwtDoubleInterval &interval,
95
setScale(interval.minValue(), interval.maxValue(), stepSize);
100
\brief Specify a scale.
102
Disable autoscaling and define a scale by a scale division
104
\param scaleDiv Scale division
107
void QwtAbstractScale::setScale(const QwtScaleDiv &scaleDiv)
109
d_data->autoScale = false;
111
if (scaleDiv != d_data->scaleDraw->scaleDiv())
113
d_data->scaleDraw->setScaleDiv(scaleDiv);
119
Recalculate the scale division and update the scale draw.
121
\param vmin Lower limit of the scale interval
122
\param vmax Upper limit of the scale interval
123
\param stepSize Major step size
127
void QwtAbstractScale::rescale(double vmin, double vmax, double stepSize)
129
const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(
130
vmin, vmax, d_data->maxMajor, d_data->maxMinor, stepSize);
132
if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
134
d_data->scaleDraw->setTransformation(
135
d_data->scaleEngine->transformation());
136
d_data->scaleDraw->setScaleDiv(scaleDiv);
142
\brief Advise the widget to control the scale range internally.
144
Autoscaling is on by default.
145
\sa setScale(), autoScale()
147
void QwtAbstractScale::setAutoScale()
149
if (!d_data->autoScale)
151
d_data->autoScale = true;
157
\return \c true if autoscaling is enabled
159
bool QwtAbstractScale::autoScale() const
161
return d_data->autoScale;
165
\brief Set the maximum number of major tick intervals.
167
The scale's major ticks are calculated automatically such that
168
the number of major intervals does not exceed ticks.
169
The default value is 5.
170
\param ticks maximal number of major ticks.
171
\sa QwtAbstractScaleDraw
173
void QwtAbstractScale::setScaleMaxMajor(int ticks)
175
if (ticks != d_data->maxMajor)
177
d_data->maxMajor = ticks;
183
\brief Set the maximum number of minor tick intervals
185
The scale's minor ticks are calculated automatically such that
186
the number of minor intervals does not exceed ticks.
187
The default value is 3.
189
\sa QwtAbstractScaleDraw
191
void QwtAbstractScale::setScaleMaxMinor(int ticks)
193
if ( ticks != d_data->maxMinor)
195
d_data->maxMinor = ticks;
201
\return Max. number of minor tick intervals
202
The default value is 3.
204
int QwtAbstractScale::scaleMaxMinor() const
206
return d_data->maxMinor;
210
\return Max. number of major tick intervals
211
The default value is 5.
213
int QwtAbstractScale::scaleMaxMajor() const
215
return d_data->maxMajor;
219
\brief Set a scale draw
221
scaleDraw has to be created with new and will be deleted in
222
~QwtAbstractScale or the next call of setAbstractScaleDraw.
224
void QwtAbstractScale::setAbstractScaleDraw(QwtAbstractScaleDraw *scaleDraw)
226
if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )
229
delete d_data->scaleDraw;
230
d_data->scaleDraw = scaleDraw;
235
\sa setAbstractScaleDraw()
237
QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()
239
return d_data->scaleDraw;
244
\sa setAbstractScaleDraw()
246
const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
248
return d_data->scaleDraw;
251
void QwtAbstractScale::updateScaleDraw()
253
rescale( d_data->scaleDraw->scaleDiv().lBound(),
254
d_data->scaleDraw->scaleDiv().hBound(), d_data->stepSize);
258
\brief Set a scale engine
260
The scale engine is responsible for calculating the scale division,
261
and in case of auto scaling how to align the scale.
263
scaleEngine has to be created with new and will be deleted in
264
~QwtAbstractScale or the next call of setScaleEngine.
266
void QwtAbstractScale::setScaleEngine(QwtScaleEngine *scaleEngine)
268
if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )
270
delete d_data->scaleEngine;
271
d_data->scaleEngine = scaleEngine;
279
const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
281
return d_data->scaleEngine;
288
QwtScaleEngine *QwtAbstractScale::scaleEngine()
290
return d_data->scaleEngine;
294
\brief Notify changed scale
296
Dummy empty implementation, intended to be overloaded by derived classes
298
void QwtAbstractScale::scaleChange()
303
\return abstractScaleDraw()->scaleMap()
305
const QwtScaleMap &QwtAbstractScale::scaleMap() const
307
return d_data->scaleDraw->scaleMap();