Flow view more or less works now. Some small tweaks are still coming.

This commit is contained in:
Collin Kidder
2015-05-12 22:34:19 -04:00
parent 2d989053e7
commit 60e5b323cf
6 changed files with 338 additions and 33 deletions
+59 -1
View File
@@ -9,6 +9,9 @@ CANDataGrid::CANDataGrid(QWidget *parent) :
ui(new Ui::CANDataGrid)
{
ui->setupUi(this);
memset(data, 0, 8);
memset(refData, 0, 8);
}
CANDataGrid::~CANDataGrid()
@@ -19,6 +22,9 @@ CANDataGrid::~CANDataGrid()
void CANDataGrid::paintEvent(QPaintEvent *event)
{
int x, y;
unsigned char prevByte, thisByte;
bool thisBit, prevBit;
QBrush blackBrush, whiteBrush, redBrush, greenBrush;
QPainter painter(this);
QRect viewport = painter.viewport();
@@ -29,6 +35,11 @@ void CANDataGrid::paintEvent(QPaintEvent *event)
int xSector = xSpan / 10;
int ySector = ySpan / 10;
blackBrush = QBrush(Qt::black);
whiteBrush = QBrush(Qt::white);
redBrush = QBrush(Qt::red);
greenBrush = QBrush(Qt::green);
//the whole thing is broken up into 100 chunks which are allocated as such:
//The entirety of the upper row is taken up by "BITS"
//The next row down skips two columns and then has 7 6 5 4 3 2 1 0
@@ -58,12 +69,59 @@ void CANDataGrid::paintEvent(QPaintEvent *event)
painter.drawText(viewport.left() + 10, viewport.top() + ySector * 7, "E");
painter.drawText(viewport.left() + 10, viewport.top() + ySector * 8, "S");
//now, color the bitfield by seeing if a given bit is freshly set/unset in the new data
//compared to the old. Bits that are not set in either are white, bits set in both are black
//bits that used to be set but now are unset are red, bits that used to be unset but now are set
//are green
for (y = 0; y < 8; y++)
{
thisByte = data[y];
prevByte = refData[y];
for (x = 0; x < 8; x++)
{
painter.drawRect(viewport.left() + (x+2) * xSector, viewport.top() + (y+2) * ySector, xSector, ySector);
thisBit = false;
prevBit = false;
if ((thisByte & (1 << x)) == (1 << x)) thisBit = true;
if ((prevByte & (1 << x)) == (1 << x)) prevBit = true;
if (thisBit)
{
if (prevBit)
{
painter.setBrush(blackBrush);
}
else
{
painter.setBrush(greenBrush);
}
}
else
{
if (prevBit)
{
painter.setBrush(redBrush);
}
else
{
painter.setBrush(whiteBrush);
}
}
//painter.fillRect(viewport.left() + (x+2) * xSector, viewport.top() + (y+2) * ySector, xSector, ySector, redBrush);
painter.drawRect(viewport.left() + (x+2) * xSector, viewport.top() + (y+2) * ySector, xSector, ySector);
}
}
}
void CANDataGrid::setReference(unsigned char *newRef, bool bUpdate = true)
{
memcpy(refData, newRef, 8);
if (bUpdate) this->update();
}
void CANDataGrid::updateData(unsigned char *newData, bool bUpdate = true)
{
memcpy(data, newData, 8); //on a 64 bit processor this is probably optimized to a single instruction
if (bUpdate) this->update();
}
+4
View File
@@ -15,9 +15,13 @@ public:
explicit CANDataGrid(QWidget *parent = 0);
~CANDataGrid();
void paintEvent(QPaintEvent *event);
void setReference(unsigned char *, bool);
void updateData(unsigned char *, bool);
private:
Ui::CANDataGrid *ui;
unsigned char refData[8];
unsigned char data[8];
};
#endif // CANDATAGRID_H
+207 -1
View File
@@ -1,14 +1,220 @@
#include "flowviewwindow.h"
#include "ui_flowviewwindow.h"
FlowViewWindow::FlowViewWindow(QWidget *parent) :
FlowViewWindow::FlowViewWindow(QList<CANFrame> *frames, QWidget *parent) :
QDialog(parent),
ui(new Ui::FlowViewWindow)
{
ui->setupUi(this);
modelFrames = frames;
playbackTimer = new QTimer();
currentPosition = 0;
playbackActive = false;
playbackForward = true;
memset(refBytes, 0, 8);
memset(currBytes, 0, 8);
refreshIDList();
updateFrameLabel();
connect(ui->btnBackOne, SIGNAL(clicked(bool)), this, SLOT(btnBackOneClick()));
connect(ui->btnPause, SIGNAL(clicked(bool)), this, SLOT(btnPauseClick()));
connect(ui->btnReverse, SIGNAL(clicked(bool)), this, SLOT(btnReverseClick()));
connect(ui->btnStop, SIGNAL(clicked(bool)), this, SLOT(btnStopClick()));
connect(ui->btnPlay, SIGNAL(clicked(bool)), this, SLOT(btnPlayClick()));
connect(ui->btnForwardOne, SIGNAL(clicked(bool)), this, SLOT(btnFwdOneClick()));
connect(ui->spinPlayback, SIGNAL(valueChanged(int)), this, SLOT(changePlaybackSpeed(int)));
connect(ui->cbLoopPlayback, SIGNAL(clicked(bool)), this, SLOT(changeLooping(bool)));
connect(ui->listFrameID, SIGNAL(currentTextChanged(QString)), this, SLOT(changeID(QString)));
connect(playbackTimer, SIGNAL(timeout()), this, SLOT(timerTriggered()));
playbackTimer->setInterval(ui->spinPlayback->value()); //set the timer to the default value of the control
}
FlowViewWindow::~FlowViewWindow()
{
delete ui;
playbackTimer->stop();
delete playbackTimer;
}
void FlowViewWindow::refreshIDList()
{
int id;
for (int i = 0; i < modelFrames->count(); i++)
{
id = modelFrames->at(i).ID;
if (!foundID.contains(id))
{
foundID.append(id);
QListWidgetItem* item = new QListWidgetItem(QString::number(id, 16).toUpper().rightJustified(4,'0'), ui->listFrameID);
}
}
//default is to sort in ascending order
ui->listFrameID->sortItems();
}
void FlowViewWindow::updateFrameLabel()
{
ui->lblNumFrames->setText(QString::number(currentPosition) + tr(" of ") + QString::number(frameCache.count()));
}
void FlowViewWindow::changeID(QString newID)
{
//parse the ID and then load up the frame cache with just messages with that ID.
int id = newID.toInt(NULL, 16);
frameCache.clear();
playbackTimer->stop();
playbackActive = false;
for (int x = 0; x < modelFrames->count(); x++)
{
CANFrame thisFrame = modelFrames->at(x);
if (thisFrame.ID == id)
{
frameCache.append(thisFrame);
}
}
currentPosition = 0;
updateFrameLabel();
}
void FlowViewWindow::btnBackOneClick()
{
playbackTimer->stop(); //pushing this button halts automatic playback
playbackActive = false;
updatePosition(false);
updateDataView();
}
void FlowViewWindow::btnPauseClick()
{
playbackActive = false;
playbackTimer->stop();
updateDataView();
}
void FlowViewWindow::btnReverseClick()
{
playbackActive = true;
playbackForward = false;
playbackTimer->start();
}
void FlowViewWindow::btnStopClick()
{
playbackTimer->stop(); //pushing this button halts automatic playback
playbackActive = false;
currentPosition = 0;
updateFrameLabel();
}
void FlowViewWindow::btnPlayClick()
{
playbackActive = true;
playbackForward = true;
playbackTimer->start();
}
void FlowViewWindow::btnFwdOneClick()
{
playbackTimer->stop();
playbackActive = false;
updatePosition(true);
updateDataView();
}
void FlowViewWindow::changePlaybackSpeed(int newSpeed)
{
playbackTimer->setInterval(newSpeed);
}
void FlowViewWindow::changeLooping(bool check)
{
}
void FlowViewWindow::timerTriggered()
{
if (!playbackActive)
{
playbackTimer->stop();
return;
}
if (playbackForward)
{
updatePosition(true);
}
else
{
updatePosition(false);
}
updateDataView();
if (!ui->cbLoopPlayback->isChecked())
{
if (currentPosition == 0) playbackActive = false;
if (currentPosition == (frameCache.count() - 1)) playbackActive = false;
}
}
void FlowViewWindow::updateDataView()
{
ui->txtCurr1->setText(QString::number(currBytes[0], 16).toUpper().rightJustified(2, '0'));
ui->txtCurr2->setText(QString::number(currBytes[1], 16).toUpper().rightJustified(2, '0'));
ui->txtCurr3->setText(QString::number(currBytes[2], 16).toUpper().rightJustified(2, '0'));
ui->txtCurr4->setText(QString::number(currBytes[3], 16).toUpper().rightJustified(2, '0'));
ui->txtCurr5->setText(QString::number(currBytes[4], 16).toUpper().rightJustified(2, '0'));
ui->txtCurr6->setText(QString::number(currBytes[5], 16).toUpper().rightJustified(2, '0'));
ui->txtCurr7->setText(QString::number(currBytes[6], 16).toUpper().rightJustified(2, '0'));
ui->txtCurr8->setText(QString::number(currBytes[7], 16).toUpper().rightJustified(2, '0'));
ui->txtRef1->setText(QString::number(refBytes[0], 16).toUpper().rightJustified(2, '0'));
ui->txtRef2->setText(QString::number(refBytes[1], 16).toUpper().rightJustified(2, '0'));
ui->txtRef3->setText(QString::number(refBytes[2], 16).toUpper().rightJustified(2, '0'));
ui->txtRef4->setText(QString::number(refBytes[3], 16).toUpper().rightJustified(2, '0'));
ui->txtRef5->setText(QString::number(refBytes[4], 16).toUpper().rightJustified(2, '0'));
ui->txtRef6->setText(QString::number(refBytes[5], 16).toUpper().rightJustified(2, '0'));
ui->txtRef7->setText(QString::number(refBytes[6], 16).toUpper().rightJustified(2, '0'));
ui->txtRef8->setText(QString::number(refBytes[7], 16).toUpper().rightJustified(2, '0'));
ui->flowView->setReference(refBytes, false);
ui->flowView->updateData(currBytes, true);
updateFrameLabel();
}
void FlowViewWindow::updatePosition(bool forward)
{
if (forward)
{
if (currentPosition < (frameCache.count() - 1)) currentPosition++;
else if (ui->cbLoopPlayback->isChecked()) currentPosition = 0;
}
else
{
if (currentPosition > 0) currentPosition--;
else if (ui->cbLoopPlayback->isChecked()) currentPosition = frameCache.count() - 1;
}
if (ui->cbAutoRef->isChecked())
{
memcpy(refBytes, currBytes, 8);
}
memcpy(currBytes, frameCache.at(currentPosition).data, 8);
}
+28 -1
View File
@@ -2,6 +2,7 @@
#define FLOWVIEWWINDOW_H
#include <QDialog>
#include "can_structs.h"
namespace Ui {
class FlowViewWindow;
@@ -12,11 +13,37 @@ class FlowViewWindow : public QDialog
Q_OBJECT
public:
explicit FlowViewWindow(QWidget *parent = 0);
explicit FlowViewWindow(QList<CANFrame> *frames, QWidget *parent = 0);
~FlowViewWindow();
private slots:
void btnBackOneClick();
void btnPauseClick();
void btnReverseClick();
void btnStopClick();
void btnPlayClick();
void btnFwdOneClick();
void changePlaybackSpeed(int newSpeed);
void changeLooping(bool check);
void timerTriggered();
void changeID(QString);
private:
Ui::FlowViewWindow *ui;
QList<int> foundID;
QList<CANFrame> frameCache;
QList<CANFrame> *modelFrames;
unsigned char refBytes[8];
unsigned char currBytes[8];
int currentPosition;
QTimer *playbackTimer;
bool playbackActive;
bool playbackForward;
void refreshIDList();
void updateFrameLabel();
void updatePosition(bool forward);
void updateDataView();
};
#endif // FLOWVIEWWINDOW_H
+38 -28
View File
@@ -32,7 +32,7 @@
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidget">
<widget class="QListWidget" name="listFrameID">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
@@ -62,7 +62,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="btnBackOne">
<property name="text">
<string/>
</property>
@@ -73,7 +73,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="btnStop">
<property name="text">
<string/>
</property>
@@ -84,7 +84,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="btnForwardOne">
<property name="text">
<string/>
</property>
@@ -99,7 +99,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="pushButton_6">
<widget class="QPushButton" name="btnReverse">
<property name="text">
<string/>
</property>
@@ -110,7 +110,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">
<widget class="QPushButton" name="btnPause">
<property name="text">
<string/>
</property>
@@ -121,7 +121,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_4">
<widget class="QPushButton" name="btnPlay">
<property name="text">
<string/>
</property>
@@ -147,10 +147,20 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox"/>
<widget class="QSpinBox" name="spinPlayback">
<property name="maximum">
<number>5000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>25</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="cbLoopPlayback">
<property name="text">
<string>Loop Playback</string>
</property>
@@ -170,7 +180,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="lblNumFrames">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -186,7 +196,7 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<widget class="QCheckBox" name="cbCapture">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -216,7 +226,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="checkBox_3">
<widget class="QCheckBox" name="cbAutoRef">
<property name="text">
<string>Auto Reference</string>
</property>
@@ -269,7 +279,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLineEdit" name="lineEdit_4">
<widget class="QLineEdit" name="txtRef1">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -297,7 +307,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_3">
<widget class="QLineEdit" name="txtRef2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -325,7 +335,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2">
<widget class="QLineEdit" name="txtRef3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -353,7 +363,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="txtRef4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -417,7 +427,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLineEdit" name="lineEdit_6">
<widget class="QLineEdit" name="txtRef5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -439,7 +449,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_7">
<widget class="QLineEdit" name="txtRef6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -461,7 +471,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_8">
<widget class="QLineEdit" name="txtRef7">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -483,7 +493,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_5">
<widget class="QLineEdit" name="txtRef8">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -556,7 +566,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLineEdit" name="lineEdit_12">
<widget class="QLineEdit" name="txtCurr1">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -578,7 +588,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_11">
<widget class="QLineEdit" name="txtCurr2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -600,7 +610,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_10">
<widget class="QLineEdit" name="txtCurr3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -622,7 +632,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_9">
<widget class="QLineEdit" name="txtCurr4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -680,7 +690,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLineEdit" name="lineEdit_16">
<widget class="QLineEdit" name="txtCurr5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -702,7 +712,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_15">
<widget class="QLineEdit" name="txtCurr6">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -724,7 +734,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_14">
<widget class="QLineEdit" name="txtCurr7">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
@@ -746,7 +756,7 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_13">
<widget class="QLineEdit" name="txtCurr8">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
+1 -1
View File
@@ -626,7 +626,7 @@ void MainWindow::showFlowViewWindow()
{
if (!flowViewWindow)
{
flowViewWindow = new FlowViewWindow();
flowViewWindow = new FlowViewWindow(model->getListReference());
}
flowViewWindow->show();