Skip to content

Commit

Permalink
Merge pull request #23 from lgolouz/develop
Browse files Browse the repository at this point in the history
merge with master
  • Loading branch information
lgolouz authored Oct 18, 2021
2 parents 77af37e + d4b1919 commit bdd96e5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
24 changes: 23 additions & 1 deletion qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,29 @@ ApplicationWindow {
TableViewColumn {
title: "#"
width: rightArea.width * 0.07
role: "blockNumber"
role: "block"
delegate: Item {
property bool blkSelected: styleData.value.blockSelected
property int blkNumber: styleData.value.blockNumber

Rectangle {
anchors.fill: parent
border.width: 0
color: parent.blkSelected ? "#A00000FF" : "transparent"
Text {
anchors.centerIn: parent
color: parent.parent.blkSelected ? "white" : "black"
text: blkNumber
}
}

MouseArea {
anchors.fill: parent
onClicked: {
WaveformParser.toggleBlockSelection(blkNumber - 1);
}
}
}
}

TableViewColumn {
Expand Down
31 changes: 21 additions & 10 deletions sources/core/waveformparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QDebug>
#include <QDateTime>
#include <QByteArray>
#include <QVariantMap>
#include <algorithm>

WaveformParser::WaveformParser(QObject* parent) :
Expand Down Expand Up @@ -229,7 +230,6 @@ void WaveformParser::parse(uint chNum)
if (it == parsed.end()) {
currentState = NO_MORE_DATA;
}

}

if (chNum == 0) {
Expand All @@ -247,12 +247,15 @@ void WaveformParser::saveTap(uint chNum, const QString& fileName)

auto& parsedData = mParsedData[chNum];
for (auto i = 0; i < parsedData.size(); ++i) {
if (i < mSelectedBlocks.size() && !mSelectedBlocks[i]) {
continue;
}

QByteArray b;
const uint16_t size = parsedData.at(i).data.size();
const auto& data { parsedData.at(i).data };
const uint16_t size = data.size();
b.append(reinterpret_cast<const char *>(&size), sizeof(size));
for (uint8_t c: parsedData.at(i).data) {
b.append(c);
}
b.append(reinterpret_cast<const char *>(data.data()), size);
f.write(b);
}

Expand All @@ -272,6 +275,16 @@ QVector<uint8_t> WaveformParser::getParsedWaveform(uint chNum) const
return mParsedWaveform[chNum];
}

void WaveformParser::toggleBlockSelection(int blockNum) {
if (blockNum < mSelectedBlocks.size()) {
auto& blk = mSelectedBlocks[blockNum];
blk = !blk;

emit parsedChannel0Changed();
emit parsedChannel1Changed();
}
}

int WaveformParser::getBlockDataStart(uint chNum, uint blockNum) const
{
if (chNum < mParsedData.size() && blockNum < mParsedData[chNum].size()) {
Expand Down Expand Up @@ -307,12 +320,12 @@ QVariantList WaveformParser::getParsedChannelData(uint chNum) const

QVariantList r;
const auto& ch = mParsedData[chNum];
uint blockNumber = 1;
uint blockNumber = 0;

for (const auto& i: ch) {
QVariantMap m;

m.insert("blockNumber", blockNumber++);
m.insert("block", QVariantMap { {"blockSelected", blockNumber < (unsigned) mSelectedBlocks.size() ? mSelectedBlocks[blockNumber] : (mSelectedBlocks.append(true), true)}, {"blockNumber", (++blockNumber, blockNumber)} });
if (i.data.size() > 0) {
auto d = i.data.at(0);
int blockType = -1;
Expand Down Expand Up @@ -345,9 +358,7 @@ QVariantList WaveformParser::getParsedChannelData(uint chNum) const
12, i.data.size())
};

for (auto idx = 2; idx < loopRange; ++idx) {
nameText += QChar(i.data.at(idx));
}
nameText = QByteArray((const char*) &i.data.data()[2], loopRange > 1 ? loopRange - 2 : 0);
}
m.insert("blockName", nameText);
m.insert("blockStatus", i.state == OK ? "Ok" : "Error");
Expand Down
2 changes: 2 additions & 0 deletions sources/core/waveformparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const uint8_t sequenceEnd = 0b00000001; //end of signal sequence
WavReader& mWavReader;
QMap<uint, QVector<uint8_t>> mParsedWaveform;
QMap<uint, QVector<DataBlock>> mParsedData;
mutable QVector<bool> mSelectedBlocks;

protected:
explicit WaveformParser(QObject* parent = nullptr);
Expand All @@ -129,6 +130,7 @@ const uint8_t sequenceEnd = 0b00000001; //end of signal sequence
void saveWaveform(uint chNum);
QVector<uint8_t> getParsedWaveform(uint chNum) const;

Q_INVOKABLE void toggleBlockSelection(int blockNum);
Q_INVOKABLE int getBlockDataStart(uint chNum, uint blockNum) const;
Q_INVOKABLE int getBlockDataEnd(uint chNum, uint blockNum) const;
Q_INVOKABLE int getPositionByAddress(uint chNum, uint blockNum, uint addr) const;
Expand Down
19 changes: 7 additions & 12 deletions sources/models/suspiciouspointsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ SuspiciousPointsModel::SuspiciousPointsModel(QObject* parent) : QObject(parent)
bool SuspiciousPointsModel::addSuspiciousPoint(uint idx)
{
qDebug() << QString("Adding suspicious point: %1").arg(idx);
for (auto i = 0; i < mSuspiciousPoints.size(); ++i) {
auto& p = mSuspiciousPoints[i];
if (p == idx) {
return false;
}
else if (p.toUInt() > idx) {
mSuspiciousPoints.insert(i, idx);
emit suspiciousPointsChanged();
emit sizeChanged();
return true;
}
const auto it { std::lower_bound(mSuspiciousPoints.begin(), mSuspiciousPoints.end(), idx, [](const QVariant& t1, uint t2) { return t1.toUInt() < t2; }) };
if (it == mSuspiciousPoints.end()) {
mSuspiciousPoints.append(idx);
} else if (idx == it->toUInt()) {
return false;
} else {
mSuspiciousPoints.insert(it, idx);
}

mSuspiciousPoints.append(idx);
emit suspiciousPointsChanged();
emit sizeChanged();
return true;
Expand Down

0 comments on commit bdd96e5

Please sign in to comment.