Loading...
Searching...
No Matches
qwt_scale_map.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_scale_map.h"
#include "qwt_math.h"
#include <qrect.h>
#include <qdebug.h>
QwtScaleMap::QwtScaleMap()
: m_s1( 0.0 )
, m_s2( 1.0 )
, m_p1( 0.0 )
, m_p2( 1.0 )
, m_cnv( 1.0 )
, m_ts1( 0.0 )
, m_transform( NULL )
{
}
QwtScaleMap::QwtScaleMap( const QwtScaleMap& other )
: m_s1( other.m_s1 )
, m_s2( other.m_s2 )
, m_p1( other.m_p1 )
, m_p2( other.m_p2 )
, m_cnv( other.m_cnv )
, m_ts1( other.m_ts1 )
, m_transform( NULL )
{
if ( other.m_transform )
m_transform = other.m_transform->copy();
}
QwtScaleMap::~QwtScaleMap()
{
delete m_transform;
}
QwtScaleMap& QwtScaleMap::operator=( const QwtScaleMap& other )
{
m_s1 = other.m_s1;
m_s2 = other.m_s2;
m_p1 = other.m_p1;
m_p2 = other.m_p2;
m_cnv = other.m_cnv;
m_ts1 = other.m_ts1;
delete m_transform;
m_transform = NULL;
if ( other.m_transform )
m_transform = other.m_transform->copy();
return *this;
}
void QwtScaleMap::setTransformation( QwtTransform* transform )
{
if ( transform != m_transform )
{
delete m_transform;
m_transform = transform;
}
setScaleInterval( m_s1, m_s2 );
}
const QwtTransform* QwtScaleMap::transformation() const
{
return m_transform;
}
void QwtScaleMap::setScaleInterval( double s1, double s2 )
{
m_s1 = s1;
m_s2 = s2;
if ( m_transform )
{
m_s1 = m_transform->bounded( m_s1 );
m_s2 = m_transform->bounded( m_s2 );
}
updateFactor();
}
void QwtScaleMap::setPaintInterval( double p1, double p2 )
{
m_p1 = p1;
m_p2 = p2;
updateFactor();
}
void QwtScaleMap::updateFactor()
{
m_ts1 = m_s1;
double ts2 = m_s2;
if ( m_transform )
{
m_ts1 = m_transform->transform( m_ts1 );
ts2 = m_transform->transform( ts2 );
}
m_cnv = 1.0;
if ( m_ts1 != ts2 )
m_cnv = ( m_p2 - m_p1 ) / ( ts2 - m_ts1 );
}
QRectF QwtScaleMap::transform( const QwtScaleMap& xMap,
const QwtScaleMap& yMap, const QRectF& rect )
{
double x1 = xMap.transform( rect.left() );
double x2 = xMap.transform( rect.right() );
double y1 = yMap.transform( rect.top() );
double y2 = yMap.transform( rect.bottom() );
if ( x2 < x1 )
qSwap( x1, x2 );
if ( y2 < y1 )
qSwap( y1, y2 );
if ( qwtFuzzyCompare( x1, 0.0, x2 - x1 ) == 0 )
x1 = 0.0;
if ( qwtFuzzyCompare( x2, 0.0, x2 - x1 ) == 0 )
x2 = 0.0;
if ( qwtFuzzyCompare( y1, 0.0, y2 - y1 ) == 0 )
y1 = 0.0;
if ( qwtFuzzyCompare( y2, 0.0, y2 - y1 ) == 0 )
y2 = 0.0;
return QRectF( x1, y1, x2 - x1 + 1, y2 - y1 + 1 );
}
QPointF QwtScaleMap::invTransform( const QwtScaleMap& xMap,
const QwtScaleMap& yMap, const QPointF& pos )
{
return QPointF(
xMap.invTransform( pos.x() ),
yMap.invTransform( pos.y() )
);
}
QPointF QwtScaleMap::transform( const QwtScaleMap& xMap,
const QwtScaleMap& yMap, const QPointF& pos )
{
return QPointF(
xMap.transform( pos.x() ),
yMap.transform( pos.y() )
);
}
QRectF QwtScaleMap::invTransform( const QwtScaleMap& xMap,
const QwtScaleMap& yMap, const QRectF& rect )
{
const double x1 = xMap.invTransform( rect.left() );
const double x2 = xMap.invTransform( rect.right() - 1 );
const double y1 = yMap.invTransform( rect.top() );
const double y2 = yMap.invTransform( rect.bottom() - 1 );
const QRectF r( x1, y1, x2 - x1, y2 - y1 );
return r.normalized();
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<( QDebug debug, const QwtScaleMap& map )
{
debug.nospace() << "QwtScaleMap("
<< map.transformation()
<< ", s:" << map.s1() << "->" << map.s2()
<< ", p:" << map.p1() << "->" << map.p2()
<< ")";
return debug.space();
}
#endif
QwtScaleMap
A scale map.
Definition qwt_scale_map.h:27
QwtScaleMap::operator=
QwtScaleMap & operator=(const QwtScaleMap &)
Assignment operator.
Definition qwt_scale_map.cpp:55
QwtScaleMap::p1
double p1() const
Definition qwt_scale_map.h:99
QwtScaleMap::transform
double transform(double s) const
Definition qwt_scale_map.h:137
QwtScaleMap::s1
double s1() const
Definition qwt_scale_map.h:83
QwtScaleMap::s2
double s2() const
Definition qwt_scale_map.h:91
QwtScaleMap::transformation
const QwtTransform * transformation() const
Get the transformation.
Definition qwt_scale_map.cpp:88
QwtScaleMap::QwtScaleMap
QwtScaleMap()
Constructor.
Definition qwt_scale_map.cpp:21
QwtScaleMap::setPaintInterval
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
Definition qwt_scale_map.cpp:119
QwtScaleMap::setScaleInterval
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
Definition qwt_scale_map.cpp:100
QwtScaleMap::invTransform
double invTransform(double p) const
Definition qwt_scale_map.h:154
QwtScaleMap::p2
double p2() const
Definition qwt_scale_map.h:107
QwtScaleMap::setTransformation
void setTransformation(QwtTransform *)
Definition qwt_scale_map.cpp:76
QwtScaleMap::~QwtScaleMap
~QwtScaleMap()
Definition qwt_scale_map.cpp:49
QwtTransform
A transformation between coordinate systems.
Definition qwt_transform.h:36
QwtTransform::copy
virtual QwtTransform * copy() const =0
Virtualized copy operation.
QwtTransform::transform
virtual double transform(double value) const =0
QwtTransform::bounded
virtual double bounded(double value) const
Definition qwt_transform.cpp:33