Changeset 259 in flair-src for trunk/tools/FlairGCS
- Timestamp:
- Jul 25, 2018, 5:27:17 PM (6 years ago)
- Location:
- trunk/tools/FlairGCS/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/FlairGCS/src/UsSensorPlot.cpp
r244 r259 14 14 #include <qwt_legend.h> 15 15 #include <qwt_plot_panner.h> 16 #include <qwt_plot_rescaler.h>17 16 #include <qwt_plot_marker.h> 18 17 #include <QMouseEvent> 19 18 #include <QMenu> 20 19 #include <QInputDialog> 20 #include <QVBoxLayout> 21 #include <QScrollBar> 21 22 #include <qendian.h> 22 23 #include <qwt_symbol.h> … … 25 26 QString y_name, float ymin, float ymax, uint32_t nbSamples,QString datasType,bool enabled, int period) 26 27 : DataRemote(plot_name, "UsSensorPlot", parent, enabled, period) { 28 visible_widget = new QWidget(); 29 30 parent->addWidget(visible_widget, row, col); 31 QVBoxLayout* layout = new QVBoxLayout(visible_widget); 32 27 33 plot = new QwtPlot(NULL); 28 34 plot->setEnabled(enabled); 29 30 parent->addWidget(plot, row, col);31 visible_widget = plot;32 35 33 36 this->nbSamples=nbSamples; … … 44 47 #endif 45 48 49 //scroll bar 50 scrollbar=new QScrollBar(Qt::Horizontal); 51 scrollbar->setSingleStep(1); 52 scrollbar->setRange(0,0); 53 scrolling=true; 54 connect(scrollbar,SIGNAL(valueChanged(int)),this,SLOT(scrollBarMoved(int))); 55 layout->addWidget(scrollbar); 56 layout->addWidget(plot); 57 46 58 alignScales(); 47 59 48 60 // Assign a title 49 61 plot->setTitle(plot_name); 50 62 51 63 // Axis 52 64 plot->setAxisTitle(QwtPlot::xBottom, "samples"); 53 65 setXAxisScale(0, nbSamples-1); 54 66 55 67 plot->setAxisTitle(QwtPlot::yLeft, y_name); 56 68 setYAxisScale(ymin, ymax); 57 58 //QwtPlotRescaler *rescaler = new QwtPlotRescaler(plot->canvas());59 //rescaler->setRescalePolicy(QwtPlotRescaler::Fixed);60 /*61 rescaler->setReferenceAxis(QwtPlot::xBottom);62 rescaler->setAspectRatio(QwtPlot::yLeft, 1.0);*/63 69 64 70 // grid … … 77 83 78 84 dx = (double *)malloc(nbSamples* sizeof(double)); 79 dy = (double *)malloc(nbSamples* sizeof(double));80 85 for (int i = 0; i < nbSamples; i++) dx[i] = i; 81 86 … … 86 91 87 92 datas->setVisible(true); 88 89 // Attach (don't copy) data90 datas->setRawSamples(dx,dy, nbSamples);91 93 92 94 if (datasType == "float") { … … 104 106 QwtSymbol* s1=new QwtSymbol( QwtSymbol::Diamond, Qt::blue, Qt::NoPen, QSize( 10, 10 ) ); 105 107 firstPeakStart->setSymbol(s1); 106 //m->setLabel("toto" );107 108 firstPeakStart->attach( plot ); 108 109 … … 125 126 UsSensorPlot::~UsSensorPlot() { 126 127 free(dx); 127 free(dy); 128 for(int i=0;i<measures.count();i++) { 129 free(measures.at(i).dy); 130 } 128 131 } 129 132 … … 185 188 if (IsEnabled() == false || RefreshRate_ms() != period) 186 189 return; 190 191 measure_t measure; 192 measure.dy = (double *)malloc(nbSamples* sizeof(double)); 187 193 188 194 if (datasType == "float") { 189 195 float *data=(float*)*buf; 190 196 for (int i = 0; i < nbSamples; i++) { 191 dy[i]=data[i];197 measure.dy[i]=data[i]; 192 198 } 193 199 *buf += nbSamples*sizeof(float); … … 195 201 int8_t *data=(int8_t*)*buf; 196 202 for (int i = 0; i < nbSamples; i++) { 197 dy[i]=data[i];203 measure.dy[i]=data[i]; 198 204 } 199 205 *buf += nbSamples*sizeof(int8_t); … … 201 207 uint8_t *data=(uint8_t*)*buf; 202 208 for (int i = 0; i < nbSamples; i++) { 203 dy[i]=data[i];209 measure.dy[i]=data[i]; 204 210 } 205 211 *buf += nbSamples*sizeof(uint8_t); … … 207 213 int16_t *data=(int16_t*)*buf; 208 214 for (int i = 0; i < nbSamples; i++) { 209 dy[i]=data[i];215 measure.dy[i]=data[i]; 210 216 } 211 217 *buf += nbSamples*sizeof(int16_t); … … 213 219 uint16_t *data=(uint16_t*)*buf; 214 220 for (int i = 0; i < nbSamples; i++) { 215 dy[i]=data[i];221 measure.dy[i]=data[i]; 216 222 } 217 223 *buf += nbSamples*sizeof(uint16_t); … … 222 228 *buf += 4*sizeof(uint16_t); 223 229 224 firstPeakStart->setValue( QPointF( data[0], dy[data[0]] ) ); 225 firstPeakEnd->setValue( QPointF( data[1], dy[data[1]] ) ); 226 secondPeakStart->setValue( QPointF( data[2], dy[data[2]] ) ); 227 secondPeakEnd->setValue( QPointF( data[3], dy[data[3]] ) ); 230 measure.firstPeakStartIndex=data[0]; 231 measure.firstPeakEndIndex=data[1]; 232 measure.secondPeakStartIndex=data[2]; 233 measure.secondPeakEndIndex=data[3]; 234 measures.append(measure); 235 236 scrollbar->setRange(0,measures.count()-1); 237 if(scrolling) { 238 scrollbar->blockSignals(true);//block valuechanged signal 239 scrollbar->setValue(measures.count()-1); 240 scrollbar->blockSignals(false); 241 242 plotMeasure(measures.count()-1); 243 } 244 } 245 246 void UsSensorPlot::plotMeasure(int index) { 247 firstPeakStart->setValue( QPointF(measures.at(index).firstPeakStartIndex,measures.at(index).dy[measures.at(index).firstPeakStartIndex] ) ); 248 firstPeakEnd->setValue( QPointF(measures.at(index).firstPeakEndIndex,measures.at(index).dy[measures.at(index).firstPeakEndIndex] ) ); 249 secondPeakStart->setValue( QPointF(measures.at(index).secondPeakStartIndex,measures.at(index).dy[measures.at(index).secondPeakStartIndex] ) ); 250 secondPeakEnd->setValue( QPointF(measures.at(index).secondPeakEndIndex,measures.at(index).dy[measures.at(index).secondPeakEndIndex] ) ); 251 252 // Attach (don't copy) data 253 datas->setRawSamples(dx,measures.at(index).dy, nbSamples); 228 254 229 255 plot->replot(); 230 256 } 231 232 233 257 // context menu 234 258 void UsSensorPlot::mousePressEvent(QMouseEvent *event) { … … 241 265 a = menu->addAction("reset zoom"); 242 266 menu->addSeparator(); 243 244 267 245 268 appendmenu(menu); … … 254 277 } 255 278 } 279 280 void UsSensorPlot::scrollBarMoved(int value) { 281 if(value==scrollbar->maximum()) { 282 scrolling=true; 283 } else { 284 scrolling=false; 285 } 286 plotMeasure(value); 287 } -
trunk/tools/FlairGCS/src/UsSensorPlot.h
r221 r259 16 16 class QMouseEvent; 17 17 class QwtPlotMarker; 18 class QScrollBar; 18 19 19 20 class UsSensorPlot : public DataRemote { … … 33 34 void alignScales(void); 34 35 float xmin_orig, xmax_orig, ymin_orig, ymax_orig; 36 QScrollBar* scrollbar; 35 37 36 38 QwtPlotCurve *datas; 37 39 QwtPlotMarker *firstPeakStart,*firstPeakEnd,*secondPeakStart,*secondPeakEnd; 38 40 QString datasType; 39 bool datas_first_update;40 41 double *dx; 41 double *dy; 42 43 struct measure_t { 44 double *dy; 45 uint16_t firstPeakStartIndex; 46 uint16_t firstPeakEndIndex; 47 uint16_t secondPeakStartIndex; 48 uint16_t secondPeakEndIndex; 49 }; 50 QList<measure_t> measures; 51 52 42 53 uint32_t nbSamples; 54 bool scrolling; 43 55 44 56 bool eventFilter(QObject *, QEvent *); … … 46 58 void setXAxisScale(float xmin, float xmax); 47 59 void BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian); 60 void plotMeasure(int index); 61 62 private slots: 63 void scrollBarMoved(int value); 48 64 }; 49 65
Note:
See TracChangeset
for help on using the changeset viewer.