diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ qt5_wrap_ui(UI_FILES src/commandpanel.ui src/commandwidget.ui src/dataformatpanel.ui + src/plotcontrolpanel.ui ) if (WIN32) @@ -87,6 +88,7 @@ add_executable(${PROGRAM_NAME} WIN32 src/commandwidget.cpp src/commandedit.cpp src/dataformatpanel.cpp + src/plotcontrolpanel.cpp src/tooltipfilter.cpp src/sneakylineedit.cpp src/channelmanager.cpp diff --git a/serialplot.pro b/serialplot.pro --- a/serialplot.pro +++ b/serialplot.pro @@ -54,7 +54,8 @@ SOURCES += \ src/tooltipfilter.cpp \ src/sneakylineedit.cpp \ src/channelmanager.cpp \ - src/framebufferseries.cpp + src/framebufferseries.cpp \ + src/plotcontrolpanel.cpp HEADERS += \ src/mainwindow.h \ @@ -79,7 +80,8 @@ HEADERS += \ src/tooltipfilter.h \ src/sneakylineedit.h \ src/channelmanager.h \ - src/framebufferseries.h + src/framebufferseries.h \ + src/plotcontrolpanel.h FORMS += \ src/mainwindow.ui \ @@ -88,7 +90,8 @@ FORMS += \ src/snapshotview.ui \ src/commandpanel.ui \ src/commandwidget.ui \ - src/dataformatpanel.ui + src/dataformatpanel.ui \ + src/plotcontrolpanel.ui INCLUDEPATH += qmake/ src/ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -44,14 +44,6 @@ Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) #endif -struct Range -{ - double rmin; - double rmax; -}; - -Q_DECLARE_METATYPE(Range); - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -65,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent) ui->setupUi(this); ui->tabWidget->insertTab(0, &portControl, "Port"); ui->tabWidget->insertTab(1, &dataFormatPanel, "Data Format"); + ui->tabWidget->insertTab(2, &plotControlPanel, "Plot"); ui->tabWidget->insertTab(3, &commandPanel, "Commands"); ui->tabWidget->setCurrentIndex(0); addToolBar(portControl.toolBar()); @@ -115,17 +108,11 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(&portControl, &PortControl::skipByteRequested, &dataFormatPanel, &DataFormatPanel::requestSkipByte); - QObject::connect(ui->spNumOfSamples, SELECT::OVERLOAD_OF(&QSpinBox::valueChanged), - this, &MainWindow::onNumOfSamplesChanged); - - QObject::connect(ui->cbAutoScale, &QCheckBox::toggled, - this, &MainWindow::onAutoScaleChecked); + connect(&plotControlPanel, &PlotControlPanel::numOfSamplesChanged, + this, &MainWindow::onNumOfSamplesChanged); - QObject::connect(ui->spYmin, SIGNAL(valueChanged(double)), - this, SLOT(onYScaleChanged())); - - QObject::connect(ui->spYmax, SIGNAL(valueChanged(double)), - this, SLOT(onYScaleChanged())); + connect(&plotControlPanel, &PlotControlPanel::scaleChanged, + ui->plot, &Plot::setAxis); QObject::connect(ui->actionClear, SIGNAL(triggered(bool)), this, SLOT(clearPlot())); @@ -137,13 +124,6 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(&(this->serialPort), SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(onPortError(QSerialPort::SerialPortError))); - // set limits for axis limit boxes - ui->spYmin->setRange((-1) * std::numeric_limits::max(), - std::numeric_limits::max()); - - ui->spYmax->setRange((-1) * std::numeric_limits::max(), - std::numeric_limits::max()); - // init data format and reader QObject::connect(&dataFormatPanel, &DataFormatPanel::dataAdded, ui->plot, &QwtPlot::replot); @@ -152,10 +132,10 @@ MainWindow::MainWindow(QWidget *parent) &dataFormatPanel, &DataFormatPanel::pause); // init data arrays and plot - numOfSamples = ui->spNumOfSamples->value(); + numOfSamples = plotControlPanel.numOfSamples(); unsigned numOfChannels = dataFormatPanel.numOfChannels(); - channelMan.setNumOfSamples(ui->spNumOfSamples->value()); + channelMan.setNumOfSamples(numOfSamples); channelMan.setNumOfChannels(dataFormatPanel.numOfChannels()); connect(&dataFormatPanel, &DataFormatPanel::numOfChannelsChanged, @@ -167,7 +147,7 @@ MainWindow::MainWindow(QWidget *parent) connect(&channelMan, &ChannelManager::channelNameChanged, this, &MainWindow::onChannelNameChanged); - ui->lvChannelNames->setModel(channelMan.channelNames()); + plotControlPanel.setChannelNamesModel(channelMan.channelNames()); // init curve list for (unsigned int i = 0; i < numOfChannels; i++) @@ -180,33 +160,8 @@ MainWindow::MainWindow(QWidget *parent) } // init auto scale - ui->plot->setAxis(ui->cbAutoScale->isChecked(), - ui->spYmin->value(), ui->spYmax->value()); - - // init scale range preset list - for (int nbits = 8; nbits <= 24; nbits++) // signed binary formats - { - int rmax = pow(2, nbits-1)-1; - int rmin = -rmax-1; - Range r = {double(rmin), double(rmax)}; - ui->cbRangePresets->addItem( - QString().sprintf("Signed %d bits %d to +%d", nbits, rmin, rmax), - QVariant::fromValue(r)); - } - for (int nbits = 8; nbits <= 24; nbits++) // unsigned binary formats - { - int rmax = pow(2, nbits)-1; - ui->cbRangePresets->addItem( - QString().sprintf("Unsigned %d bits %d to +%d", nbits, 0, rmax), - QVariant::fromValue(Range{0, double(rmax)})); - } - ui->cbRangePresets->addItem("-1 to +1", QVariant::fromValue(Range{-1, +1})); - ui->cbRangePresets->addItem("0 to +1", QVariant::fromValue(Range{0, +1})); - ui->cbRangePresets->addItem("-100 to +100", QVariant::fromValue(Range{-100, +100})); - ui->cbRangePresets->addItem("0 to +100", QVariant::fromValue(Range{0, +100})); - - QObject::connect(ui->cbRangePresets, SIGNAL(activated(int)), - this, SLOT(onRangeSelected())); + ui->plot->setAxis(plotControlPanel.autoScale(), + plotControlPanel.yMin(), plotControlPanel.yMax()); // Init sps (sample per second) counter spsLabel.setText("0sps"); @@ -386,40 +341,6 @@ void MainWindow::onChannelNameChanged(un } } -void MainWindow::onAutoScaleChecked(bool checked) -{ - if (checked) - { - ui->plot->setAxis(true); - ui->lYmin->setEnabled(false); - ui->lYmax->setEnabled(false); - ui->spYmin->setEnabled(false); - ui->spYmax->setEnabled(false); - } - else - { - ui->lYmin->setEnabled(true); - ui->lYmax->setEnabled(true); - ui->spYmin->setEnabled(true); - ui->spYmax->setEnabled(true); - - ui->plot->setAxis(false, ui->spYmin->value(), ui->spYmax->value()); - } -} - -void MainWindow::onYScaleChanged() -{ - ui->plot->setAxis(false, ui->spYmin->value(), ui->spYmax->value()); -} - -void MainWindow::onRangeSelected() -{ - Range r = ui->cbRangePresets->currentData().value(); - ui->spYmin->setValue(r.rmin); - ui->spYmax->setValue(r.rmax); - ui->cbAutoScale->setChecked(false); -} - void MainWindow::onSpsChanged(unsigned sps) { spsLabel.setText(QString::number(sps) + "sps"); diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -37,6 +37,7 @@ #include "portcontrol.h" #include "commandpanel.h" #include "dataformatpanel.h" +#include "plotcontrolpanel.h" #include "ui_about_dialog.h" #include "framebuffer.h" #include "channelmanager.h" @@ -77,6 +78,7 @@ private: CommandPanel commandPanel; DataFormatPanel dataFormatPanel; + PlotControlPanel plotControlPanel; SnapshotManager snapshotMan; @@ -88,9 +90,6 @@ private slots: void onPortError(QSerialPort::SerialPortError error); void onNumOfSamplesChanged(int value); - void onAutoScaleChecked(bool checked); - void onYScaleChanged(); - void onRangeSelected(); void onNumOfChannelsChanged(unsigned value); void onChannelNameChanged(unsigned channel, QString name); diff --git a/src/mainwindow.ui b/src/mainwindow.ui --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -51,158 +51,6 @@ false - - - Plot - - - - - - - - font-weight: bold; - - - Channel Names: - - - - - - - - 16777215 - 170 - - - - - - - - - - Qt::Vertical - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Number Of Samples: - - - - - - - length of X axis - - - false - - - 2 - - - 10000 - - - 1000 - - - - - - - Auto Scale Y Axis - - - true - - - - - - - false - - - Ymax - - - - - - - false - - - - 75 - 16777215 - - - - upper limit of Y axis - - - 1000.000000000000000 - - - 1000.000000000000000 - - - - - - - false - - - Ymin - - - - - - - false - - - - 75 - 16777215 - - - - lower limit of Y axis - - - 0.000000000000000 - - - - - - - - - - Select Range Preset: - - - - - - - Log diff --git a/src/plot.h b/src/plot.h --- a/src/plot.h +++ b/src/plot.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -39,7 +39,6 @@ class Plot : public QwtPlot public: Plot(QWidget* parent = 0); ~Plot(); - void setAxis(bool autoScaled, double yMin = 0, double yMax = 1); QList menuActions(); @@ -66,6 +65,7 @@ public slots: void showMinorGrid(bool show = true); void unzoom(); void darkBackground(bool enabled = true); + void setAxis(bool autoScaled, double yMin = 0, double yMax = 1); void flashSnapshotOverlay(); diff --git a/src/plotcontrolpanel.cpp b/src/plotcontrolpanel.cpp new file mode 100644 --- /dev/null +++ b/src/plotcontrolpanel.cpp @@ -0,0 +1,151 @@ +/* + Copyright © 2016 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#include "plotcontrolpanel.h" +#include "ui_plotcontrolpanel.h" + +#include + +/// Used for scale range selection combobox +struct Range +{ + double rmin; + double rmax; +}; + +Q_DECLARE_METATYPE(Range); + +PlotControlPanel::PlotControlPanel(QWidget *parent) : + QWidget(parent), + ui(new Ui::PlotControlPanel) +{ + ui->setupUi(this); + + // set limits for axis limit boxes + ui->spYmin->setRange((-1) * std::numeric_limits::max(), + std::numeric_limits::max()); + + ui->spYmax->setRange((-1) * std::numeric_limits::max(), + std::numeric_limits::max()); + + // connect signals + connect(ui->spNumOfSamples, SIGNAL(valueChanged(int)), + this, SIGNAL(numOfSamplesChanged(int))); + + connect(ui->cbAutoScale, &QCheckBox::toggled, + this, &PlotControlPanel::onAutoScaleChecked); + + connect(ui->spYmax, SIGNAL(valueChanged(double)), + this, SLOT(onYScaleChanged())); + + connect(ui->spYmin, SIGNAL(valueChanged(double)), + this, SLOT(onYScaleChanged())); + + // init scale range preset list + for (int nbits = 8; nbits <= 24; nbits++) // signed binary formats + { + int rmax = pow(2, nbits-1)-1; + int rmin = -rmax-1; + Range r = {double(rmin), double(rmax)}; + ui->cbRangePresets->addItem( + QString().sprintf("Signed %d bits %d to +%d", nbits, rmin, rmax), + QVariant::fromValue(r)); + } + for (int nbits = 8; nbits <= 24; nbits++) // unsigned binary formats + { + int rmax = pow(2, nbits)-1; + ui->cbRangePresets->addItem( + QString().sprintf("Unsigned %d bits %d to +%d", nbits, 0, rmax), + QVariant::fromValue(Range{0, double(rmax)})); + } + ui->cbRangePresets->addItem("-1 to +1", QVariant::fromValue(Range{-1, +1})); + ui->cbRangePresets->addItem("0 to +1", QVariant::fromValue(Range{0, +1})); + ui->cbRangePresets->addItem("-100 to +100", QVariant::fromValue(Range{-100, +100})); + ui->cbRangePresets->addItem("0 to +100", QVariant::fromValue(Range{0, +100})); + + QObject::connect(ui->cbRangePresets, SIGNAL(activated(int)), + this, SLOT(onRangeSelected())); +} + +PlotControlPanel::~PlotControlPanel() +{ + delete ui; +} + +unsigned PlotControlPanel::numOfSamples() +{ + return ui->spNumOfSamples->value(); +} + +void PlotControlPanel::onAutoScaleChecked(bool checked) +{ + if (checked) + { + // ui->plot->setAxis(true); + ui->lYmin->setEnabled(false); + ui->lYmax->setEnabled(false); + ui->spYmin->setEnabled(false); + ui->spYmax->setEnabled(false); + + emit scaleChanged(true); // autoscale + } + else + { + ui->lYmin->setEnabled(true); + ui->lYmax->setEnabled(true); + ui->spYmin->setEnabled(true); + ui->spYmax->setEnabled(true); + + // ui->plot->setAxis(false, ui->spYmin->value(), ui->spYmax->value()); + emit scaleChanged(false, ui->spYmin->value(), ui->spYmax->value()); + } +} + +void PlotControlPanel::onYScaleChanged() +{ + emit scaleChanged(false, ui->spYmin->value(), ui->spYmax->value()); +} + +bool PlotControlPanel::autoScale() +{ + return ui->cbAutoScale->isChecked(); +} + +double PlotControlPanel::yMax() +{ + return ui->spYmax->value(); +} + +double PlotControlPanel::yMin() +{ + return ui->spYmin->value(); +} + +void PlotControlPanel::onRangeSelected() +{ + Range r = ui->cbRangePresets->currentData().value(); + ui->spYmin->setValue(r.rmin); + ui->spYmax->setValue(r.rmax); + ui->cbAutoScale->setChecked(false); +} + +void PlotControlPanel::setChannelNamesModel(QAbstractItemModel * model) +{ + ui->lvChannelNames->setModel(model); +} diff --git a/src/plotcontrolpanel.h b/src/plotcontrolpanel.h new file mode 100644 --- /dev/null +++ b/src/plotcontrolpanel.h @@ -0,0 +1,58 @@ +/* + Copyright © 2016 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#ifndef PLOTCONTROLPANEL_H +#define PLOTCONTROLPANEL_H + +#include +#include + +namespace Ui { +class PlotControlPanel; +} + +class PlotControlPanel : public QWidget +{ + Q_OBJECT + +public: + explicit PlotControlPanel(QWidget *parent = 0); + ~PlotControlPanel(); + + unsigned numOfSamples(); + bool autoScale(); + double yMax(); + double yMin(); + + void setChannelNamesModel(QAbstractItemModel * model); + +signals: + void numOfSamplesChanged(int value); + void scaleChanged(bool autoScaled, double yMin = 0, double yMax = 1); + +private: + Ui::PlotControlPanel *ui; + +private slots: + void onAutoScaleChecked(bool checked); + void onYScaleChanged(); + void onRangeSelected(); +}; + +#endif // PLOTCONTROLPANEL_H diff --git a/src/plotcontrolpanel.ui b/src/plotcontrolpanel.ui new file mode 100644 --- /dev/null +++ b/src/plotcontrolpanel.ui @@ -0,0 +1,166 @@ + + + PlotControlPanel + + + + 0 + 0 + 590 + 183 + + + + Form + + + + + + + + font-weight: bold; + + + Channel Names: + + + + + + + + 16777215 + 170 + + + + + + + + + + Qt::Vertical + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Number Of Samples: + + + + + + + length of X axis + + + false + + + 2 + + + 10000 + + + 1000 + + + + + + + Auto Scale Y Axis + + + true + + + + + + + false + + + Ymax + + + + + + + false + + + + 75 + 16777215 + + + + upper limit of Y axis + + + 1000.000000000000000 + + + 1000.000000000000000 + + + + + + + false + + + Ymin + + + + + + + false + + + + 75 + 16777215 + + + + lower limit of Y axis + + + 0.000000000000000 + + + + + + + + + + Select Range Preset: + + + + + + + + + +