source: ntrip/trunk/GnssCenter/qwt/qwt_scale_div.cpp@ 5034

Last change on this file since 5034 was 4839, checked in by mervart, 11 years ago
File size: 3.8 KB
Line 
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_interval.h"
13#include <qalgorithms.h>
14
15//! Construct an invalid QwtScaleDiv instance.
16QwtScaleDiv::QwtScaleDiv():
17 d_lowerBound( 0.0 ),
18 d_upperBound( 0.0 ),
19 d_isValid( false )
20{
21}
22
23/*!
24 Construct QwtScaleDiv instance.
25
26 \param interval Interval
27 \param ticks List of major, medium and minor ticks
28*/
29QwtScaleDiv::QwtScaleDiv( const QwtInterval &interval,
30 QList<double> ticks[NTickTypes] ):
31 d_lowerBound( interval.minValue() ),
32 d_upperBound( 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 lowerBound First interval limit
43 \param upperBound Second interval limit
44 \param ticks List of major, medium and minor ticks
45*/
46QwtScaleDiv::QwtScaleDiv(
47 double lowerBound, double upperBound,
48 QList<double> ticks[NTickTypes] ):
49 d_lowerBound( lowerBound ),
50 d_upperBound( upperBound ),
51 d_isValid( true )
52{
53 for ( int i = 0; i < NTickTypes; i++ )
54 d_ticks[i] = ticks[i];
55}
56
57/*!
58 Change the interval
59 \param interval Interval
60*/
61void QwtScaleDiv::setInterval( const QwtInterval &interval )
62{
63 setInterval( interval.minValue(), interval.maxValue() );
64}
65
66/*!
67 \brief Equality operator
68 \return true if this instance is equal to other
69*/
70bool QwtScaleDiv::operator==( const QwtScaleDiv &other ) const
71{
72 if ( d_lowerBound != other.d_lowerBound ||
73 d_upperBound != other.d_upperBound ||
74 d_isValid != other.d_isValid )
75 {
76 return false;
77 }
78
79 for ( int i = 0; i < NTickTypes; i++ )
80 {
81 if ( d_ticks[i] != other.d_ticks[i] )
82 return false;
83 }
84
85 return true;
86}
87
88/*!
89 \brief Inequality
90 \return true if this instance is not equal to s
91*/
92bool QwtScaleDiv::operator!=( const QwtScaleDiv &s ) const
93{
94 return ( !( *this == s ) );
95}
96
97//! Invalidate the scale division
98void QwtScaleDiv::invalidate()
99{
100 d_isValid = false;
101
102 // detach arrays
103 for ( int i = 0; i < NTickTypes; i++ )
104 d_ticks[i].clear();
105
106 d_lowerBound = d_upperBound = 0;
107}
108
109//! Check if the scale division is valid
110bool QwtScaleDiv::isValid() const
111{
112 return d_isValid;
113}
114
115/*!
116 Return if a value is between lowerBound() and upperBound()
117
118 \param value Value
119 \return true/false
120*/
121bool QwtScaleDiv::contains( double value ) const
122{
123 if ( !d_isValid )
124 return false;
125
126 const double min = qMin( d_lowerBound, d_upperBound );
127 const double max = qMax( d_lowerBound, d_upperBound );
128
129 return value >= min && value <= max;
130}
131
132//! Invert the scale divison
133void QwtScaleDiv::invert()
134{
135 qSwap( d_lowerBound, d_upperBound );
136
137 for ( int i = 0; i < NTickTypes; i++ )
138 {
139 QList<double>& ticks = d_ticks[i];
140
141 const int size = ticks.count();
142 const int size2 = size / 2;
143
144 for ( int i = 0; i < size2; i++ )
145 qSwap( ticks[i], ticks[size - 1 - i] );
146 }
147}
148
149/*!
150 Assign ticks
151
152 \param type MinorTick, MediumTick or MajorTick
153 \param ticks Values of the tick positions
154*/
155void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
156{
157 if ( type >= 0 || type < NTickTypes )
158 d_ticks[type] = ticks;
159}
160
161/*!
162 Return a list of ticks
163
164 \param type MinorTick, MediumTick or MajorTick
165*/
166const QList<double> &QwtScaleDiv::ticks( int type ) const
167{
168 if ( type >= 0 || type < NTickTypes )
169 return d_ticks[type];
170
171 static QList<double> noTicks;
172 return noTicks;
173}
Note: See TracBrowser for help on using the repository browser.