Files
@ a9d626540c2c
Branch filter:
Location: tempo-plotter/src/channelmanager.cpp - annotation
a9d626540c2c
3.8 KiB
text/x-c++hdr
implemented settings for framed reader
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 797666010f26 797666010f26 797666010f26 797666010f26 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 3ec20782037b 1a05d0ad46b0 797666010f26 3ec20782037b 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 797666010f26 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 1a05d0ad46b0 | /*
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 <http://www.gnu.org/licenses/>.
*/
#include "channelmanager.h"
#include <QStringList>
#include <QModelIndex>
ChannelManager::ChannelManager(unsigned numberOfChannels, unsigned numberOfSamples, QObject *parent) :
QObject(parent)
{
_numOfChannels = numberOfChannels;
_numOfSamples = numberOfSamples;
QStringList channelNamesList;
for (unsigned int i = 0; i < numberOfChannels; i++)
{
channelBuffers.append(new FrameBuffer(numberOfSamples));
channelNamesList << QString("Channel %1").arg(i+1);
}
_channelNames.setStringList(channelNamesList);
connect(&_channelNames, &QStringListModel::dataChanged,
this, &ChannelManager::onChannelNameDataChange);
}
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));
addChannelName(QString("Channel %1").arg(oldNum+i+1));
}
}
else if(number < oldNum)
{
// remove channels
for (unsigned int i = oldNum-1; i > number-1; i--)
{
delete channelBuffers.takeLast();
_channelNames.removeRow(i);
}
}
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);
}
FrameBuffer* ChannelManager::channelBuffer(unsigned channel)
{
return channelBuffers[channel];
}
QStringListModel* ChannelManager::channelNames()
{
return &_channelNames;
}
QString ChannelManager::channelName(unsigned channel)
{
return _channelNames.data(_channelNames.index(channel, 0), Qt::DisplayRole).toString();
}
void ChannelManager::setChannelName(unsigned channel, QString name)
{
_channelNames.setData(_channelNames.index(channel, 0), QVariant(name), Qt::DisplayRole);
}
void ChannelManager::addChannelName(QString name)
{
_channelNames.insertRow(_channelNames.rowCount());
setChannelName(_channelNames.rowCount()-1, name);
}
void ChannelManager::onChannelNameDataChange(const QModelIndex & topLeft,
const QModelIndex & bottomRight,
const QVector<int> & roles)
{
Q_UNUSED(roles);
int start = topLeft.row();
int end = bottomRight.row();
// TODO: maybe check `roles` parameter, can't think of a reason for current use case
for (int i = start; i <= end; i++)
{
emit channelNameChanged(i, channelName(i));
}
}
void ChannelManager::addChannelData(unsigned channel, double* data, unsigned size)
{
channelBuffer(channel)->addSamples(data, size);
}
|