MCPcopy Create free account
hub / github.com/analogdevicesinc/scopy / generateCsvData

Method generateCsvData

gui/src/plotwidget.cpp:432–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430PlotChannel *PlotWidget::selectedChannel() const { return m_selectedChannel; }
431
432QString PlotWidget::generateCsvData()
433{
434 QString result;
435 QTextStream out(&result);
436 out.setRealNumberNotation(QTextStream::FixedNotation);
437 out.setRealNumberPrecision(10);
438
439 QList<PlotChannel *> enabledChannels;
440 for(PlotChannel *ch : m_plotChannels) {
441 if(ch->isEnabled() && ch->curve() && ch->curve()->data() && ch->curve()->data()->size() > 0) {
442 enabledChannels.append(ch);
443 }
444 }
445
446 if(enabledChannels.isEmpty()) {
447 return result;
448 }
449
450 // Write header: X (unit), Ch1_Y (unit), Ch2_Y (unit), ...
451 QString xUnits = enabledChannels.first()->xAxis()->getUnits();
452 if(!xUnits.isEmpty()) {
453 out << "X (" << xUnits << ")";
454 } else {
455 out << "X";
456 }
457 for(PlotChannel *ch : enabledChannels) {
458 QString yUnits = ch->yAxis()->getUnits();
459 if(!yUnits.isEmpty()) {
460 out << "," << ch->name() << " (" << yUnits << ")";
461 } else {
462 out << "," << ch->name();
463 }
464 }
465 out << "\n";
466
467 size_t maxSize = 0;
468 for(PlotChannel *ch : enabledChannels) {
469 maxSize = std::max(maxSize, ch->curve()->data()->size());
470 }
471 for(size_t i = 0; i < maxSize; i++) {
472 // Use X from first channel
473 QwtSeriesData<QPointF> *firstData = enabledChannels.first()->curve()->data();
474 if(i < firstData->size()) {
475 out << firstData->sample(i).x();
476 } else {
477 out << "";
478 }
479
480 for(PlotChannel *ch : enabledChannels) {
481 QwtSeriesData<QPointF> *data = ch->curve()->data();
482 out << ",";
483 if(i < data->size()) {
484 out << data->sample(i).y();
485 }
486 }
487 out << "\n";
488 }
489

Callers 2

Calls 9

appendMethod · 0.80
getUnitsMethod · 0.80
sampleMethod · 0.80
isEnabledMethod · 0.45
curveMethod · 0.45
dataMethod · 0.45
xAxisMethod · 0.45
yAxisMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected