![]() |
RTXI 1.3
|
00001 #include <qwt-qt3/qwt_plot.h> 00002 #include <qwt-qt3/qwt_plot_canvas.h> 00003 #include <qwt-qt3/qwt_plot_curve.h> 00004 #include "incrementalplot.h" 00005 #if QT_VERSION >= 0x040000 00006 #include <qpaintengine.h> 00007 #endif 00008 00009 CurveData::CurveData() : 00010 d_count(0) 00011 { 00012 } 00013 00014 void 00015 CurveData::append(double *x, double *y, int count) 00016 { 00017 int newSize = ((d_count + count) / 1000 + 1) * 1000; 00018 if (newSize > size()) 00019 { 00020 d_x.resize(newSize); 00021 d_y.resize(newSize); 00022 } 00023 00024 for (register int i = 0; i < count; i++) 00025 { 00026 d_x[d_count + i] = x[i]; 00027 d_y[d_count + i] = y[i]; 00028 } 00029 d_count += count; 00030 } 00031 00032 int 00033 CurveData::count() const 00034 { 00035 return d_count; 00036 } 00037 00038 int 00039 CurveData::size() const 00040 { 00041 return d_x.size(); 00042 } 00043 00044 const double * 00045 CurveData::x() const 00046 { 00047 return d_x.data(); 00048 } 00049 00050 const double * 00051 CurveData::y() const 00052 { 00053 return d_y.data(); 00054 } 00055 00056 IncrementalPlot::IncrementalPlot(QWidget *parent) : 00057 BasicPlot(parent), d_data(NULL), d_curve(NULL), l_data(NULL), l_curve(NULL) 00058 { 00059 setAutoReplot(false); 00060 } 00061 00062 IncrementalPlot::~IncrementalPlot() 00063 { 00064 delete d_data; 00065 } 00066 00067 const double * 00068 IncrementalPlot::xData() 00069 { 00070 return d_data->x(); 00071 } 00072 00073 const double * 00074 IncrementalPlot::yData() 00075 { 00076 return d_data->y(); 00077 } 00078 00079 const uint 00080 IncrementalPlot::dataSize() 00081 { 00082 return d_data->count(); 00083 } 00084 00085 bool 00086 IncrementalPlot::dataExists() 00087 { 00088 if (d_data == NULL) 00089 return false; 00090 else 00091 return true; 00092 } 00093 00094 void 00095 IncrementalPlot::appendData(double x, double y) 00096 { 00097 appendData(&x, &y, 1); 00098 } 00099 00100 void 00101 IncrementalPlot::appendData(double x, double y, QwtSymbol::Style s) 00102 { 00103 appendData(&x, &y, 1, s); 00104 } 00105 00106 void 00107 IncrementalPlot::appendData(double *x, double *y, int size) 00108 { 00109 if (d_data == NULL) 00110 d_data = new CurveData; 00111 00112 if (d_curve == NULL) 00113 { 00114 d_curve = new QwtPlotCurve("Data"); 00115 d_curve->setStyle(QwtPlotCurve::NoCurve); 00116 d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered); 00117 const QColor &c = Qt::white; 00118 d_curve->setSymbol(QwtSymbol(QwtSymbol::Ellipse, QBrush(c), QPen(c), 00119 QSize(6, 6))); 00120 00121 d_curve->attach(this); 00122 } 00123 00124 d_data->append(x, y, size); 00125 d_curve->setRawData(d_data->x(), d_data->y(), d_data->count()); 00126 #ifdef __GNUC__ 00127 #warning better use QwtData 00128 #endif 00129 00130 const bool cacheMode = canvas()->testPaintAttribute( 00131 QwtPlotCanvas::PaintCached); 00132 00133 #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) 00134 // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent 00135 // works on X11. This has an tremendous effect on the performance.. 00136 00137 canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); 00138 #endif 00139 00140 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); 00141 d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1); 00142 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode); 00143 00144 #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) 00145 canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false); 00146 #endif 00147 } 00148 00149 void 00150 IncrementalPlot::appendData(double *x, double *y, int size, QwtSymbol::Style s) 00151 { 00152 if (d_data == NULL) 00153 d_data = new CurveData; 00154 00155 if (d_curve == NULL) 00156 { 00157 d_curve = new QwtPlotCurve("Data"); 00158 d_curve->setStyle(QwtPlotCurve::NoCurve); 00159 d_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered); 00160 const QColor &c = Qt::white; 00161 d_curve->setSymbol(QwtSymbol(s, QBrush(c), QPen(c), QSize(6, 6))); 00162 d_curve->attach(this); 00163 } 00164 00165 d_data->append(x, y, size); 00166 d_curve->setRawData(d_data->x(), d_data->y(), d_data->count()); 00167 #ifdef __GNUC__ 00168 #warning better use QwtData 00169 #endif 00170 00171 const bool cacheMode = canvas()->testPaintAttribute( 00172 QwtPlotCanvas::PaintCached); 00173 00174 #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) 00175 // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent 00176 // works on X11. This has an tremendous effect on the performance.. 00177 00178 canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); 00179 #endif 00180 00181 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); 00182 d_curve->draw(d_curve->dataSize() - size, d_curve->dataSize() - 1); 00183 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode); 00184 00185 #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) 00186 canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false); 00187 #endif 00188 } 00189 00190 void 00191 IncrementalPlot::appendLine(double *x, double *y, int size) 00192 { 00193 if (l_data == NULL) 00194 l_data = new CurveData; 00195 00196 if (l_curve == NULL) 00197 { 00198 l_curve = new QwtPlotCurve("Line"); 00199 l_curve->setStyle(QwtPlotCurve::Lines); 00200 l_curve->setPaintAttribute(QwtPlotCurve::PaintFiltered); 00201 l_curve->setPen(QColor(Qt::white)); 00202 const QColor &c = Qt::white; 00203 l_curve->setSymbol(QwtSymbol(QwtSymbol::NoSymbol, QBrush(c), QPen(c), 00204 QSize(6, 6))); 00205 00206 l_curve->attach(this); 00207 } 00208 00209 l_data->append(x, y, size); 00210 l_curve->setRawData(l_data->x(), l_data->y(), l_data->count()); 00211 #ifdef __GNUC__ 00212 #warning better use QwtData 00213 #endif 00214 00215 const bool cacheMode = canvas()->testPaintAttribute( 00216 QwtPlotCanvas::PaintCached); 00217 00218 #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) 00219 // Even if not recommended by TrollTech, Qt::WA_PaintOutsidePaintEvent 00220 // works on X11. This has an tremendous effect on the performance.. 00221 00222 canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true); 00223 #endif 00224 00225 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); 00226 l_curve->draw(l_curve->dataSize() - size, l_curve->dataSize() - 1); 00227 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, cacheMode); 00228 00229 #if QT_VERSION >= 0x040000 && defined(Q_WS_X11) 00230 canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, false); 00231 #endif 00232 } 00233 00234 void 00235 IncrementalPlot::removeData() 00236 { 00237 delete d_curve; 00238 d_curve = NULL; 00239 delete l_curve; 00240 l_curve = NULL; 00241 00242 delete d_data; 00243 d_data = NULL; 00244 delete l_data; 00245 l_data = NULL; 00246 replot(); 00247 } 00248 00249 void 00250 IncrementalPlot::nextSymbol() 00251 { 00252 int n = d_curve->symbol().style() + 1; 00253 if (n > 14) 00254 n = 0; 00255 d_curve->setSymbol(QwtSymbol((QwtSymbol::Style) n, QBrush(Qt::white), QPen( 00256 Qt::white), QSize(6, 6))); 00257 } 00258