QXRD  0.11.16
qwt_plot_piecewise_curve.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 
11 
12 #include "qcepplot.h"
13 
15  m_Plot(NULL)
16 {
17 }
18 
20  QwtPlotCurve(title),
21  m_Plot(plot)
22 {
23 }
24 
26  QwtPlotCurve(title),
27  m_Plot(plot)
28 {
29 }
30 
32 {
33  return x != x;
34 }
35 
36 bool QwtPlotPiecewiseCurve::ignorePoint(double x, double y) const
37 {
38  if (isNaN(x)) return true;
39 
40  if (isNaN(y)) return true;
41 
42  if (m_Plot) {
43  if (m_Plot->logAxis(xAxis()) && (x <= 0)) return true;
44  if (m_Plot->logAxis(yAxis()) && (y <= 0)) return true;
45  }
46 
47  return false;
48 }
49 
50 // This is a slow implementation: it might be worth to cache valid data ranges.
51 void QwtPlotPiecewiseCurve::drawSeries(QPainter *painter,
52  const QwtScaleMap &xMap, const QwtScaleMap &yMap,
53  const QRectF &canvasRect, int from, int to) const
54 {
55  if (to < 0) {
56  to = dataSize() - 1;
57  }
58 
59  int first, last = from;
60  while (last <= to) {
61  first = last;
62  while (first <= to && ignorePoint(x(first),y(first))) {
63  ++first;
64  }
65 
66  last = first;
67  while (last <= to && !ignorePoint(x(last),y(last))) {
68  ++last;
69  }
70 
71  if (first <= to) {
72  QwtPlotCurve::drawSeries(painter, xMap, yMap, canvasRect, first, last - 1);
73  }
74  }
75 }
76 
77 // This overload is needed when using autoscale. It is a slow implementation:
78 // it might be worth to cache valid data ranges.
80 {
81  if (dataSize() <= 0) {
82  return QRectF(1.0, 1.0, 2.0, 2.0); // Empty data.
83  }
84 
85  size_t first = 0;
86  while (first < dataSize() && ignorePoint(x(first),y(first))) {
87  ++first;
88  }
89 
90  if (first == dataSize()) {
91  return QRectF(1.0, 1.0, 2.0, 2.0); // Empty data.
92  }
93 
94  double minX, maxX, minY, maxY;
95  minX = maxX = x(first);
96  minY = maxY = y(first);
97  for (size_t i = first + 1; i < dataSize(); ++i) {
98  const double xv = x(i);
99  const double yv = y(i);
100 
101  if (!ignorePoint(xv,yv)) {
102  if (xv < minX)
103  minX = xv;
104  if (xv > maxX)
105  maxX = xv;
106  if (yv < minY)
107  minY = yv;
108  if (yv > maxY)
109  maxY = yv;
110  }
111  }
112 
113  return QRectF(minX, minY, maxX - minX, maxY - minY);
114 }
115 
116 double QwtPlotPiecewiseCurve::x(int n) const
117 {
118  QPointF s = sample(n);
119 
120  return s.x();
121 }
122 
123 double QwtPlotPiecewiseCurve::y(int n) const
124 {
125  QPointF s = sample(n);
126 
127  return s.y();
128 }
int logAxis(int axis)
Definition: qcepplot.cpp:389
virtual QRectF boundingRect() const
virtual void drawSeries(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const
bool ignorePoint(double x, double y) const