Public Member Functions | Protected Member Functions

PlotDateTimeScaleEngine Class Reference

#include <PlotDateTimeScaleEngine.h>

Inheritance diagram for PlotDateTimeScaleEngine:
Inheritance graph
[legend]
Collaboration diagram for PlotDateTimeScaleEngine:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PlotDateTimeScaleEngine ()
virtual ~PlotDateTimeScaleEngine ()
virtual void autoScale (int maxSteps, double &x1, double &x2, double &stepSize) const
virtual double divideInterval (double intervalSize, int numSteps) const
virtual QwtScaleDiv divideScale (double x1, double x2, int numMajorSteps, int numMinorSteps, double stepSize=0.0) const
virtual QwtScaleTransformationtransformation () const

Protected Member Functions

QwtDoubleInterval align (const QwtDoubleInterval &, double stepSize) const

Constructor & Destructor Documentation

PlotDateTimeScaleEngine::PlotDateTimeScaleEngine (  ) 

{
  //qDebug( "PlotDateTimeScaleEngine::PlotDateTimeScaleEngine" );
}

PlotDateTimeScaleEngine::~PlotDateTimeScaleEngine (  )  [virtual]

{
  //qDebug( "PlotDateTimeScaleEngine::~PlotDateTimeScaleEngine" );
}


Member Function Documentation

QwtDoubleInterval PlotDateTimeScaleEngine::align ( const QwtDoubleInterval interval,
double  stepSize 
) const [protected]

Referenced by autoScale().

{
  //qDebug( "PlotDateTimeScaleEngine::align" );

  const double x1 = QwtScaleArithmetic::floorEps( interval.minValue(), stepSize );
  const double x2 = QwtScaleArithmetic::ceilEps( interval.maxValue(), stepSize );

  return QwtDoubleInterval( x1, x2 );
}

void PlotDateTimeScaleEngine::autoScale ( int  maxSteps,
double &  x1,
double &  x2,
double &  stepSize 
) const [virtual]

Reimplemented from QwtScaleEngine.

{
  //qDebug( "PlotDateTimeScaleEngine::autoScale" );

  QwtDoubleInterval interval( x1, x2 );
  interval = interval.normalized();

  interval.setMinValue( interval.minValue() - lowerMargin() );
  interval.setMaxValue( interval.maxValue() + upperMargin() );

  if ( testAttribute( QwtScaleEngine::Symmetric ) )
    interval = interval.symmetrize( reference() );

  if ( testAttribute( QwtScaleEngine::IncludeReference ) )
    interval = interval.extend( reference() );

  if ( interval.width() == 0.0 )
    interval = buildInterval( interval.minValue() );

  stepSize = divideInterval( interval.width(), qwtMax( maxNumSteps, 1 ) );

  if ( !testAttribute( QwtScaleEngine::Floating ) )
    interval = align( interval, stepSize );

  x1 = interval.minValue();
  x2 = interval.maxValue();

  if ( testAttribute( QwtScaleEngine::Inverted ) )
  {
    qSwap( x1, x2 );
    stepSize = -stepSize;
  }
}

double PlotDateTimeScaleEngine::divideInterval ( double  intervalSize,
int  numSteps 
) const [virtual]

Reimplemented from QwtScaleEngine.

Referenced by autoScale(), and divideScale().

{
  //qDebug( "PlotDateTimeScaleEngine::divideInterval" );

  // Only this function was changed as compared to the QwtLinearScaleEngine

  if ( numSteps <= 0 )
    return 0.0;

  double x = QwtScaleArithmetic::divideEps( intervalSize, numSteps );

  if ( x == 0.0 )
    return 0.0;

  const double sign = ( x > 0 ) ? 1.0 : -1.0;
  // log_b( x ) = log_n( x ) / log_n( b )
  const double lx = log( fabs( x ) ) / log( 60.0 );
  const double p10 = floor( lx );

  double fr = pow( 60.0, lx - p10 );

  if ( fr <= 1.0 )
    fr = 1.0;
  else if ( fr <= 2.0 )
    fr = 2.0;
  else if ( fr <= 5.0 )
    fr = 5.0;
  else if ( fr <= 10.0 )
    fr = 10.0;
  else if ( fr <= 20.0 )
    fr = 20.0;
  else if ( fr <= 30.0 )
    fr = 30.0;
  else
    fr = 60.0;

  return sign * fr * pow( 60.0, p10 );
}

QwtScaleDiv PlotDateTimeScaleEngine::divideScale ( double  x1,
double  x2,
int  numMajorSteps,
int  numMinorSteps,
double  stepSize = 0.0 
) const [virtual]

Reimplemented from QwtScaleEngine.

{
  //qDebug( "PlotDateTimeScaleEngine::divideScale" );

  QwtDoubleInterval interval = QwtDoubleInterval( x1, x2 ).normalized();
  if ( interval.width() <= 0 )
    return QwtScaleDiv();

  stepSize = qwtAbs( stepSize );
  if ( stepSize == 0.0 )
  {
    if ( maxMajSteps < 1 )
      maxMajSteps = 1;

    stepSize = divideInterval( interval.width(), maxMajSteps );
  }

  QwtScaleDiv scaleDiv;

  if ( stepSize != 0.0 )
  {
    QwtValueList ticks[ QwtScaleDiv::NTickTypes ];
    buildTicks( interval, stepSize, maxMinSteps, ticks );

    scaleDiv = QwtScaleDiv( interval, ticks );
  }

  if ( x1 > x2 )
    scaleDiv.invert();

  return scaleDiv;
}

QwtScaleTransformation * PlotDateTimeScaleEngine::transformation (  )  const [virtual]

Reimplemented from QwtScaleEngine.

{

  return new QwtScaleTransformation( QwtScaleTransformation::Linear );
}


The documentation for this class was generated from the following files: