# HG changeset patch # User Hasan Yavuz Ă–ZDERYA # Date 2018-05-22 15:46:18 # Node ID d92b6daade5d3531a7d8c092dc9e3af6d0227289 # Parent 68f79a7c6762f30544f7ac344734cc0fafeae662 plotting works, only demo is tested switching readers when demo is enabled breaks demo diff --git a/src/dataformatpanel.cpp b/src/dataformatpanel.cpp --- a/src/dataformatpanel.cpp +++ b/src/dataformatpanel.cpp @@ -47,8 +47,6 @@ DataFormatPanel::DataFormatPanel(QSerial ui->horizontalLayout->addWidget(bsReader.settingsWidget(), 1); connect(&bsReader, SIGNAL(numOfChannelsChanged(unsigned)), this, SIGNAL(numOfChannelsChanged(unsigned))); - connect(&bsReader, SIGNAL(samplesPerSecondChanged(unsigned)), - this, SIGNAL(samplesPerSecondChanged(unsigned))); // initalize reader selection buttons connect(ui->rbBinary, &QRadioButton::toggled, [this](bool checked) @@ -98,8 +96,6 @@ void DataFormatPanel::enableDemo(bool en if (enabled) { demoReader.enable(); - connect(&demoReader, &DemoReader::samplesPerSecondChanged, - this, &DataFormatPanel::samplesPerSecondChanged); emit sourceChanged(&demoReader); } else @@ -120,8 +116,6 @@ void DataFormatPanel::selectReader(Abstr disconnect(currentReader, 0, this, 0); connect(reader, SIGNAL(numOfChannelsChanged(unsigned)), this, SIGNAL(numOfChannelsChanged(unsigned))); - connect(reader, SIGNAL(samplesPerSecondChanged(unsigned)), - this, SIGNAL(samplesPerSecondChanged(unsigned))); // switch the settings widget ui->horizontalLayout->removeWidget(currentReader->settingsWidget()); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -206,7 +206,7 @@ MainWindow::MainWindow(QWidget *parent) connect(&serialPort, &QIODevice::aboutToClose, &recordPanel, &RecordPanel::onPortClose); - // init data arrays and plot + // init plot numOfSamples = plotControlPanel.numOfSamples(); stream.setNumSamples(numOfSamples); plotControlPanel.setChannelInfoModel(stream.infoModel()); @@ -234,6 +234,11 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->actionDemoMode, &QAction::toggled, plotMan, &PlotManager::showDemoIndicator); + // init stream connections + connect(&dataFormatPanel, &DataFormatPanel::sourceChanged, + this, &MainWindow::setStreamSource); + setStreamSource(dataFormatPanel.activeSource()); + // load default settings QSettings settings("serialplot", "serialplot"); loadAllSettings(&settings); @@ -341,6 +346,18 @@ void MainWindow::onPortToggled(bool open ui->actionDemoMode->setEnabled(!open); } +void MainWindow::setStreamSource(Source* source) +{ + // disconnect previous source + auto currentSource = stream.connectedSource(); + if (currentSource != nullptr) + { + currentSource->disconnect((Sink*) &stream); + } + // connect to new source + source->connectSink(&stream); +} + void MainWindow::clearPlot() { stream.clear(); diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -112,7 +112,7 @@ private: private slots: void onPortToggled(bool open); - + void setStreamSource(Source* source); void onNumOfSamplesChanged(int value); void clearPlot(); diff --git a/src/sink.cpp b/src/sink.cpp --- a/src/sink.cpp +++ b/src/sink.cpp @@ -55,7 +55,7 @@ void Sink::setNumChannels(unsigned nc, b void Sink::setSource(const Source* s) { - Q_ASSERT((source == NULL) != (s == NULL)); + Q_ASSERT((source == nullptr) != (s == nullptr)); source = s; } @@ -63,3 +63,8 @@ const Source* Sink::connectedSource() co { return source; } + +Source* Sink::connectedSource() +{ + return const_cast(static_cast(*this).connectedSource()); +} diff --git a/src/sink.h b/src/sink.h --- a/src/sink.h +++ b/src/sink.h @@ -39,8 +39,9 @@ public: /// an error. void disconnectFollower(Sink* sink); - /// Returns the connected source. `NULL` if it's not connected. + /// Returns the connected source. `nullptr` if it's not connected. const Source* connectedSource() const; + Source* connectedSource(); protected: /// Entry point for incoming data. Re-implementations should @@ -62,7 +63,7 @@ protected: private: QList followers; - const Source* source = NULL; ///< source that this sink is connected to + const Source* source = nullptr; ///< source that this sink is connected to bool _hasX; unsigned _numChannels; }; diff --git a/src/source.cpp b/src/source.cpp --- a/src/source.cpp +++ b/src/source.cpp @@ -25,14 +25,14 @@ Source::~Source() { for (auto sink : sinks) { - sink->setSource(NULL); + sink->setSource(nullptr); } } void Source::connectSink(Sink* sink) { Q_ASSERT(!sinks.contains(sink)); - Q_ASSERT(sink->connectedSource() == NULL); + Q_ASSERT(sink->connectedSource() == nullptr); sinks.append(sink); sink->setSource(this); @@ -44,7 +44,7 @@ void Source::disconnect(Sink* sink) Q_ASSERT(sinks.contains(sink)); Q_ASSERT(sink->connectedSource() == this); - sink->setSource(NULL); + sink->setSource(nullptr); sinks.removeOne(sink); } @@ -53,7 +53,7 @@ void Source::disconnectSinks() while (!sinks.isEmpty()) { auto sink = sinks.takeFirst(); - sink->setSource(NULL); + sink->setSource(nullptr); } } diff --git a/src/stream.cpp b/src/stream.cpp --- a/src/stream.cpp +++ b/src/stream.cpp @@ -157,6 +157,8 @@ void Stream::feedIn(const SamplePack& da } Sink::feedIn(data); + + emit dataAdded(); } void Stream::pause(bool paused)