You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
304 lines
6.8 KiB
304 lines
6.8 KiB
15 years ago
|
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
||
|
* Qwt Widget Library
|
||
|
* Copyright (C) 1997 Josef Wilgen
|
||
|
* Copyright (C) 2002 Uwe Rathmann
|
||
14 years ago
|
*
|
||
15 years ago
|
* 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_scale_engine.h"
|
||
|
#include "qwt_scale_draw.h"
|
||
|
#include "qwt_scale_div.h"
|
||
|
#include "qwt_scale_map.h"
|
||
|
#include "qwt_double_interval.h"
|
||
|
#include "qwt_abstract_scale.h"
|
||
|
|
||
|
class QwtAbstractScale::PrivateData
|
||
|
{
|
||
|
public:
|
||
|
PrivateData():
|
||
|
maxMajor(5),
|
||
|
maxMinor(3),
|
||
|
stepSize(0.0),
|
||
14 years ago
|
autoScale(true) {
|
||
15 years ago
|
scaleEngine = new QwtLinearScaleEngine;
|
||
|
scaleDraw = new QwtScaleDraw();
|
||
|
}
|
||
|
|
||
14 years ago
|
~PrivateData() {
|
||
15 years ago
|
delete scaleEngine;
|
||
|
delete scaleDraw;
|
||
|
}
|
||
|
|
||
|
QwtScaleEngine *scaleEngine;
|
||
|
QwtAbstractScaleDraw *scaleDraw;
|
||
|
|
||
|
int maxMajor;
|
||
|
int maxMinor;
|
||
|
double stepSize;
|
||
|
|
||
|
bool autoScale;
|
||
|
};
|
||
|
|
||
|
/*!
|
||
|
Constructor
|
||
|
|
||
14 years ago
|
Creates a default QwtScaleDraw and a QwtLinearScaleEngine.
|
||
15 years ago
|
Autoscaling is enabled, and the stepSize is initialized by 0.0.
|
||
|
*/
|
||
14 years ago
|
|
||
15 years ago
|
QwtAbstractScale::QwtAbstractScale()
|
||
|
{
|
||
|
d_data = new PrivateData;
|
||
|
rescale(0.0, 100.0);
|
||
|
}
|
||
|
|
||
|
//! Destructor
|
||
|
QwtAbstractScale::~QwtAbstractScale()
|
||
|
{
|
||
|
delete d_data;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\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
|
||
|
\sa setAutoScale()
|
||
|
*/
|
||
|
void QwtAbstractScale::setScale(double vmin, double vmax, double stepSize)
|
||
|
{
|
||
|
d_data->autoScale = false;
|
||
|
d_data->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
|
||
|
\sa setAutoScale()
|
||
|
*/
|
||
14 years ago
|
void QwtAbstractScale::setScale(const QwtDoubleInterval &interval,
|
||
|
double stepSize)
|
||
15 years ago
|
{
|
||
|
setScale(interval.minValue(), interval.maxValue(), stepSize);
|
||
|
}
|
||
|
|
||
|
|
||
|
/*!
|
||
|
\brief Specify a scale.
|
||
|
|
||
|
Disable autoscaling and define a scale by a scale division
|
||
|
|
||
|
\param scaleDiv Scale division
|
||
|
\sa setAutoScale()
|
||
|
*/
|
||
|
void QwtAbstractScale::setScale(const QwtScaleDiv &scaleDiv)
|
||
|
{
|
||
|
d_data->autoScale = false;
|
||
|
|
||
14 years ago
|
if (scaleDiv != d_data->scaleDraw->scaleDiv()) {
|
||
15 years ago
|
d_data->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()
|
||
|
*/
|
||
14 years ago
|
void QwtAbstractScale::rescale(double vmin, double vmax, double stepSize)
|
||
15 years ago
|
{
|
||
|
const QwtScaleDiv scaleDiv = d_data->scaleEngine->divideScale(
|
||
14 years ago
|
vmin, vmax, d_data->maxMajor, d_data->maxMinor, stepSize);
|
||
15 years ago
|
|
||
14 years ago
|
if ( scaleDiv != d_data->scaleDraw->scaleDiv() ) {
|
||
15 years ago
|
d_data->scaleDraw->setTransformation(
|
||
|
d_data->scaleEngine->transformation());
|
||
|
d_data->scaleDraw->setScaleDiv(scaleDiv);
|
||
|
scaleChange();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\brief Advise the widget to control the scale range internally.
|
||
|
|
||
14 years ago
|
Autoscaling is on by default.
|
||
15 years ago
|
\sa setScale(), autoScale()
|
||
|
*/
|
||
|
void QwtAbstractScale::setAutoScale()
|
||
|
{
|
||
14 years ago
|
if (!d_data->autoScale) {
|
||
15 years ago
|
d_data->autoScale = true;
|
||
|
scaleChange();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\return \c true if autoscaling is enabled
|
||
14 years ago
|
*/
|
||
15 years ago
|
bool QwtAbstractScale::autoScale() const
|
||
|
{
|
||
|
return d_data->autoScale;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\brief Set the maximum number of major tick intervals.
|
||
|
|
||
|
The scale's major ticks are calculated automatically such that
|
||
|
the number of major intervals does not exceed ticks.
|
||
|
The default value is 5.
|
||
|
\param ticks maximal number of major ticks.
|
||
|
\sa QwtAbstractScaleDraw
|
||
|
*/
|
||
|
void QwtAbstractScale::setScaleMaxMajor(int ticks)
|
||
|
{
|
||
14 years ago
|
if (ticks != d_data->maxMajor) {
|
||
15 years ago
|
d_data->maxMajor = ticks;
|
||
|
updateScaleDraw();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\brief Set the maximum number of minor tick intervals
|
||
|
|
||
|
The scale's minor ticks are calculated automatically such that
|
||
|
the number of minor intervals does not exceed ticks.
|
||
|
The default value is 3.
|
||
|
\param ticks
|
||
|
\sa QwtAbstractScaleDraw
|
||
|
*/
|
||
|
void QwtAbstractScale::setScaleMaxMinor(int ticks)
|
||
|
{
|
||
14 years ago
|
if ( ticks != d_data->maxMinor) {
|
||
15 years ago
|
d_data->maxMinor = ticks;
|
||
|
updateScaleDraw();
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
/*!
|
||
|
\return Max. number of minor tick intervals
|
||
15 years ago
|
The default value is 3.
|
||
|
*/
|
||
14 years ago
|
int QwtAbstractScale::scaleMaxMinor() const
|
||
15 years ago
|
{
|
||
|
return d_data->maxMinor;
|
||
|
}
|
||
|
|
||
14 years ago
|
/*!
|
||
|
\return Max. number of major tick intervals
|
||
15 years ago
|
The default value is 5.
|
||
|
*/
|
||
14 years ago
|
int QwtAbstractScale::scaleMaxMajor() const
|
||
15 years ago
|
{
|
||
|
return d_data->maxMajor;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\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(QwtAbstractScaleDraw *scaleDraw)
|
||
|
{
|
||
|
if ( scaleDraw == NULL || scaleDraw == d_data->scaleDraw )
|
||
|
return;
|
||
|
|
||
|
if ( d_data->scaleDraw != NULL )
|
||
|
scaleDraw->setScaleDiv(d_data->scaleDraw->scaleDiv());
|
||
|
|
||
|
delete d_data->scaleDraw;
|
||
|
d_data->scaleDraw = scaleDraw;
|
||
14 years ago
|
}
|
||
15 years ago
|
|
||
|
/*!
|
||
|
\return Scale draw
|
||
|
\sa setAbstractScaleDraw()
|
||
|
*/
|
||
14 years ago
|
QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw()
|
||
15 years ago
|
{
|
||
|
return d_data->scaleDraw;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\return Scale draw
|
||
|
\sa setAbstractScaleDraw()
|
||
|
*/
|
||
|
const QwtAbstractScaleDraw *QwtAbstractScale::abstractScaleDraw() const
|
||
|
{
|
||
|
return d_data->scaleDraw;
|
||
|
}
|
||
|
|
||
|
void QwtAbstractScale::updateScaleDraw()
|
||
|
{
|
||
14 years ago
|
rescale( d_data->scaleDraw->scaleDiv().lBound(),
|
||
|
d_data->scaleDraw->scaleDiv().hBound(), d_data->stepSize);
|
||
15 years ago
|
}
|
||
|
|
||
|
/*!
|
||
|
\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)
|
||
|
{
|
||
14 years ago
|
if ( scaleEngine != NULL && scaleEngine != d_data->scaleEngine ) {
|
||
15 years ago
|
delete d_data->scaleEngine;
|
||
|
d_data->scaleEngine = scaleEngine;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\return Scale engine
|
||
|
\sa setScaleEngine()
|
||
|
*/
|
||
|
const QwtScaleEngine *QwtAbstractScale::scaleEngine() const
|
||
|
{
|
||
|
return d_data->scaleEngine;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\return Scale engine
|
||
|
\sa setScaleEngine()
|
||
|
*/
|
||
|
QwtScaleEngine *QwtAbstractScale::scaleEngine()
|
||
|
{
|
||
|
return d_data->scaleEngine;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\brief Notify changed scale
|
||
|
|
||
|
Dummy empty implementation, intended to be overloaded by derived classes
|
||
|
*/
|
||
|
void QwtAbstractScale::scaleChange()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
\return abstractScaleDraw()->scaleMap()
|
||
|
*/
|
||
|
const QwtScaleMap &QwtAbstractScale::scaleMap() const
|
||
|
{
|
||
|
return d_data->scaleDraw->scaleMap();
|
||
|
}
|