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_math.h"
12 #include <qalgorithms.h>
13 
22 QwtScaleDiv::QwtScaleDiv( double lowerBound, double upperBound ):
23  d_lowerBound( lowerBound ),
24  d_upperBound( upperBound )
25 {
26 }
27 
35  QList<double> ticks[NTickTypes] ):
36  d_lowerBound( interval.minValue() ),
37  d_upperBound( interval.maxValue() )
38 {
39  for ( int i = 0; i < NTickTypes; i++ )
40  d_ticks[i] = ticks[i];
41 }
42 
53  QList<double> ticks[NTickTypes] ):
54  d_lowerBound( lowerBound ),
55  d_upperBound( upperBound )
56 {
57  for ( int i = 0; i < NTickTypes; i++ )
58  d_ticks[i] = ticks[i];
59 }
60 
73  const QList<double> &minorTicks,
74  const QList<double> &mediumTicks,
75  const QList<double> &majorTicks ):
76  d_lowerBound( lowerBound ),
77  d_upperBound( upperBound )
78 {
79  d_ticks[ MinorTick ] = minorTicks;
80  d_ticks[ MediumTick ] = mediumTicks;
81  d_ticks[ MajorTick ] = majorTicks;
82 }
83 
93 {
96 }
97 
104 {
105  d_lowerBound = interval.minValue();
106  d_upperBound = interval.maxValue();
107 }
108 
113 {
115 }
116 
124 {
126 }
127 
133 {
134  return d_lowerBound;
135 }
136 
144 {
146 }
147 
153 {
154  return d_upperBound;
155 }
156 
160 double QwtScaleDiv::range() const
161 {
162  return d_upperBound - d_lowerBound;
163 }
164 
169 bool QwtScaleDiv::operator==( const QwtScaleDiv &other ) const
170 {
171  if ( d_lowerBound != other.d_lowerBound ||
172  d_upperBound != other.d_upperBound )
173  {
174  return false;
175  }
176 
177  for ( int i = 0; i < NTickTypes; i++ )
178  {
179  if ( d_ticks[i] != other.d_ticks[i] )
180  return false;
181  }
182 
183  return true;
184 }
185 
190 bool QwtScaleDiv::operator!=( const QwtScaleDiv &other ) const
191 {
192  return ( !( *this == other ) );
193 }
194 
197 {
198  return ( d_lowerBound == d_upperBound );
199 }
200 
203 {
204  return d_lowerBound <= d_upperBound;
205 }
206 
213 bool QwtScaleDiv::contains( double value ) const
214 {
215  const double min = qMin( d_lowerBound, d_upperBound );
216  const double max = qMax( d_lowerBound, d_upperBound );
217 
218  return value >= min && value <= max;
219 }
220 
226 {
227  qSwap( d_lowerBound, d_upperBound );
228 
229  for ( int i = 0; i < NTickTypes; i++ )
230  {
231  QList<double>& ticks = d_ticks[i];
232 
233  const int size = ticks.count();
234  const int size2 = size / 2;
235 
236  for ( int j = 0; j < size2; j++ )
237  qSwap( ticks[j], ticks[size - 1 - j] );
238  }
239 }
240 
246 {
247  QwtScaleDiv other = *this;
248  other.invert();
249 
250  return other;
251 }
252 
265  double lowerBound, double upperBound ) const
266 {
267  const double min = qMin( lowerBound, upperBound );
268  const double max = qMax( lowerBound, upperBound );
269 
270  QwtScaleDiv sd;
271  sd.setInterval( lowerBound, upperBound );
272 
273  for ( int tickType = 0; tickType < QwtScaleDiv::NTickTypes; tickType++ )
274  {
275  const QList<double> &ticks = d_ticks[ tickType ];
276 
277  QList<double> boundedTicks;
278  for ( int i = 0; i < ticks.size(); i++ )
279  {
280  const double tick = ticks[i];
281  if ( tick >= min && tick <= max )
282  boundedTicks += tick;
283  }
284 
285  sd.setTicks( tickType, boundedTicks );
286  }
287 
288  return sd;
289 
290 }
291 
298 void QwtScaleDiv::setTicks( int type, const QList<double> &ticks )
299 {
300  if ( type >= 0 && type < NTickTypes )
301  d_ticks[type] = ticks;
302 }
303 
310 QList<double> QwtScaleDiv::ticks( int type ) const
311 {
312  if ( type >= 0 && type < NTickTypes )
313  return d_ticks[type];
314 
315  return QList<double>();
316 }
317 
318 #ifndef QT_NO_DEBUG_STREAM
319 
320 QDebug operator<<( QDebug debug, const QwtScaleDiv &scaleDiv )
321 {
322  debug << scaleDiv.lowerBound() << "<->" << scaleDiv.upperBound();
323  debug << "Major: " << scaleDiv.ticks( QwtScaleDiv::MajorTick );
324  debug << "Medium: " << scaleDiv.ticks( QwtScaleDiv::MediumTick );
325  debug << "Minor: " << scaleDiv.ticks( QwtScaleDiv::MinorTick );
326 
327  return debug;
328 }
329 
330 #endif
331 
QList< double > d_ticks[NTickTypes]
QwtScaleDiv bounded(double lowerBound, double upperBound) const
A class representing an interval.
Definition: qwt_interval.h:26
double minValue() const
Definition: qwt_interval.h:193
void setTicks(int tickType, const QList< double > &)
A class representing a scale division.
Definition: qwt_scale_div.h:36
void setLowerBound(double)
bool operator!=(const QwtScaleDiv &) const
Inequality.
double maxValue() const
Definition: qwt_interval.h:199
double upperBound() const
void setInterval(double lowerBound, double upperBound)
bool contains(double value) const
double d_upperBound
double lowerBound() const
void setUpperBound(double)
Number of valid tick types.
Definition: qwt_scale_div.h:55
bool isIncreasing() const
Check if the scale division is increasing( lowerBound() <= upperBound() )
uintptr_t size
double d_lowerBound
Definition: qwt_scale_div.h:99
int min(int a, int b)
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
int i
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 Sat Jul 6 2019 03:44:17