diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp
deleted file mode 100644
--- a/src/channelmanager.cpp
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- Copyright © 2017 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
-
-#include
-
-#include "channelmanager.h"
-#include "setting_defines.h"
-
-ChannelManager::ChannelManager(unsigned numberOfChannels, unsigned numberOfSamples, QObject *parent) :
- QObject(parent),
- _infoModel(numberOfChannels)
-{
- _numOfChannels = numberOfChannels;
- _numOfSamples = numberOfSamples;
- _paused = false;
-
- for (unsigned int i = 0; i < numberOfChannels; i++)
- {
- channelBuffers.append(new FrameBuffer(numberOfSamples));
- }
-
- connect(&_infoModel, &ChannelInfoModel::dataChanged,
- this, &ChannelManager::onChannelInfoChanged);
-}
-
-ChannelManager::~ChannelManager()
-{
- for (auto buffer : channelBuffers)
- {
- delete buffer;
- }
-}
-
-unsigned ChannelManager::numOfChannels()
-{
- return channelBuffers.size();
-}
-
-unsigned ChannelManager::numOfSamples()
-{
- return _numOfSamples;
-}
-
-void ChannelManager::setNumOfChannels(unsigned number)
-{
- unsigned int oldNum = channelBuffers.size();
-
- if (number > oldNum)
- {
- // add new channels
- for (unsigned int i = 0; i < number - oldNum; i++)
- {
- channelBuffers.append(new FrameBuffer(_numOfSamples));
- }
- }
- else if(number < oldNum)
- {
- // remove channels
- for (unsigned int i = oldNum-1; i > number-1; i--)
- {
- delete channelBuffers.takeLast();
- }
- }
-
- _numOfChannels = number;
- _infoModel.setNumOfChannels(number);
-
- emit numOfChannelsChanged(number);
-}
-
-void ChannelManager::setNumOfSamples(unsigned number)
-{
- _numOfSamples = number;
-
- for (int ci = 0; ci < channelBuffers.size(); ci++)
- {
- channelBuffers[ci]->resize(_numOfSamples);
- }
-
- emit numOfSamplesChanged(number);
-}
-
-void ChannelManager::pause(bool paused)
-{
- _paused = paused;
-}
-
-FrameBuffer* ChannelManager::channelBuffer(unsigned channel)
-{
- return channelBuffers[channel];
-}
-
-ChannelInfoModel* ChannelManager::infoModel()
-{
- return &_infoModel;
-}
-
-QString ChannelManager::channelName(unsigned channel)
-{
- return _infoModel.data(_infoModel.index(channel, ChannelInfoModel::COLUMN_NAME),
- Qt::DisplayRole).toString();
-}
-
-void ChannelManager::onChannelInfoChanged(const QModelIndex & topLeft,
- const QModelIndex & bottomRight,
- const QVector & roles)
-{
- int start = topLeft.row();
- int end = bottomRight.row();
- int col = topLeft.column();
-
- for (int ci = start; ci <= end; ci++)
- {
- for (auto role : roles)
- {
- switch (role)
- {
- case Qt::EditRole:
- if (col == ChannelInfoModel::COLUMN_NAME)
- {
- emit channelNameChanged(ci, channelName(ci));
- }
- break;
- case Qt::ForegroundRole:
- if (col == ChannelInfoModel::COLUMN_NAME)
- {
- // TODO: emit channel color changed
- }
- break;
- case Qt::CheckStateRole:
- if (col == ChannelInfoModel::COLUMN_VISIBILITY)
- {
- // TODO: emit visibility
- }
- break;
- }
- }
- // emit channelNameChanged(i, channelName(i));
- }
-}
-
-void ChannelManager::addData(double* data, unsigned size)
-{
- Q_ASSERT(size % _numOfChannels == 0);
-
- if (_paused) return;
-
- int n = size / _numOfChannels;
- for (unsigned ci = 0; ci < _numOfChannels; ci++)
- {
- channelBuffers[ci]->addSamples(&data[ci*n], n);
- }
-
- emit dataAdded();
-}
-
-void ChannelManager::saveSettings(QSettings* settings)
-{
- _infoModel.saveSettings(settings);
-}
-
-void ChannelManager::loadSettings(QSettings* settings)
-{
- _infoModel.loadSettings(settings);
-}
diff --git a/src/channelmanager.h b/src/channelmanager.h
deleted file mode 100644
--- a/src/channelmanager.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- Copyright © 2017 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 CHANNELMANAGER_H
-#define CHANNELMANAGER_H
-
-#include
-#include
-#include
-#include
-#include
-
-#include "framebuffer.h"
-#include "channelinfomodel.h"
-
-class ChannelManager : public QObject
-{
- Q_OBJECT
-public:
- explicit ChannelManager(unsigned numberOfChannels, unsigned numberOfSamples, QObject *parent = 0);
- ~ChannelManager();
-
- unsigned numOfChannels();
- unsigned numOfSamples();
- FrameBuffer* channelBuffer(unsigned channel);
- QString channelName(unsigned channel);
- /// Stores channel names into a `QSettings`
- void saveSettings(QSettings* settings);
- /// Loads channel names from a `QSettings`.
- void loadSettings(QSettings* settings);
- /// Returns a model that manages channel information (name, color etc)
- ChannelInfoModel* infoModel();
-
-signals:
- void numOfChannelsChanged(unsigned value);
- void numOfSamplesChanged(unsigned value);
- void channelNameChanged(unsigned channel, QString name);
- void dataAdded(); ///< emitted when data added to channel man.
-
-public slots:
- void setNumOfChannels(unsigned number);
- void setNumOfSamples(unsigned number);
- /**
- * Add data for all channels.
- *
- * All channels data is provided in a single array which contains equal
- * number of samples for all channels. Structure is as shown below:
- *
- * [CH0_SMP0, CH0_SMP1 ... CH0_SMPN, CH1_SMP0, CH1_SMP1, ... , CHN_SMPN]
- *
- * @param data samples for all channels
- * @param size size of `data`, must be multiple of `numOfChannels`
- */
- void addData(double* data, unsigned size);
-
- /// When paused `addData` does nothing.
- void pause(bool paused);
-
-private:
- unsigned _numOfChannels;
- unsigned _numOfSamples;
- bool _paused;
- QList channelBuffers;
- // QStringListModel _channelNames;
- ChannelInfoModel _infoModel;
-
-private slots:
- void onChannelInfoChanged(const QModelIndex & topLeft,
- const QModelIndex & bottomRight,
- const QVector & roles = QVector ());
-};
-
-#endif // CHANNELMANAGER_H
diff --git a/src/framebuffer.cpp b/src/framebuffer.cpp
deleted file mode 100644
--- a/src/framebuffer.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- Copyright © 2017 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 "framebuffer.h"
-
-FrameBuffer::FrameBuffer(size_t size)
-{
- _size = size;
- data = new double[_size]();
- headIndex = 0;
-
- brInvalid = false;
- _brCache.setCoords(0, 0, size, 0);
-}
-
-FrameBuffer::~FrameBuffer()
-{
- delete[] data;
-}
-
-void FrameBuffer::resize(size_t size)
-{
- int offset = size - _size;
- if (offset == 0) return;
-
- double* newData = new double[size];
-
- // move data to new array
- int fill_start = offset > 0 ? offset : 0;
-
- for (int i = fill_start; i < int(size); i++)
- {
- newData[i] = sample(i - offset);
- }
-
- // fill the beginning of the new data
- if (fill_start > 0)
- {
- for (int i = 0; i < fill_start; i++)
- {
- newData[i] = 0;
- }
- }
-
- // data is ready, clean and re-point
- delete data;
- data = newData;
- headIndex = 0;
- _size = size;
-
- // invalidate bounding rectangle
- brInvalid = true;
-}
-
-void FrameBuffer::addSamples(double* samples, size_t size)
-{
- unsigned shift = size;
- if (shift < _size)
- {
- unsigned x = _size - headIndex; // distance of `head` to end
-
- if (shift <= x) // there is enough room at the end of array
- {
- for (size_t i = 0; i < shift; i++)
- {
- data[i+headIndex] = samples[i];
- }
-
- if (shift == x) // we used all the room at the end
- {
- headIndex = 0;
- }
- else
- {
- headIndex += shift;
- }
- }
- else // there isn't enough room
- {
- for (size_t i = 0; i < x; i++) // fill the end part
- {
- data[i+headIndex] = samples[i];
- }
- for (size_t i = 0; i < (shift-x); i++) // continue from the beginning
- {
- data[i] = samples[i+x];
- }
- headIndex = shift-x;
- }
- }
- else // number of new samples equal or bigger than current size
- {
- int x = shift - _size;
- for (size_t i = 0; i < _size; i++)
- {
- data[i] = samples[i+x];
- }
- headIndex = 0;
- }
-
- // invalidate cache
- brInvalid = true;
-}
-
-void FrameBuffer::clear()
-{
- for (size_t i=0; i < _size; i++) data[i] = 0.;
-
- _brCache.setCoords(0, 0, _size, 0);
-}
-
-size_t FrameBuffer::size() const
-{
- return _size;
-}
-
-QRectF FrameBuffer::boundingRect() const
-{
- if (brInvalid) updateBoundingRect();
- return _brCache;
-}
-
-void FrameBuffer::updateBoundingRect() const
-{
- double minValue = data[0];
- double maxValue = data[0];
- for (size_t i = 0; i < _size; i++)
- {
- if (data[i] > maxValue)
- {
- maxValue = data[i];
- }
- else if (data[i] < minValue)
- {
- minValue = data[i];
- }
- }
- _brCache.setTop(minValue);
- _brCache.setBottom(maxValue);
-
- brInvalid = false;
-}
-
-double FrameBuffer::sample(size_t i) const
-{
- size_t index = headIndex + i;
- if (index >= _size) index -= _size;
- return data[index];
-}
diff --git a/src/framebuffer.h b/src/framebuffer.h
deleted file mode 100644
--- a/src/framebuffer.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- Copyright © 2017 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 FRAMEBUFFER_H
-#define FRAMEBUFFER_H
-
-#include
-#include
-
-class FrameBuffer
-{
-public:
- FrameBuffer(size_t size);
- ~FrameBuffer();
-
- void resize(size_t size);
- void addSamples(double* samples, size_t size);
- void clear(); // fill 0
-
- // QwtSeriesData related implementations
- size_t size() const;
- QRectF boundingRect() const;
- double sample(size_t i) const;
-
-private:
- size_t _size; // size of `data`
- double* data;
- size_t headIndex; // indicates the actual `0` index of the ring buffer
-
- mutable bool brInvalid; ///< Indicates that bounding rectangle needs to be re-calculated
- mutable QRectF _brCache; ///< Cache for boundingRect()
- void updateBoundingRect() const; ///< Updates bounding rectangle cache
-};
-
-#endif // FRAMEBUFFER_H