~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.0.2/src/qwt_scale_div.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 
2
 * Qwt Widget Library
 
3
 * Copyright (C) 1997   Josef Wilgen
 
4
 * Copyright (C) 2002   Uwe Rathmann
 
5
 * 
 
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
 *****************************************************************************/
 
9
 
 
10
#include "qwt_scale_div.h"
 
11
#include "qwt_math.h"
 
12
#include "qwt_double_interval.h"
 
13
 
 
14
//! Construct an invalid QwtScaleDiv instance.
 
15
QwtScaleDiv::QwtScaleDiv():
 
16
    d_lBound(0.0),
 
17
    d_hBound(0.0),
 
18
    d_isValid(false)
 
19
{
 
20
}
 
21
 
 
22
/*! 
 
23
  Construct QwtScaleDiv instance.
 
24
 
 
25
  \param interval Interval
 
26
  \param ticks List of major, medium and minor ticks
 
27
*/
 
28
QwtScaleDiv::QwtScaleDiv(
 
29
        const QwtDoubleInterval &interval, 
 
30
        QwtValueList ticks[NTickTypes]):
 
31
    d_lBound(interval.minValue()),
 
32
    d_hBound(interval.maxValue()),
 
33
    d_isValid(true)
 
34
{
 
35
    for ( int i = 0; i < NTickTypes; i++ )
 
36
        d_ticks[i] = ticks[i];
 
37
}
 
38
 
 
39
/*! 
 
40
  Construct QwtScaleDiv instance.
 
41
 
 
42
  \param lBound First interval limit
 
43
  \param hBound Second interval limit
 
44
  \param ticks List of major, medium and minor ticks
 
45
*/
 
46
QwtScaleDiv::QwtScaleDiv(
 
47
        double lBound, double hBound,
 
48
        QwtValueList ticks[NTickTypes]):
 
49
    d_lBound(lBound),
 
50
    d_hBound(hBound),
 
51
    d_isValid(true)
 
52
{
 
53
    for ( int i = 0; i < NTickTypes; i++ )
 
54
        d_ticks[i] = ticks[i];
 
55
}
 
56
 
 
57
/*!
 
58
  \brief Equality operator
 
59
  \return true if this instance is equal to other
 
60
*/
 
61
int QwtScaleDiv::operator==(const QwtScaleDiv &other) const
 
62
{
 
63
    if ( d_lBound != other.d_lBound ||
 
64
        d_hBound != other.d_hBound ||
 
65
        d_isValid != other.d_isValid )
 
66
    {
 
67
        return false;
 
68
    }
 
69
 
 
70
    for ( int i = 0; i < NTickTypes; i++ )
 
71
    {
 
72
        if ( d_ticks[i] != other.d_ticks[i] )
 
73
            return false;
 
74
    }
 
75
 
 
76
    return true;
 
77
}
 
78
 
 
79
/*!
 
80
  \brief Inequality
 
81
  \return true if this instance is not equal to s
 
82
*/
 
83
int QwtScaleDiv::operator!=(const QwtScaleDiv &s) const
 
84
{
 
85
    return (!(*this == s));
 
86
}
 
87
 
 
88
//! Invalidate the scale division
 
89
void QwtScaleDiv::invalidate()
 
90
{
 
91
    d_isValid = false;
 
92
 
 
93
    // detach arrays
 
94
    for ( int i = 0; i < NTickTypes; i++ )
 
95
        d_ticks[i].clear();
 
96
 
 
97
    d_lBound = d_hBound = 0;
 
98
}
 
99
 
 
100
//! Check if the scale division is valid
 
101
bool QwtScaleDiv::isValid() const
 
102
{
 
103
    return d_isValid;
 
104
}
 
105
 
 
106
bool QwtScaleDiv::contains(double v) const
 
107
{
 
108
    if ( !d_isValid )
 
109
        return false;
 
110
 
 
111
    const double min = qwtMin(d_lBound, d_hBound);
 
112
    const double max = qwtMax(d_lBound, d_hBound);
 
113
 
 
114
    return v >= min && v <= max;
 
115
}
 
116
 
 
117
//! Invert the scale divison
 
118
void QwtScaleDiv::invert()
 
119
{
 
120
    qSwap(d_lBound, d_hBound);
 
121
 
 
122
    for ( int i = 0; i < NTickTypes; i++ )
 
123
    {
 
124
        QwtValueList& ticks = d_ticks[i];
 
125
 
 
126
        const int size = ticks.count();
 
127
        const int size2 = size / 2;
 
128
 
 
129
        for (int i=0; i < size2; i++)
 
130
            qSwap(ticks[i], ticks[size - 1 - i]);
 
131
    }
 
132
}
 
133
 
 
134
/*!
 
135
   Return a list of ticks
 
136
 
 
137
   \param type MinorTick, MediumTick or MajorTick
 
138
*/
 
139
const QwtValueList &QwtScaleDiv::ticks(int type) const
 
140
{
 
141
    if ( type >= 0 || type < NTickTypes )
 
142
        return d_ticks[type];
 
143
 
 
144
    static QwtValueList noTicks;
 
145
    return noTicks;
 
146
}