qwt_scale_div.cpp
Go to the documentation of this file.
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_interval.h"
12 
21 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ):
22  d_lowerBound( lowerBound ),
23  d_upperBound( upperBound )
24 {
25 }
26 
35  d_lowerBound( interval.minValue() ),
36  d_upperBound( interval.maxValue() )
37 {
38  for ( int i = 0; i < NTickTypes; i++ )
39  d_ticks[i] = ticks[i];
40 }
41 
53  d_lowerBound( lowerBound ),
54  d_upperBound( upperBound )
55 {
56  for ( int i = 0; i < NTickTypes; i++ )
57  d_ticks[i] = ticks[i];
58 }
59 
72  const QList<double> &minorTicks,
73  const QList<double> &mediumTicks,
74  const QList<double> &majorTicks ):
75  d_lowerBound( lowerBound ),
76  d_upperBound( upperBound )
77 {
78  d_ticks[ MinorTick ] = minorTicks;
79  d_ticks[ MediumTick ] = mediumTicks;
80  d_ticks[ MajorTick ] = majorTicks;
81 }
82 
92 {
95 }
96 
103 {
104  d_lowerBound = interval.minValue();
105  d_upperBound = interval.maxValue();
106 }
107 
112 {
114 }
115 
123 {
125 }
126 
132 {
133  return d_lowerBound;
134 }
135 
143 {
145 }
146 
152 {
153  return d_upperBound;
154 }
155 
159 double QwtScaleDiv::range() const
160 {
161  return d_upperBound - d_lowerBound;
162 }
163 
168 bool QwtScaleDiv::operator==( const QwtScaleDiv &other ) const
169 {
170  if ( d_lowerBound != other.d_lowerBound ||
171  d_upperBound != other.d_upperBound )
172  {
173  return false;
174  }
175 
176  for ( int i = 0; i < NTickTypes; i++ )
177  {
178  if ( d_ticks[i] != other.d_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 ( d_lowerBound == d_upperBound );
198 }
199 
202 {
203  return d_lowerBound <= d_upperBound;
204 }
205 
212 bool QwtScaleDiv::contains( double value ) const
213 {
214  const double min = qMin( d_lowerBound, d_upperBound );
215  const double max = qMax( d_lowerBound, d_upperBound );
216 
217  return value >= min && value <= max;
218 }
219 
225 {
226  qSwap( d_lowerBound, d_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 = d_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  d_ticks[tickType] = ticks;
301 }
302 
309 QList<double> QwtScaleDiv::ticks( int tickType ) const
310 {
311  if ( tickType >= 0 && tickType < NTickTypes )
312  return d_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 
enum MQTTPropertyCodes value
QList< double > d_ticks[NTickTypes]
Definition: qwt_scale_div.h:98
QwtScaleDiv bounded(double lowerBound, double upperBound) const
A class representing an interval.
Definition: qwt_interval.h:22
double minValue() const
Definition: qwt_interval.h:190
void setTicks(int tickType, const QList< double > &)
A class representing a scale division.
Definition: qwt_scale_div.h:33
void setLowerBound(double)
bool operator!=(const QwtScaleDiv &) const
Inequality.
double maxValue() const
Definition: qwt_interval.h:196
double upperBound() const
void setInterval(double lowerBound, double upperBound)
bool contains(double value) const
double d_upperBound
Definition: qwt_scale_div.h:97
#define min(A, B)
Definition: Log.c:64
#define max(A, B)
Definition: Socket.h:88
double lowerBound() const
void setUpperBound(double)
Number of valid tick types.
Definition: qwt_scale_div.h:52
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
double d_lowerBound
Definition: qwt_scale_div.h:96
QDebug operator<<(QDebug debug, const QwtScaleDiv &scaleDiv)
bool operator==(const QwtScaleDiv &) const
Equality operator.
QwtInterval interval() const
bool isEmpty() const
Check if the scale division is empty( lowerBound() == upperBound() )
double range() const
QList< double > ticks(int tickType) const
QwtScaleDiv(double lowerBound=0.0, double upperBound=0.0)
QwtScaleDiv inverted() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10