~l3on/ubuntu/oneiric/qwt/fix-921430

« back to all changes in this revision

Viewing changes to qwt-5.0.1/src/qwt_abstract_scale.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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
 
 
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"
16
 
 
17
 
class QwtAbstractScale::PrivateData
18
 
{
19
 
public:
20
 
    PrivateData():
21
 
        maxMajor(5),
22
 
        maxMinor(3),
23
 
        stepSize(0.0),
24
 
        autoScale(true)
25
 
    {
26
 
        scaleEngine = new QwtLinearScaleEngine;
27
 
        scaleDraw = new QwtScaleDraw();
28
 
    }
29
 
 
30
 
    ~PrivateData()
31
 
    {
32
 
        delete scaleEngine;
33
 
        delete scaleDraw;
34
 
    }
35
 
 
36
 
    QwtScaleEngine *scaleEngine;
37
 
    QwtAbstractScaleDraw *scaleDraw;
38
 
 
39
 
    int maxMajor;
40
 
    int maxMinor;
41
 
    double stepSize;
42
 
 
43
 
    bool autoScale;
44
 
};
45
 
 
46
 
/*!
47
 
  Constructor
48
 
 
49
 
  Creates a default QwtScaleDraw and a QwtLinearScaleEngine. 
50
 
  Autoscaling is enabled, and the stepSize is initialized by 0.0.
51
 
*/
52
 
   
53
 
QwtAbstractScale::QwtAbstractScale()
54
 
{
55
 
    d_data = new PrivateData;
56
 
    rescale(0.0, 100.0);
57
 
}
58
 
 
59
 
//! Destructor
60
 
QwtAbstractScale::~QwtAbstractScale()
61
 
{
62
 
    delete d_data;
63
 
}
64
 
 
65
 
/*!
66
 
  \brief Specify a scale.
67
 
 
68
 
  Disable autoscaling and define a scale by an interval and a step size
69
 
 
70
 
  \param vmin lower limit of the scale interval
71
 
  \param vmax upper limit of the scale interval
72
 
  \param stepSize major step size
73
 
  \sa setAutoScale()
74
 
*/
75
 
void QwtAbstractScale::setScale(double vmin, double vmax, double stepSize)
76
 
{
77
 
    d_data->autoScale = false;
78
 
    d_data->stepSize = stepSize;
79
 
 
80
 
    rescale(vmin, vmax, stepSize);
81
 
}
82
 
 
83
 
/*!
84
 
  \brief Specify a scale.
85
 
 
86
 
  Disable autoscaling and define a scale by an interval and a step size
87
 
 
88
 
  \param interval Interval
89
 
  \param stepSize major step size
90
 
  \sa setAutoScale()
91
 
*/
92
 
void QwtAbstractScale::setScale(const QwtDoubleInterval &interval, 
93
 
    double stepSize)
94
 
{
95
 
    setScale(interval.minValue(), interval.maxValue(), stepSize);
96
 
}
97
 
 
98
 
 
99
 
/*!
100
 
  \brief Specify a scale.
101
 
 
102
 
  Disable autoscaling and define a scale by a scale division
103
 
 
104
 
  \param scaleDiv Scale division
105
 
  \sa setAutoScale()
106
 
*/
107
 
void QwtAbstractScale::setScale(const QwtScaleDiv &scaleDiv)
108
 
{
109
 
    d_data->autoScale = false;
110
 
 
111
 
    if (scaleDiv != d_data->scaleDraw->scaleDiv())
112
 
    {
113
 
        d_data->scaleDraw->setScaleDiv(scaleDiv);
114
 
        scaleChange();
115
 
    }
116
 
}
117
 
 
118
 
/*!
119
 
  Recalculate the scale division and update the scale draw.
120
 
 
121
 
  \param vmin Lower limit of the scale interval
122
 
  \param vmax Upper limit of the scale interval
123
 
  \param stepSize Major step size
124
 
 
125
 
  \sa scaleChange()
126
 
*/
127
 
void QwtAbstractScale::rescale(double vmin, double vmax, double stepSize) 
128
 
{
129
 
    const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(
130
 
        vmin, vmax, d_data->maxMajor, d_data->maxMinor, stepSize);
131
 
 
132
 
    if ( scaleDiv != d_data->scaleDraw->scaleDiv() )
133
 
    {
134
 
        d_data->scaleDraw->setTransformation(
135
 
            d_data->scaleEngine->transformation());
136
 
        d_data->scaleDraw->setScaleDiv(scaleDiv);
137
 
        scaleChange();
138
 
    }
139
 
}
140
 
 
141
 
/*!
142
 
  \brief Advise the widget to control the scale range internally.
143
 
 
144
 
  Autoscaling is on by default. 
145
 
  \sa setScale(), autoScale()
146
 
*/
147
 
void QwtAbstractScale::setAutoScale()
148
 
{
149
 
    if (!d_data->autoScale) 
150
 
    {
151
 
        d_data->autoScale = true;
152
 
        scaleChange();
153
 
    }
154
 
}
155
 
 
156
 
/*!
157
 
  \return \c true if autoscaling is enabled
158
 
*/  
159
 
bool QwtAbstractScale::autoScale() const
160
 
{
161
 
    return d_data->autoScale;
162
 
}
163
 
 
164
 
/*!
165
 
  \brief Set the maximum number of major tick intervals.
166
 
 
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
172
 
*/
173
 
void QwtAbstractScale::setScaleMaxMajor(int ticks)
174
 
{
175
 
    if (ticks != d_data->maxMajor)
176
 
    {
177
 
        d_data->maxMajor = ticks;
178
 
        updateScaleDraw();
179
 
    }
180
 
}
181
 
 
182
 
/*!
183
 
  \brief Set the maximum number of minor tick intervals
184
 
 
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.
188
 
  \param ticks
189
 
  \sa QwtAbstractScaleDraw
190
 
*/
191
 
void QwtAbstractScale::setScaleMaxMinor(int ticks)
192
 
{
193
 
    if ( ticks != d_data->maxMinor)
194
 
    {
195
 
        d_data->maxMinor = ticks;
196
 
        updateScaleDraw();
197
 
    }
198
 
}
199
 
 
200
 
/*! 
201
 
  \return Max. number of minor tick intervals 
202
 
  The default value is 3.
203
 
*/
204
 
int QwtAbstractScale::scaleMaxMinor() const 
205
 
{
206
 
    return d_data->maxMinor;
207
 
}
208
 
 
209
 
/*! 
210
 
  \return Max. number of major tick intervals 
211
 
  The default value is 5.
212
 
*/
213
 
int QwtAbstractScale::scaleMaxMajor() const 
214
 
{
215
 
    return d_data->maxMajor;
216
 
}
217
 
 
218
 
/*!
219
 
  \brief Set a scale draw
220
 
 
221
 
  scaleDraw has to be created with new and will be deleted in
222
 
  ~QwtAbstractScale or the next call of setAbstractScaleDraw.
223
 
*/
224
 
void QwtAbstractScale::setAbstractScaleDraw(QwtAbstractScaleDraw *scaleDraw)
225
 
{
226
 
    if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )
227
 
        return;
228
 
 
229
 
    delete d_data->scaleDraw;
230
 
    d_data->scaleDraw = scaleDraw;
231
 
232
 
 
233
 
/*!
234
 
    \return Scale draw
235
 
    \sa setAbstractScaleDraw()
236
 
*/
237
 
QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() 
238
 
{
239
 
    return d_data->scaleDraw;
240
 
}
241
 
 
242
 
/*!
243
 
    \return Scale draw
244
 
    \sa setAbstractScaleDraw()
245
 
*/
246
 
const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
247
 
{
248
 
    return d_data->scaleDraw;
249
 
}
250
 
 
251
 
void QwtAbstractScale::updateScaleDraw()
252
 
{
253
 
    rescale( d_data->scaleDraw->scaleDiv().lBound(), 
254
 
        d_data->scaleDraw->scaleDiv().hBound(), d_data->stepSize);
255
 
}
256
 
 
257
 
/*!
258
 
  \brief Set a scale engine
259
 
 
260
 
  The scale engine is responsible for calculating the scale division,
261
 
  and in case of auto scaling how to align the scale.
262
 
 
263
 
  scaleEngine has to be created with new and will be deleted in
264
 
  ~QwtAbstractScale or the next call of setScaleEngine.
265
 
*/
266
 
void QwtAbstractScale::setScaleEngine(QwtScaleEngine *scaleEngine)
267
 
{
268
 
    if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )
269
 
    {
270
 
        delete d_data->scaleEngine;
271
 
        d_data->scaleEngine = scaleEngine;
272
 
    }
273
 
}
274
 
 
275
 
/*!
276
 
    \return Scale engine
277
 
    \sa setScaleEngine()
278
 
*/
279
 
const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
280
 
{
281
 
    return d_data->scaleEngine;
282
 
}
283
 
 
284
 
/*!
285
 
    \return Scale engine
286
 
    \sa setScaleEngine()
287
 
*/
288
 
QwtScaleEngine *QwtAbstractScale::scaleEngine()
289
 
{
290
 
    return d_data->scaleEngine;
291
 
}
292
 
 
293
 
/*!
294
 
  \brief Notify changed scale
295
 
 
296
 
  Dummy empty implementation, intended to be overloaded by derived classes
297
 
*/
298
 
void QwtAbstractScale::scaleChange()
299
 
{
300
 
}
301
 
 
302
 
/*!
303
 
   \return abstractScaleDraw()->scaleMap()
304
 
*/
305
 
const QwtScaleMap &QwtAbstractScale::scaleMap() const
306
 
{
307
 
    return d_data->scaleDraw->scaleMap();
308
 
}