1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
10
#include "qwt_scale_div.h"
12
#include "qwt_double_interval.h"
14
//! Construct an invalid QwtScaleDiv instance.
15
QwtScaleDiv::QwtScaleDiv():
23
Construct QwtScaleDiv instance.
25
\param interval Interval
26
\param ticks List of major, medium and minor ticks
28
QwtScaleDiv::QwtScaleDiv(
29
const QwtDoubleInterval &interval,
30
QwtValueList ticks[NTickTypes]):
31
d_lBound(interval.minValue()),
32
d_hBound(interval.maxValue()),
35
for ( int i = 0; i < NTickTypes; i++ )
36
d_ticks[i] = ticks[i];
40
Construct QwtScaleDiv instance.
42
\param lBound First interval limit
43
\param hBound Second interval limit
44
\param ticks List of major, medium and minor ticks
46
QwtScaleDiv::QwtScaleDiv(
47
double lBound, double hBound,
48
QwtValueList ticks[NTickTypes]):
53
for ( int i = 0; i < NTickTypes; i++ )
54
d_ticks[i] = ticks[i];
58
\brief Equality operator
59
\return true if this instance is equal to other
61
int QwtScaleDiv::operator==(const QwtScaleDiv &other) const
63
if ( d_lBound != other.d_lBound ||
64
d_hBound != other.d_hBound ||
65
d_isValid != other.d_isValid )
70
for ( int i = 0; i < NTickTypes; i++ )
72
if ( d_ticks[i] != other.d_ticks[i] )
81
\return true if this instance is not equal to s
83
int QwtScaleDiv::operator!=(const QwtScaleDiv &s) const
85
return (!(*this == s));
88
//! Invalidate the scale division
89
void QwtScaleDiv::invalidate()
94
for ( int i = 0; i < NTickTypes; i++ )
97
d_lBound = d_hBound = 0;
100
//! Check if the scale division is valid
101
bool QwtScaleDiv::isValid() const
106
bool QwtScaleDiv::contains(double v) const
111
const double min = qwtMin(d_lBound, d_hBound);
112
const double max = qwtMax(d_lBound, d_hBound);
114
return v >= min && v <= max;
117
//! Invert the scale divison
118
void QwtScaleDiv::invert()
120
qSwap(d_lBound, d_hBound);
122
for ( int i = 0; i < NTickTypes; i++ )
124
QwtValueList& ticks = d_ticks[i];
126
const int size = ticks.count();
127
const int size2 = size / 2;
129
for (int i=0; i < size2; i++)
130
qSwap(ticks[i], ticks[size - 1 - i]);
135
Return a list of ticks
137
\param type MinorTick, MediumTick or MajorTick
139
const QwtValueList &QwtScaleDiv::ticks(int type) const
141
if ( type >= 0 || type < NTickTypes )
142
return d_ticks[type];
144
static QwtValueList noTicks;