Qwt User's Guide: qwt_scale_div.cpp Source File

Qwt User's Guide 6.3.0

Loading...
Searching...
No Matches
qwt_scale_div.cpp
1/******************************************************************************
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_interval.h"
12
21QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound )
22 : m_lowerBound( lowerBound )
23 , m_upperBound( upperBound )
24{
25}
26
33 QwtScaleDiv::QwtScaleDiv( const QwtInterval& interval,
34 QList< double > ticks[NTickTypes] )
35 : m_lowerBound( interval.minValue() )
36 , m_upperBound( interval.maxValue() )
37{
38 for ( int i = 0; i < NTickTypes; i++ )
39 m_ticks[i] = ticks[i];
40}
41
51 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
52 QList< double > ticks[NTickTypes] )
53 : m_lowerBound( lowerBound )
54 , m_upperBound( upperBound )
55{
56 for ( int i = 0; i < NTickTypes; i++ )
57 m_ticks[i] = ticks[i];
58}
59
71 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound,
72 const QList< double >& minorTicks,
73 const QList< double >& mediumTicks,
74 const QList< double >& majorTicks )
75 : m_lowerBound( lowerBound )
76 , m_upperBound( upperBound )
77{
78 m_ticks[ MinorTick ] = minorTicks;
79 m_ticks[ MediumTick ] = mediumTicks;
80 m_ticks[ MajorTick ] = majorTicks;
81}
82
91 void QwtScaleDiv::setInterval( double lowerBound, double upperBound )
92{
93 m_lowerBound = lowerBound;
94 m_upperBound = upperBound;
95}
96
102 void QwtScaleDiv::setInterval( const QwtInterval& interval )
103{
104 m_lowerBound = interval.minValue();
105 m_upperBound = interval.maxValue();
106}
107
111 QwtInterval QwtScaleDiv::interval() const
112{
113 return QwtInterval( m_lowerBound, m_upperBound );
114}
115
122 void QwtScaleDiv::setLowerBound( double lowerBound )
123{
124 m_lowerBound = lowerBound;
125}
126
131 double QwtScaleDiv::lowerBound() const
132{
133 return m_lowerBound;
134}
135
142 void QwtScaleDiv::setUpperBound( double upperBound )
143{
144 m_upperBound = upperBound;
145}
146
151 double QwtScaleDiv::upperBound() const
152{
153 return m_upperBound;
154}
155
159 double QwtScaleDiv::range() const
160{
161 return m_upperBound - m_lowerBound;
162}
163
168 bool QwtScaleDiv::operator==( const QwtScaleDiv& other ) const
169{
170 if ( m_lowerBound != other.m_lowerBound ||
171 m_upperBound != other.m_upperBound )
172 {
173 return false;
174 }
175
176 for ( int i = 0; i < NTickTypes; i++ )
177 {
178 if ( m_ticks[i] != other.m_ticks[i] )
179 return false;
180 }
181
182 return true;
183}
184
189 bool QwtScaleDiv::operator!=( const QwtScaleDiv& other ) const
190{
191 return ( !( *this == other ) );
192}
193
195 bool QwtScaleDiv::isEmpty() const
196{
197 return ( m_lowerBound == m_upperBound );
198}
199
201 bool QwtScaleDiv::isIncreasing() const
202{
203 return m_lowerBound <= m_upperBound;
204}
205
212 bool QwtScaleDiv::contains( double value ) const
213{
214 const double min = qMin( m_lowerBound, m_upperBound );
215 const double max = qMax( m_lowerBound, m_upperBound );
216
217 return value >= min && value <= max;
218}
219
224 void QwtScaleDiv::invert()
225{
226 qSwap( m_lowerBound, m_upperBound );
227
228 for ( int i = 0; i < NTickTypes; i++ )
229 {
230 QList< double >& ticks = m_ticks[i];
231
232 const int size = ticks.count();
233 const int size2 = size / 2;
234
235 for ( int j = 0; j < size2; j++ )
236 qSwap( ticks[j], ticks[size - 1 - j] );
237 }
238}
239
244 QwtScaleDiv QwtScaleDiv::inverted() const
245{
246 QwtScaleDiv other = *this;
247 other.invert();
248
249 return other;
250}
251
263 QwtScaleDiv QwtScaleDiv::bounded(
264 double lowerBound, double upperBound ) const
265{
266 const double min = qMin( lowerBound, upperBound );
267 const double max = qMax( lowerBound, upperBound );
268
269 QwtScaleDiv sd;
270 sd.setInterval( lowerBound, upperBound );
271
272 for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ )
273 {
274 const QList< double >& ticks = m_ticks[ tickType ];
275
276 QList< double > boundedTicks;
277 for ( int i = 0; i < ticks.size(); i++ )
278 {
279 const double tick = ticks[i];
280 if ( tick >= min && tick <= max )
281 boundedTicks += tick;
282 }
283
284 sd.setTicks( tickType, boundedTicks );
285 }
286
287 return sd;
288
289}
290
297 void QwtScaleDiv::setTicks( int tickType, const QList< double >& ticks )
298{
299 if ( tickType >= 0 && tickType < NTickTypes )
300 m_ticks[tickType] = ticks;
301}
302
309 QList< double > QwtScaleDiv::ticks( int tickType ) const
310{
311 if ( tickType >= 0 && tickType < NTickTypes )
312 return m_ticks[tickType];
313
314 return QList< double >();
315}
316
317#ifndef QT_NO_DEBUG_STREAM
318
319#include <qdebug.h>
320
321QDebug operator<<( QDebug debug, const QwtScaleDiv& scaleDiv )
322{
323 debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound();
324 debug << "Major: " << scaleDiv.ticks( QwtScaleDiv::MajorTick );
325 debug << "Medium: " << scaleDiv.ticks( QwtScaleDiv::MediumTick );
326 debug << "Minor: " << scaleDiv.ticks( QwtScaleDiv::MinorTick );
327
328 return debug;
329}
330
331#endif
332
QList< double >
QwtInterval
A class representing an interval.
Definition qwt_interval.h:23
QwtInterval::minValue
double minValue() const
Definition qwt_interval.h:192
QwtInterval::maxValue
double maxValue() const
Definition qwt_interval.h:198
QwtScaleDiv
A class representing a scale division.
Definition qwt_scale_div.h:34
QwtScaleDiv::bounded
QwtScaleDiv bounded(double lowerBound, double upperBound) const
Definition qwt_scale_div.cpp:263
QwtScaleDiv::lowerBound
double lowerBound() const
Definition qwt_scale_div.cpp:131
QwtScaleDiv::invert
void invert()
Definition qwt_scale_div.cpp:224
QwtScaleDiv::operator==
bool operator==(const QwtScaleDiv &) const
Equality operator.
Definition qwt_scale_div.cpp:168
QwtScaleDiv::interval
QwtInterval interval() const
Definition qwt_scale_div.cpp:111
QwtScaleDiv::range
double range() const
Definition qwt_scale_div.cpp:159
QwtScaleDiv::upperBound
double upperBound() const
Definition qwt_scale_div.cpp:151
QwtScaleDiv::setUpperBound
void setUpperBound(double)
Definition qwt_scale_div.cpp:142
QwtScaleDiv::QwtScaleDiv
QwtScaleDiv(double lowerBound=0.0, double upperBound=0.0)
Definition qwt_scale_div.cpp:21
QwtScaleDiv::operator!=
bool operator!=(const QwtScaleDiv &) const
Inequality.
Definition qwt_scale_div.cpp:189
QwtScaleDiv::setLowerBound
void setLowerBound(double)
Definition qwt_scale_div.cpp:122
QwtScaleDiv::ticks
QList< double > ticks(int tickType) const
Definition qwt_scale_div.cpp:309
QwtScaleDiv::contains
bool contains(double value) const
Definition qwt_scale_div.cpp:212
QwtScaleDiv::setInterval
void setInterval(double lowerBound, double upperBound)
Definition qwt_scale_div.cpp:91
QwtScaleDiv::inverted
QwtScaleDiv inverted() const
Definition qwt_scale_div.cpp:244
QwtScaleDiv::isEmpty
bool isEmpty() const
Check if the scale division is empty( lowerBound() == upperBound() )
Definition qwt_scale_div.cpp:195
QwtScaleDiv::isIncreasing
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
Definition qwt_scale_div.cpp:201
QwtScaleDiv::MediumTick
@ MediumTick
Medium ticks.
Definition qwt_scale_div.h:46
QwtScaleDiv::MinorTick
@ MinorTick
Minor ticks.
Definition qwt_scale_div.h:43
QwtScaleDiv::NTickTypes
@ NTickTypes
Number of valid tick types.
Definition qwt_scale_div.h:52
QwtScaleDiv::MajorTick
@ MajorTick
Major ticks.
Definition qwt_scale_div.h:49
QwtScaleDiv::setTicks
void setTicks(int tickType, const QList< double > &)
Definition qwt_scale_div.cpp:297