diff --git a/src/dataformatpanel.cpp b/src/dataformatpanel.cpp --- a/src/dataformatpanel.cpp +++ b/src/dataformatpanel.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2017 Hasan Yavuz Özderya + Copyright © 2018 Hasan Yavuz Özderya This file is part of serialplot. @@ -21,29 +21,22 @@ #include "ui_dataformatpanel.h" #include -#include -#include #include #include "utils.h" #include "setting_defines.h" -#include "floatswap.h" -DataFormatPanel::DataFormatPanel(QSerialPort* port, - ChannelManager* channelMan, - DataRecorder* recorder, - QWidget *parent) : +DataFormatPanel::DataFormatPanel(QSerialPort* port, QWidget *parent) : QWidget(parent), ui(new Ui::DataFormatPanel), - bsReader(port, channelMan, recorder, this), - asciiReader(port, channelMan, recorder, this), - framedReader(port, channelMan, recorder, this), - demoReader(port, channelMan, recorder, this) + bsReader(port, this), + asciiReader(port, this), + framedReader(port, this), + demoReader(port, this) { ui->setupUi(this); serialPort = port; - _channelMan = channelMan; paused = false; demoEnabled = false; @@ -83,9 +76,14 @@ DataFormatPanel::~DataFormatPanel() delete ui; } -unsigned DataFormatPanel::numOfChannels() +unsigned DataFormatPanel::numChannels() const { - return currentReader->numOfChannels(); + return currentReader->numChannels(); +} + +Source* DataFormatPanel::activeSource() +{ + return ¤tReader; } void DataFormatPanel::pause(bool enabled) @@ -100,30 +98,19 @@ void DataFormatPanel::enableDemo(bool en if (enabled) { demoReader.enable(); - demoReader.recording = currentReader->recording; connect(&demoReader, &DemoReader::samplesPerSecondChanged, this, &DataFormatPanel::samplesPerSecondChanged); + emit sourceChanged(&demoreader); } else { demoReader.enable(false); disconnect(&demoReader, 0, this, 0); + emit sourceChanged(currentReader); } demoEnabled = enabled; } -void DataFormatPanel::startRecording() -{ - currentReader->recording = true; - if (demoEnabled) demoReader.recording = true; -} - -void DataFormatPanel::stopRecording() -{ - currentReader->recording = false; - if (demoEnabled) demoReader.recording = false; -} - void DataFormatPanel::selectReader(AbstractReader* reader) { currentReader->enable(false); @@ -152,6 +139,7 @@ void DataFormatPanel::selectReader(Abstr reader->recording = currentReader->recording; currentReader = reader; + emit sourceChanged(currentReader); } void DataFormatPanel::saveSettings(QSettings* settings) diff --git a/src/dataformatpanel.h b/src/dataformatpanel.h --- a/src/dataformatpanel.h +++ b/src/dataformatpanel.h @@ -1,5 +1,5 @@ /* - Copyright © 2017 Hasan Yavuz Özderya + Copyright © 2018 Hasan Yavuz Özderya This file is part of serialplot. @@ -28,8 +28,6 @@ #include #include -#include "framebuffer.h" -#include "channelmanager.h" #include "binarystreamreader.h" #include "asciireader.h" #include "demoreader.h" @@ -45,14 +43,13 @@ class DataFormatPanel : public QWidget Q_OBJECT public: - explicit DataFormatPanel(QSerialPort* port, - ChannelManager* channelMan, - DataRecorder* recorder, - QWidget* parent = 0); + explicit DataFormatPanel(QSerialPort* port, QWidget* parent = 0); ~DataFormatPanel(); /// Returns currently selected number of channels - unsigned numOfChannels(); + unsigned numChannels() const; + /// Returns active source (reader) + Source* activeSource(); /// Stores data format panel settings into a `QSettings` void saveSettings(QSettings* settings); /// Loads data format panel settings from a `QSettings`. @@ -62,17 +59,9 @@ public slots: void pause(bool); void enableDemo(bool); // demo shouldn't be enabled when port is open - /** - * @brief Starts sending data to recorder. - * - * @note recorder must have been started! - */ - void startRecording(); - - /// Stops recording. - void stopRecording(); - signals: + /// Active (selected) reader has changed. + void sourceChanged(Source* source); void numOfChannelsChanged(unsigned); void samplesPerSecondChanged(unsigned); @@ -80,7 +69,6 @@ private: Ui::DataFormatPanel *ui; QSerialPort* serialPort; - ChannelManager* _channelMan; BinaryStreamReader bsReader; AsciiReader asciiReader;