Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

QwtScaleDiv Class Reference

A class for building scale divisions. More...

#include <qwt_scldiv.h>

List of all members.

Public Member Functions

 QwtScaleDiv ()
int operator== (const QwtScaleDiv &s) const
int operator!= (const QwtScaleDiv &s) const
double lBound () const
double hBound () const
int minCnt () const
int majCnt () const
bool logScale () const
double majMark (int i) const
double minMark (int i) const
double majStep () const
void reset ()
bool rebuild (double lBound, double hBound, int maxMaj, int maxMin, bool log, double step=0.0, bool ascend=TRUE)

Private Member Functions

bool buildLinDiv (int maxMajMark, int maxMinMark, double step=0.0)
bool buildLogDiv (int maxMajMark, int maxMinMark, double step=0.0)

Private Attributes

double d_lBound
double d_hBound
double d_majStep
bool d_log
QwtArray< double > d_majMarks
QwtArray< double > d_minMarks


Detailed Description

A class for building scale divisions.

The QwtScaleDiv class can build linear and logarithmic scale divisions for specified intervals. It uses an adjustable algorithm to generate the major and minor step widths automatically. A scale division has a minimum value, a maximum value, a vector of major marks, and a vector of minor marks.

Warning:
QwtScaleDiv uses implicit sharing for the mark vectors.
Example
To build a logarithmic scale division from 0.01 to 1000 and print out the major and minor marks.
#include "../include/qwt_scldiv.h>
#include <iostream.h>

main()
{
  int i,k;
  QwtScaleDiv sd;

  sd.rebuild(0.01, 100, 10, 10, TRUE, 0.0);

  k=0;
  for (i=0;i<sd.majCnt();i++)
  {
    while(k < sd.minCnt())
    {
      if (sd.minMark(k) < sd.majMark(i))
      {
        cout << " - " << sd.minMark(i) << "\n";
    k++;
      }
      else
        break;
    }
    cout << "-- " << sd.majMark(i) << "\n";
  }
  while(k < sd.minCnt())
  {
    cout << " - " << sd.minMark(i) << "\n";
    k++;
  }
}

Definition at line 69 of file qwt_scldiv.h.


Constructor & Destructor Documentation

QwtScaleDiv::QwtScaleDiv  ) 
 

Construct a QwtScaleDiv instance.

Definition at line 42 of file qwt_scldiv.cpp.

References d_hBound, d_lBound, d_log, and d_majStep.


Member Function Documentation

bool QwtScaleDiv::buildLinDiv int  maxMajSteps,
int  maxMinSteps,
double  step = 0.0
[private]
 

Build a linear scale division in ascending order.

If the 'step' parameter is set to 0.0, this function cal[culates the step width automatically according to the value of 'maxSteps'. MaxSteps must be greater than or equal to 2. It will be guessed if an invalid value is specified.

The maximum possible number of steps is limited to 10000. The maxSteps parameter has no effect if a fixed step width is specified.

Parameters:
maxSteps max. number of step intervals
step -- fixed step width
Returns:
TRUE if array has been successfully resized
Warning:
This function uses the data members d_lBound and d_hBound and assumes that d_hBound > d_lBound.

Definition at line 129 of file qwt_scldiv.cpp.

References border_eps, d_hBound, d_lBound, d_majMarks, d_majStep, d_minMarks, qwtAbs, qwtCeil125(), qwtLimRange(), qwtLinSpace(), qwtMax, qwtMin, and step_eps.

Referenced by buildLogDiv(), and rebuild().

bool QwtScaleDiv::buildLogDiv int  maxMajSteps,
int  maxMinSteps,
double  majStep = 0.0
[private]
 

Build a logarithmic scale division.

Returns:
True if memory has been successfully allocated
Warning:
This function uses the data members d_lBound and d_hBound and assumes that d_hBound > d_lBound.

Definition at line 232 of file qwt_scldiv.cpp.

References border_eps, buildLinDiv(), d_hBound, d_lBound, d_majMarks, d_majStep, d_minMarks, LOG_MAX, LOG_MIN, qwtAbs, qwtCeil125(), qwtLimRange(), qwtLogSpace(), qwtMax, qwtMin, and step_eps.

Referenced by rebuild().

double QwtScaleDiv::hBound  )  const [inline]
 

Returns:
right bound
See also:
QwtScaleDiv::rebuild

Definition at line 86 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::setScale(), QwtScaleIf::setScaleMaxMajor(), and QwtScaleIf::setScaleMaxMinor().

double QwtScaleDiv::lBound  )  const [inline]
 

Returns:
left bound
See also:
QwtScaleDiv::rebuild

Definition at line 81 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::setScale(), QwtScaleIf::setScaleMaxMajor(), and QwtScaleIf::setScaleMaxMinor().

bool QwtScaleDiv::logScale  )  const [inline]
 

Returns:
TRUE id ths scale div is logarithmic
See also:
QwtScaleDiv::rebuild

Definition at line 102 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::draw(), QwtScaleDraw::labelPlacement(), QwtScaleDraw::maxLabelHeight(), QwtScaleDraw::maxLabelWidth(), QwtSlider::rangeChange(), QwtSlider::scaleChange(), QwtScaleDraw::setScale(), QwtScaleIf::setScaleMaxMajor(), and QwtScaleIf::setScaleMaxMinor().

int QwtScaleDiv::majCnt  )  const [inline]
 

Returns:
major mark count
See also:
QwtScaleDiv::rebuild

Definition at line 96 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::draw(), QwtGrid::draw(), QwtScaleDraw::maxLabelHeight(), QwtScaleDraw::maxLabelWidth(), QwtScaleDraw::minBorderDist(), QwtScaleDraw::minHeight(), QwtScaleDraw::minLabelDist(), QwtScaleDraw::minWidth(), QwtScaleIf::setScale(), and QwtPlot::sizeHint().

double QwtScaleDiv::majMark int  i  )  const [inline]
 

Returns:
major mark at position i

Definition at line 105 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::draw(), QwtGrid::draw(), QwtScaleDraw::maxLabelHeight(), QwtScaleDraw::maxLabelWidth(), QwtScaleDraw::minBorderDist(), and QwtScaleDraw::minLabelDist().

double QwtScaleDiv::majStep  )  const [inline]
 

Returns:
major step size
See also:
QwtScaleDiv::rebuild

Definition at line 113 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::draw(), QwtScaleDraw::labelPlacement(), QwtScaleDraw::maxLabelHeight(), and QwtScaleDraw::maxLabelWidth().

int QwtScaleDiv::minCnt  )  const [inline]
 

Returns:
minor mark count
See also:
QwtScaleDiv::rebuild

Definition at line 91 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::draw(), QwtGrid::draw(), QwtScaleDraw::minHeight(), QwtScaleDraw::minWidth(), and QwtScaleIf::setScale().

double QwtScaleDiv::minMark int  i  )  const [inline]
 

Returns:
minor mark at position i

Definition at line 107 of file qwt_scldiv.h.

Referenced by QwtScaleDraw::draw(), and QwtGrid::draw().

int QwtScaleDiv::operator!= const QwtScaleDiv s  )  const
 

Inequality.

Returns:
TRUE if this instance is not equal to s

Definition at line 439 of file qwt_scldiv.cpp.

int QwtScaleDiv::operator== const QwtScaleDiv s  )  const
 

Equality operator.

Returns:
TRUE if this instance is equal to s

Definition at line 425 of file qwt_scldiv.cpp.

References d_hBound, d_lBound, d_log, d_majMarks, d_majStep, and d_minMarks.

bool QwtScaleDiv::rebuild double  x1,
double  x2,
int  maxMajSteps,
int  maxMinSteps,
bool  log,
double  step = 0.0,
bool  ascend = TRUE
 

Build a scale width major and minor divisions If no fixed step width is specified or if it is set to 0, the major step width will be calculated automatically according to the the value of maxMajSteps. The maxMajSteps parameter has no effect if a fixed step size is specified. The minor step width is always calculated automatically.

If the step width is to be calculated automatically, the algorithm tries to find reasonable values fitting into the scheme {1,2,5}*10^n with an integer number n for linear scales.

For logarithmic scales, there are three different cases

  1. If the major step width is one decade, the minor marks will fit into one of the schemes {1,2,...9}, {2,4,6,8}, {2,5} or {5}, depending on the maxMinSteps parameter.
  2. If the major step size spans more than one decade, the minor step size will be {1,2,5}*10^n decades with a natural number n.
  3. If the whole range is less than one decade, a linear scale division will be built.

Parameters:
x1 first boundary value
x2 second boundary value
maxMajSteps max. number of major step intervals
maxMinSteps max. number of minor step intervals
log logarithmic division (TRUE/FALSE)
step fixed major step width. Defaults to 0.0.
ascend if TRUE, sort in ascending order from min(x1, x2) to max(x1, x2). If FALSE, sort in the direction from x1 to x2. Defaults to TRUE.
Returns:
True if the arrays have been allocated successfully.
Warning:
For logarithmic scales, the step width is measured in decades.

Definition at line 86 of file qwt_scldiv.cpp.

References buildLinDiv(), buildLogDiv(), d_hBound, d_lBound, d_log, d_majMarks, d_minMarks, qwtMax, qwtMin, and qwtTwistArray().

Referenced by QwtAutoScale::build(), QwtAutoScale::buildLinScale(), QwtAutoScale::buildLogScale(), and QwtScaleDraw::setScale().

void QwtScaleDiv::reset  ) 
 

Detach the shared data and set everything to zero.

Definition at line 445 of file qwt_scldiv.cpp.

References d_hBound, d_lBound, d_log, d_majMarks, d_majStep, and d_minMarks.

Referenced by QwtAutoScale::reset().


Member Data Documentation

double QwtScaleDiv::d_hBound [private]
 

Definition at line 124 of file qwt_scldiv.h.

Referenced by buildLinDiv(), buildLogDiv(), operator==(), QwtScaleDiv(), rebuild(), and reset().

double QwtScaleDiv::d_lBound [private]
 

Definition at line 123 of file qwt_scldiv.h.

Referenced by buildLinDiv(), buildLogDiv(), operator==(), QwtScaleDiv(), rebuild(), and reset().

bool QwtScaleDiv::d_log [private]
 

Definition at line 126 of file qwt_scldiv.h.

Referenced by operator==(), QwtScaleDiv(), rebuild(), and reset().

QwtArray<double> QwtScaleDiv::d_majMarks [private]
 

Definition at line 128 of file qwt_scldiv.h.

Referenced by buildLinDiv(), buildLogDiv(), operator==(), rebuild(), and reset().

double QwtScaleDiv::d_majStep [private]
 

Definition at line 125 of file qwt_scldiv.h.

Referenced by buildLinDiv(), buildLogDiv(), operator==(), QwtScaleDiv(), and reset().

QwtArray<double> QwtScaleDiv::d_minMarks [private]
 

Definition at line 129 of file qwt_scldiv.h.

Referenced by buildLinDiv(), buildLogDiv(), operator==(), rebuild(), and reset().


The documentation for this class was generated from the following files:
Generated on Fri Nov 7 14:11:49 2003 for Qwt Developer's Guide by doxygen 1.3.2