~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2009-04-12 23:25:58 UTC
  • mfrom: (1.1.4 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090412232558-3bl06x785yr8xm8u
Tags: 5.1.2-1
* New upstream release.
* Bump compat/debhelper to 7.
* Bump Standards-Version to 3.8.1. No changes needed.
* Invert Maintainers and Uploaders field.
* Fix lintian warnings:
  - dh_clean _k deprecated.
  - missing dependency on libc.

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
 
    if ( d_data->scaleDraw != NULL )
230
 
        scaleDraw->setScaleDiv(d_data->scaleDraw->scaleDiv());
231
 
 
232
 
    delete d_data->scaleDraw;
233
 
    d_data->scaleDraw = scaleDraw;
234
 
235
 
 
236
 
/*!
237
 
    \return Scale draw
238
 
    \sa setAbstractScaleDraw()
239
 
*/
240
 
QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() 
241
 
{
242
 
    return d_data->scaleDraw;
243
 
}
244
 
 
245
 
/*!
246
 
    \return Scale draw
247
 
    \sa setAbstractScaleDraw()
248
 
*/
249
 
const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
250
 
{
251
 
    return d_data->scaleDraw;
252
 
}
253
 
 
254
 
void QwtAbstractScale::updateScaleDraw()
255
 
{
256
 
    rescale( d_data->scaleDraw->scaleDiv().lBound(), 
257
 
        d_data->scaleDraw->scaleDiv().hBound(), d_data->stepSize);
258
 
}
259
 
 
260
 
/*!
261
 
  \brief Set a scale engine
262
 
 
263
 
  The scale engine is responsible for calculating the scale division,
264
 
  and in case of auto scaling how to align the scale.
265
 
 
266
 
  scaleEngine has to be created with new and will be deleted in
267
 
  ~QwtAbstractScale or the next call of setScaleEngine.
268
 
*/
269
 
void QwtAbstractScale::setScaleEngine(QwtScaleEngine *scaleEngine)
270
 
{
271
 
    if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine )
272
 
    {
273
 
        delete d_data->scaleEngine;
274
 
        d_data->scaleEngine = scaleEngine;
275
 
    }
276
 
}
277
 
 
278
 
/*!
279
 
    \return Scale engine
280
 
    \sa setScaleEngine()
281
 
*/
282
 
const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
283
 
{
284
 
    return d_data->scaleEngine;
285
 
}
286
 
 
287
 
/*!
288
 
    \return Scale engine
289
 
    \sa setScaleEngine()
290
 
*/
291
 
QwtScaleEngine *QwtAbstractScale::scaleEngine()
292
 
{
293
 
    return d_data->scaleEngine;
294
 
}
295
 
 
296
 
/*!
297
 
  \brief Notify changed scale
298
 
 
299
 
  Dummy empty implementation, intended to be overloaded by derived classes
300
 
*/
301
 
void QwtAbstractScale::scaleChange()
302
 
{
303
 
}
304
 
 
305
 
/*!
306
 
   \return abstractScaleDraw()->scaleMap()
307
 
*/
308
 
const QwtScaleMap &QwtAbstractScale::scaleMap() const
309
 
{
310
 
    return d_data->scaleDraw->scaleMap();
311
 
}