Loading...
Searching...
No Matches
qwt_abstract_scale.cpp
/******************************************************************************
* 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"
#include <qcoreevent.h>
class QwtAbstractScale::PrivateData
{
public:
PrivateData():
maxMajor( 5 ),
maxMinor( 3 ),
stepSize( 0.0 )
{
scaleEngine = new QwtLinearScaleEngine();
scaleDraw = new QwtScaleDraw();
}
~PrivateData()
{
delete scaleEngine;
delete scaleDraw;
}
QwtScaleEngine* scaleEngine;
QwtAbstractScaleDraw* scaleDraw;
int maxMajor;
int maxMinor;
double stepSize;
};
QwtAbstractScale::QwtAbstractScale( QWidget* parent )
: QWidget( parent )
{
m_data = new PrivateData;
rescale( 0.0, 100.0, m_data->stepSize );
}
QwtAbstractScale::~QwtAbstractScale()
{
delete m_data;
}
void QwtAbstractScale::setLowerBound( double value )
{
setScale( value, upperBound() );
}
double QwtAbstractScale::lowerBound() const
{
return m_data->scaleDraw->scaleDiv().lowerBound();
}
void QwtAbstractScale::setUpperBound( double value )
{
setScale( lowerBound(), value );
}
double QwtAbstractScale::upperBound() const
{
return m_data->scaleDraw->scaleDiv().upperBound();
}
void QwtAbstractScale::setScale( double lowerBound, double upperBound )
{
rescale( lowerBound, upperBound, m_data->stepSize );
}
void QwtAbstractScale::setScale( const QwtInterval& interval )
{
setScale( interval.minValue(), interval.maxValue() );
}
void QwtAbstractScale::setScale( const QwtScaleDiv& scaleDiv )
{
if ( scaleDiv != m_data->scaleDraw->scaleDiv() )
{
#if 1
if ( m_data->scaleEngine )
{
m_data->scaleDraw->setTransformation(
m_data->scaleEngine->transformation() );
}
#endif
m_data->scaleDraw->setScaleDiv( scaleDiv );
scaleChange();
}
}
void QwtAbstractScale::setScaleMaxMajor( int ticks )
{
if ( ticks != m_data->maxMajor )
{
m_data->maxMajor = ticks;
updateScaleDraw();
}
}
int QwtAbstractScale::scaleMaxMajor() const
{
return m_data->maxMajor;
}
void QwtAbstractScale::setScaleMaxMinor( int ticks )
{
if ( ticks != m_data->maxMinor )
{
m_data->maxMinor = ticks;
updateScaleDraw();
}
}
int QwtAbstractScale::scaleMaxMinor() const
{
return m_data->maxMinor;
}
void QwtAbstractScale::setScaleStepSize( double stepSize )
{
if ( stepSize != m_data->stepSize )
{
m_data->stepSize = stepSize;
updateScaleDraw();
}
}
double QwtAbstractScale::scaleStepSize() const
{
return m_data->stepSize;
}
void QwtAbstractScale::setAbstractScaleDraw( QwtAbstractScaleDraw* scaleDraw )
{
if ( scaleDraw == NULL || scaleDraw == m_data->scaleDraw )
return;
if ( m_data->scaleDraw != NULL )
scaleDraw->setScaleDiv( m_data->scaleDraw->scaleDiv() );
delete m_data->scaleDraw;
m_data->scaleDraw = scaleDraw;
}
QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw()
{
return m_data->scaleDraw;
}
const QwtAbstractScaleDraw* QwtAbstractScale::abstractScaleDraw() const
{
return m_data->scaleDraw;
}
void QwtAbstractScale::setScaleEngine( QwtScaleEngine* scaleEngine )
{
if ( scaleEngine != NULL && scaleEngine != m_data->scaleEngine )
{
delete m_data->scaleEngine;
m_data->scaleEngine = scaleEngine;
}
}
const QwtScaleEngine* QwtAbstractScale::scaleEngine() const
{
return m_data->scaleEngine;
}
QwtScaleEngine* QwtAbstractScale::scaleEngine()
{
return m_data->scaleEngine;
}
const QwtScaleDiv& QwtAbstractScale::scaleDiv() const
{
return m_data->scaleDraw->scaleDiv();
}
const QwtScaleMap& QwtAbstractScale::scaleMap() const
{
return m_data->scaleDraw->scaleMap();
}
int QwtAbstractScale::transform( double value ) const
{
return qRound( m_data->scaleDraw->scaleMap().transform( value ) );
}
double QwtAbstractScale::invTransform( int value ) const
{
return m_data->scaleDraw->scaleMap().invTransform( value );
}
bool QwtAbstractScale::isInverted() const
{
return m_data->scaleDraw->scaleMap().isInverting();
}
double QwtAbstractScale::minimum() const
{
return qMin( m_data->scaleDraw->scaleDiv().lowerBound(),
m_data->scaleDraw->scaleDiv().upperBound() );
}
double QwtAbstractScale::maximum() const
{
return qMax( m_data->scaleDraw->scaleDiv().lowerBound(),
m_data->scaleDraw->scaleDiv().upperBound() );
}
void QwtAbstractScale::scaleChange()
{
}
void QwtAbstractScale::rescale(
double lowerBound, double upperBound, double stepSize )
{
const QwtScaleDiv scaleDiv = m_data->scaleEngine->divideScale(
lowerBound, upperBound, m_data->maxMajor, m_data->maxMinor, stepSize );
if ( scaleDiv != m_data->scaleDraw->scaleDiv() )
{
#if 1
m_data->scaleDraw->setTransformation(
m_data->scaleEngine->transformation() );
#endif
m_data->scaleDraw->setScaleDiv( scaleDiv );
scaleChange();
}
}
void QwtAbstractScale::changeEvent( QEvent* event )
{
if ( event->type() == QEvent::LocaleChange )
{
m_data->scaleDraw->invalidateCache();
}
QWidget::changeEvent( event );
}
void QwtAbstractScale::updateScaleDraw()
{
rescale( m_data->scaleDraw->scaleDiv().lowerBound(),
m_data->scaleDraw->scaleDiv().upperBound(), m_data->stepSize );
}
#include "moc_qwt_abstract_scale.cpp"
QwtAbstractScaleDraw
A abstract base class for drawing scales.
Definition qwt_abstract_scale_draw.h:32
QwtAbstractScaleDraw::setScaleDiv
void setScaleDiv(const QwtScaleDiv &)
Definition qwt_abstract_scale_draw.cpp:104
QwtAbstractScaleDraw::scaleMap
const QwtScaleMap & scaleMap() const
Definition qwt_abstract_scale_draw.cpp:121
QwtAbstractScaleDraw::invalidateCache
void invalidateCache()
Definition qwt_abstract_scale_draw.cpp:417
QwtAbstractScaleDraw::setTransformation
void setTransformation(QwtTransform *)
Definition qwt_abstract_scale_draw.cpp:115
QwtAbstractScaleDraw::scaleDiv
const QwtScaleDiv & scaleDiv() const
Definition qwt_abstract_scale_draw.cpp:133
QwtAbstractScale::scaleChange
virtual void scaleChange()
Notify changed scale.
Definition qwt_abstract_scale.cpp:416
QwtAbstractScale::scaleMap
const QwtScaleMap & scaleMap() const
Definition qwt_abstract_scale.cpp:357
QwtAbstractScale::setUpperBound
void setUpperBound(double value)
Definition qwt_abstract_scale.cpp:102
QwtAbstractScale::setScaleMaxMajor
void setScaleMaxMajor(int ticks)
Set the maximum number of major tick intervals.
Definition qwt_abstract_scale.cpp:189
QwtAbstractScale::lowerBound
double lowerBound() const
Definition qwt_abstract_scale.cpp:88
QwtAbstractScale::abstractScaleDraw
const QwtAbstractScaleDraw * abstractScaleDraw() const
Definition qwt_abstract_scale.cpp:302
QwtAbstractScale::invTransform
double invTransform(int) const
Definition qwt_abstract_scale.cpp:381
QwtAbstractScale::scaleEngine
const QwtScaleEngine * scaleEngine() const
Definition qwt_abstract_scale.cpp:329
QwtAbstractScale::rescale
void rescale(double lowerBound, double upperBound, double stepSize)
Definition qwt_abstract_scale.cpp:429
QwtAbstractScale::setScaleMaxMinor
void setScaleMaxMinor(int ticks)
Set the maximum number of minor tick intervals.
Definition qwt_abstract_scale.cpp:219
QwtAbstractScale::scaleDiv
const QwtScaleDiv & scaleDiv() const
Definition qwt_abstract_scale.cpp:349
QwtAbstractScale::scaleStepSize
double scaleStepSize() const
Definition qwt_abstract_scale.cpp:264
QwtAbstractScale::transform
int transform(double) const
Definition qwt_abstract_scale.cpp:369
QwtAbstractScale::~QwtAbstractScale
virtual ~QwtAbstractScale()
Destructor.
Definition qwt_abstract_scale.cpp:65
QwtAbstractScale::minimum
double minimum() const
Definition qwt_abstract_scale.cpp:399
QwtAbstractScale::isInverted
bool isInverted() const
Definition qwt_abstract_scale.cpp:390
QwtAbstractScale::setAbstractScaleDraw
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
Definition qwt_abstract_scale.cpp:277
QwtAbstractScale::scaleMaxMajor
int scaleMaxMajor() const
Definition qwt_abstract_scale.cpp:202
QwtAbstractScale::QwtAbstractScale
QwtAbstractScale(QWidget *parent=NULL)
Definition qwt_abstract_scale.cpp:57
QwtAbstractScale::setScaleEngine
void setScaleEngine(QwtScaleEngine *)
Set a scale engine.
Definition qwt_abstract_scale.cpp:316
QwtAbstractScale::setLowerBound
void setLowerBound(double value)
Definition qwt_abstract_scale.cpp:79
QwtAbstractScale::setScaleStepSize
void setScaleStepSize(double stepSize)
Set the step size used for calculating a scale division.
Definition qwt_abstract_scale.cpp:251
QwtAbstractScale::maximum
double maximum() const
Definition qwt_abstract_scale.cpp:409
QwtAbstractScale::updateScaleDraw
void updateScaleDraw()
Definition qwt_abstract_scale.cpp:466
QwtAbstractScale::upperBound
double upperBound() const
Definition qwt_abstract_scale.cpp:111
QwtAbstractScale::scaleMaxMinor
int scaleMaxMinor() const
Definition qwt_abstract_scale.cpp:232
QwtAbstractScale::setScale
void setScale(double lowerBound, double upperBound)
Specify a scale.
Definition qwt_abstract_scale.cpp:130
QwtAbstractScale::changeEvent
virtual void changeEvent(QEvent *) override
Definition qwt_abstract_scale.cpp:453
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition qwt_interval.h:192
QwtInterval::maxValue
double maxValue() const
Definition qwt_interval.h:198
QwtLinearScaleEngine
A scale engine for linear scales.
Definition qwt_scale_engine.h:152
QwtScaleDiv
A class representing a scale division.
Definition qwt_scale_div.h:34
QwtScaleDiv::lowerBound
double lowerBound() const
Definition qwt_scale_div.cpp:131
QwtScaleDiv::upperBound
double upperBound() const
Definition qwt_scale_div.cpp:151
QwtScaleDraw
A class for drawing scales.
Definition qwt_scale_draw.h:36
QwtScaleEngine
Base class for scale engines.
Definition qwt_scale_engine.h:46
QwtScaleEngine::transformation
QwtTransform * transformation() const
Definition qwt_scale_engine.cpp:265
QwtScaleEngine::divideScale
virtual QwtScaleDiv divideScale(double x1, double x2, int maxMajorSteps, int maxMinorSteps, double stepSize=0.0) const =0
Calculate a scale division.
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::isInverting
bool isInverting() const
Definition qwt_scale_map.h:164
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtScaleMap::invTransform
double invTransform(double p) const
Definition qwt_scale_map.h:154