diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -36,6 +36,11 @@ #include "version.h" #include "floatswap.h" +#if defined(Q_OS_WIN) && defined(QT_STATIC) +#include +Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) +#endif + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -56,6 +61,9 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->actionExportCsv, &QAction::triggered, this, &MainWindow::onExportCsv); + QObject::connect(ui->actionQuit, &QAction::triggered, + this, &MainWindow::close); + QObject::connect(&portControl, &PortControl::portToggled, this, &MainWindow::onPortToggled); @@ -137,6 +145,7 @@ MainWindow::MainWindow(QWidget *parent) selectNumberFormat(NumberFormat_uint8); } + // init text view ui->ptTextView->setEnabled(ui->cbEnableTextView->isChecked()); // TODO: does this work in binary mode? (no new lines) @@ -146,6 +155,16 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->pbClearTextView, &QPushButton::clicked, ui->ptTextView, &QPlainTextEdit::clear); + + // Init sps (sample per second) counter + sampleCount = 0; + spsLabel.setText("0sps"); + spsLabel.setToolTip("samples per second (total of all channels)"); + ui->statusBar->addPermanentWidget(&spsLabel); + spsTimer.start(SPS_UPDATE_TIMEOUT * 1000); + QObject::connect(&spsTimer, &QTimer::timeout, + this, &MainWindow::spsTimerTimeout); + // Init demo mode demoCount = 0; demoTimer.setInterval(100); @@ -153,6 +172,18 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::demoTimerTimeout); QObject::connect(ui->actionDemoMode, &QAction::toggled, this, &MainWindow::enableDemo); + + { // init demo indicator + QwtText demoText(" DEMO RUNNING "); // looks better with spaces + demoText.setColor(QColor("white")); + demoText.setBackgroundBrush(Qt::darkRed); + demoText.setBorderRadius(4); + demoText.setRenderFlags(Qt::AlignLeft | Qt::AlignTop); + demoIndicator.setText(demoText); + demoIndicator.hide(); + demoIndicator.attach(ui->plot); + } + } MainWindow::~MainWindow() @@ -246,6 +277,13 @@ void MainWindow::onDataReadyASCII() while(serialPort.canReadLine()) { QByteArray line = serialPort.readLine(); + + // discard data if paused + if (ui->actionPause->isChecked()) + { + return; + } + line = line.trimmed(); if (ui->cbEnableTextView->isChecked()) @@ -372,6 +410,8 @@ void MainWindow::addChannelData(unsigned // update plot curves[channel]->setSamples(dataX, (*channelDataArray)); ui->plot->replot(); // TODO: replot after all channel data updated + + sampleCount += data.size(); } void MainWindow::clearPlot() @@ -564,6 +604,12 @@ bool MainWindow::isDemoRunning() return ui->actionDemoMode->isChecked(); } +void MainWindow::spsTimerTimeout() +{ + spsLabel.setText(QString::number(sampleCount/SPS_UPDATE_TIMEOUT) + "sps"); + sampleCount = 0; +} + void MainWindow::demoTimerTimeout() { demoCount++; @@ -588,6 +634,8 @@ void MainWindow::enableDemo(bool enabled { demoTimer.start(); ui->actionDemoMode->setChecked(true); + demoIndicator.show(); + ui->plot->replot(); } else { @@ -598,6 +646,8 @@ void MainWindow::enableDemo(bool enabled { demoTimer.stop(); ui->actionDemoMode->setChecked(false); + demoIndicator.hide(); + ui->plot->replot(); } }