qwt_scale_div.cpp
Go to the documentation of this file.
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 
21 QwtScaleDiv::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 
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 {
95 }
96 
102 void QwtScaleDiv::setInterval( const QwtInterval& interval )
103 {
106 }
107 
112 {
114 }
115 
122 void QwtScaleDiv::setLowerBound( double lowerBound )
123 {
125 }
126 
132 {
133  return m_lowerBound;
134 }
135 
142 void QwtScaleDiv::setUpperBound( double upperBound )
143 {
145 }
146 
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 
196 {
197  return ( m_lowerBound == m_upperBound );
198 }
199 
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 
225 {
226  qSwap( m_lowerBound, m_upperBound );
227 
228  for ( int i = 0; i < NTickTypes; i++ )
229  {
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 
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 
321 QDebug 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 
QwtScaleDiv::range
double range() const
Definition: qwt_scale_div.cpp:159
QwtScaleDiv::setLowerBound
void setLowerBound(double)
Definition: qwt_scale_div.cpp:122
qwt_scale_div.h
QwtScaleDiv::MediumTick
@ MediumTick
Medium ticks.
Definition: qwt_scale_div.h:46
QwtScaleDiv::QwtScaleDiv
QwtScaleDiv(double lowerBound=0.0, double upperBound=0.0)
Definition: qwt_scale_div.cpp:21
QwtInterval::minValue
double minValue() const
Definition: qwt_interval.h:192
qwt_interval.h
QwtScaleDiv::lowerBound
double lowerBound() const
Definition: qwt_scale_div.cpp:131
QList< double >
QwtScaleDiv::setInterval
void setInterval(double lowerBound, double upperBound)
Definition: qwt_scale_div.cpp:91
QwtScaleDiv::contains
bool contains(double value) const
Definition: qwt_scale_div.cpp:212
QwtScaleDiv::ticks
QList< double > ticks(int tickType) const
Definition: qwt_scale_div.cpp:309
nonstd::span_lite::size
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1554
QwtScaleDiv::MajorTick
@ MajorTick
Major ticks.
Definition: qwt_scale_div.h:49
QwtInterval
A class representing an interval.
Definition: qwt_interval.h:22
QwtScaleDiv::m_upperBound
double m_upperBound
Definition: qwt_scale_div.h:97
QwtScaleDiv::NTickTypes
@ NTickTypes
Number of valid tick types.
Definition: qwt_scale_div.h:52
QwtScaleDiv::isIncreasing
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
Definition: qwt_scale_div.cpp:201
QwtScaleDiv::m_ticks
QList< double > m_ticks[NTickTypes]
Definition: qwt_scale_div.h:98
QwtScaleDiv::upperBound
double upperBound() const
Definition: qwt_scale_div.cpp:151
QwtScaleDiv::setUpperBound
void setUpperBound(double)
Definition: qwt_scale_div.cpp:142
QwtScaleDiv::operator==
bool operator==(const QwtScaleDiv &) const
Equality operator.
Definition: qwt_scale_div.cpp:168
QwtScaleDiv::isEmpty
bool isEmpty() const
Check if the scale division is empty( lowerBound() == upperBound() )
Definition: qwt_scale_div.cpp:195
QwtScaleDiv::invert
void invert()
Definition: qwt_scale_div.cpp:224
QwtScaleDiv::m_lowerBound
double m_lowerBound
Definition: qwt_scale_div.h:96
QwtScaleDiv::setTicks
void setTicks(int tickType, const QList< double > &)
Definition: qwt_scale_div.cpp:297
QwtScaleDiv::inverted
QwtScaleDiv inverted() const
Definition: qwt_scale_div.cpp:244
QwtInterval::maxValue
double maxValue() const
Definition: qwt_interval.h:198
presentation_type::debug
@ debug
operator<<
QDebug operator<<(QDebug debug, const QwtScaleDiv &scaleDiv)
Definition: qwt_scale_div.cpp:321
QwtScaleDiv::MinorTick
@ MinorTick
Minor ticks.
Definition: qwt_scale_div.h:43
QwtScaleDiv
A class representing a scale division.
Definition: qwt_scale_div.h:33
QwtScaleDiv::operator!=
bool operator!=(const QwtScaleDiv &) const
Inequality.
Definition: qwt_scale_div.cpp:189
QwtScaleDiv::bounded
QwtScaleDiv bounded(double lowerBound, double upperBound) const
Definition: qwt_scale_div.cpp:263
QwtScaleDiv::interval
QwtInterval interval() const
Definition: qwt_scale_div.cpp:111


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46