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
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
51QwtScaleDiv::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
71QwtScaleDiv::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
91void QwtScaleDiv::setInterval( double lowerBound, double upperBound )
92{
93 m_lowerBound = lowerBound;
94 m_upperBound = upperBound;
95}
96
103{
104 m_lowerBound = interval.minValue();
105 m_upperBound = interval.maxValue();
106}
107
112{
113 return QwtInterval( m_lowerBound, m_upperBound );
114}
115
122void QwtScaleDiv::setLowerBound( double lowerBound )
123{
124 m_lowerBound = lowerBound;
125}
126
132{
133 return m_lowerBound;
134}
135
142void QwtScaleDiv::setUpperBound( double upperBound )
143{
144 m_upperBound = upperBound;
145}
146
152{
153 return m_upperBound;
154}
155
159double QwtScaleDiv::range() const
160{
161 return m_upperBound - m_lowerBound;
162}
163
168bool 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
189bool QwtScaleDiv::operator!=( const QwtScaleDiv& other ) const
190{
191 return ( !( *this == other ) );
192}
193
196{
197 return ( m_lowerBound == m_upperBound );
198}
199
202{
203 return m_lowerBound <= m_upperBound;
204}
205
212bool 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
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
245{
246 QwtScaleDiv other = *this;
247 other.invert();
248
249 return other;
250}
251
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;
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
297void QwtScaleDiv::setTicks( int tickType, const QList< double >& ticks )
298{
299 if ( tickType >= 0 && tickType < NTickTypes )
300 m_ticks[tickType] = ticks;
301}
302
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
A class representing an interval.
double minValue() const
double maxValue() const
A class representing a scale division.
QwtScaleDiv bounded(double lowerBound, double upperBound) const
double lowerBound() const
bool operator==(const QwtScaleDiv &) const
Equality operator.
QwtInterval interval() const
double range() const
double upperBound() const
void setUpperBound(double)
QwtScaleDiv(double lowerBound=0.0, double upperBound=0.0)
bool operator!=(const QwtScaleDiv &) const
Inequality.
void setLowerBound(double)
QList< double > ticks(int tickType) const
bool contains(double value) const
void setInterval(double lowerBound, double upperBound)
QwtScaleDiv inverted() const
bool isEmpty() const
Check if the scale division is empty( lowerBound() == upperBound() )
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
@ MediumTick
Medium ticks.
@ MinorTick
Minor ticks.
@ NTickTypes
Number of valid tick types.
@ MajorTick
Major ticks.
void setTicks(int tickType, const QList< double > &)