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 
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 
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 
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 
92 {
95 }
96 
103 {
104  m_lowerBound = interval.minValue();
105  m_upperBound = interval.maxValue();
106 }
107 
112 {
114 }
115 
123 {
125 }
126 
132 {
133  return m_lowerBound;
134 }
135 
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;
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 
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 
double lowerBound() const
QList< double > m_ticks[NTickTypes]
Definition: qwt_scale_div.h:98
bool operator!=(const QwtScaleDiv &) const
Inequality.
QList< double > ticks(int tickType) const
A class representing an interval.
Definition: qwt_interval.h:22
double minValue() const
Definition: qwt_interval.h:192
bool contains(double value) const
void setTicks(int tickType, const QList< double > &)
double m_upperBound
Definition: qwt_scale_div.h:97
A class representing a scale division.
Definition: qwt_scale_div.h:33
void setLowerBound(double)
bool operator==(const QwtScaleDiv &) const
Equality operator.
void setInterval(double lowerBound, double upperBound)
QwtInterval interval() const
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
double m_lowerBound
Definition: qwt_scale_div.h:96
QwtScaleDiv bounded(double lowerBound, double upperBound) const
void setUpperBound(double)
bool isEmpty() const
Check if the scale division is empty( lowerBound() == upperBound() )
Number of valid tick types.
Definition: qwt_scale_div.h:52
QDebug operator<<(QDebug debug, const QwtScaleDiv &scaleDiv)
QwtScaleDiv inverted() const
span_constexpr std::size_t size(span< T, Extent > const &spn)
Definition: span.hpp:1485
Definition: core.h:1131
double upperBound() const
double range() const
QwtScaleDiv(double lowerBound=0.0, double upperBound=0.0)
double maxValue() const
Definition: qwt_interval.h:198


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:01:39