Skip to content

Commit

Permalink
Merge pull request collin80#433 from viktorgino/ui-fixes
Browse files Browse the repository at this point in the history
Misc UI additions
  • Loading branch information
collin80 authored Nov 28, 2021
2 parents e48fac3 + 67b48aa commit f379248
Show file tree
Hide file tree
Showing 9 changed files with 711 additions and 276 deletions.
62 changes: 60 additions & 2 deletions re/flowviewwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,19 @@ FlowViewWindow::FlowViewWindow(const QVector<CANFrame> *frames, QWidget *parent)
connect(ui->txtTrigger5, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
connect(ui->txtTrigger6, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
connect(ui->txtTrigger7, SIGNAL(textEdited(QString)), this, SLOT(updateTriggerValues()));
connect(ui->graphRangeSlider, &QSlider::valueChanged, this, &FlowViewWindow::graphRangeChanged);
connect(ui->check_0, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);
connect(ui->check_1, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);
connect(ui->check_2, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);
connect(ui->check_3, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);
connect(ui->check_4, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);
connect(ui->check_5, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);
connect(ui->check_6, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);
connect(ui->check_7, &QCheckBox::stateChanged, this, &FlowViewWindow::changeGraphVisibility);

// ui->timelineSlider->setTracking(true);
connect(ui->timelineSlider, &QSlider::sliderPressed, this, &FlowViewWindow::btnPauseClick);
connect(ui->timelineSlider, &QSlider::valueChanged, this, &FlowViewWindow::gotoFrame);

// Using lambda expression to strip away the possible filter label before passing the ID to updateDetailsWindow
connect(ui->listFrameID, &QListWidget::currentTextChanged,
Expand Down Expand Up @@ -234,6 +247,21 @@ bool FlowViewWindow::eventFilter(QObject *obj, QEvent *event)
}
}

void FlowViewWindow::changeGraphVisibility(int state){
QCheckBox *sender = qobject_cast<QCheckBox *>(QObject::sender());
if(sender){
sender->objectName();
int graphId = sender->objectName().right(1).toInt();
for (int k = 0; k < 8; k++)
{
if (k == graphId && graphRef[k] && graphRef[k]->data()){
graphRef[k]->setVisible(state);
}
}

ui->graphView->replot();
}
}
void FlowViewWindow::gotCellClick(int x, int y)
{
int bitnum = (7-x) + (8 * y);
Expand All @@ -243,6 +271,11 @@ void FlowViewWindow::gotCellClick(int x, int y)
qDebug() << "Bit Num: " << bitnum << " Hex of trigger bits: " << QString::number(triggerBits, 16);
}

void FlowViewWindow::graphRangeChanged(int range) {
ui->rangeValue->setText(QString::number(range));
updateGraphLocation();
}

void FlowViewWindow::updateTriggerValues()
{
triggerValues[0] = Utility::ParseStringToNum(ui->txtTrigger0->text());
Expand Down Expand Up @@ -623,10 +656,19 @@ void FlowViewWindow::changeID(QString newID)
memcpy(refBytes, currBytes, 8);

updateDataView();
ui->check_0->setChecked(true);
ui->check_1->setChecked(true);
ui->check_2->setChecked(true);
ui->check_3->setChecked(true);
ui->check_4->setChecked(true);
ui->check_5->setChecked(true);
ui->check_6->setChecked(true);
ui->check_7->setChecked(true);
}

void FlowViewWindow::btnBackOneClick()
{
ui->cbLiveMode->setChecked(false);
playbackTimer->stop(); //pushing this button halts automatic playback
playbackActive = false;

Expand All @@ -636,20 +678,23 @@ void FlowViewWindow::btnBackOneClick()

void FlowViewWindow::btnPauseClick()
{
ui->cbLiveMode->setChecked(false);
playbackActive = false;
playbackTimer->stop();
updateDataView();
}

void FlowViewWindow::btnReverseClick()
{
ui->cbLiveMode->setChecked(false);
playbackActive = true;
playbackForward = false;
playbackTimer->start();
}

void FlowViewWindow::btnStopClick()
{
ui->cbLiveMode->setChecked(false);
playbackTimer->stop(); //pushing this button halts automatic playback
playbackActive = false;
currentPosition = 0;
Expand All @@ -664,13 +709,15 @@ void FlowViewWindow::btnStopClick()

void FlowViewWindow::btnPlayClick()
{
ui->cbLiveMode->setChecked(false);
playbackActive = true;
playbackForward = true;
playbackTimer->start();
}

void FlowViewWindow::btnFwdOneClick()
{
ui->cbLiveMode->setChecked(false);
playbackTimer->stop();
playbackActive = false;
updatePosition(true);
Expand Down Expand Up @@ -736,6 +783,9 @@ void FlowViewWindow::updateDataView()
ui->flowView->setReference(refBytes, false);
ui->flowView->updateData(currBytes, true);

ui->timelineSlider->setMaximum(frameCache.count() - 1);
ui->timelineSlider->setValue(currentPosition);

for (int i = 0; i < 8; i++)
{
if (currBytes[i] == triggerValues[i])
Expand All @@ -752,6 +802,13 @@ void FlowViewWindow::updateDataView()

}

void FlowViewWindow::gotoFrame(int frame) {
if (frameCache.count() >= frame) currentPosition = frame;
else currentPosition = 0;

if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].frameId(), frameCache[currentPosition].timeStamp().microSeconds() / 1000000.0);
}

void FlowViewWindow::updatePosition(bool forward)
{

Expand Down Expand Up @@ -795,14 +852,15 @@ void FlowViewWindow::updatePosition(bool forward)
memcpy(currBytes, frameCache.at(currentPosition).payload().constData(), 8);

if (ui->cbSync->checkState() == Qt::Checked) emit sendCenterTimeID(frameCache[currentPosition].frameId(), frameCache[currentPosition].timeStamp().microSeconds() / 1000000.0);
ui->timelineSlider->setValue(currentPosition);
}

void FlowViewWindow::updateGraphLocation()
{
if (frameCache.count() == 0) return;
int start = currentPosition - 5;
int start = currentPosition - ui->graphRangeSlider->value();
if (start < 0) start = 0;
int end = currentPosition + 5;
int end = currentPosition + ui->graphRangeSlider->value();
if (end >= frameCache.count()) end = frameCache.count() - 1;
if (ui->cbTimeGraph->isChecked())
{
Expand Down
5 changes: 5 additions & 0 deletions re/flowviewwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#define FLOWVIEWWINDOW_H

#include <QDialog>
#include <QLocale>
#include <QSlider>
#include "qcustomplot.h"
#include "can_structs.h"

Expand Down Expand Up @@ -38,6 +40,8 @@ private slots:
void gotCenterTimeID(int32_t ID, double timestamp);
void updateTriggerValues();
void gotCellClick(int x, int y);
void graphRangeChanged(int range);
void changeGraphVisibility(int state);

signals:
void sendCenterTimeID(uint32_t ID, double timestamp);
Expand Down Expand Up @@ -65,6 +69,7 @@ private slots:
void refreshIDList();
void updateFrameLabel();
void updatePosition(bool forward);
void gotoFrame(int frame);
void updateDataView();
void removeAllGraphs();
void createGraph(int);
Expand Down
38 changes: 37 additions & 1 deletion re/frameinfowindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ FrameInfoWindow::FrameInfoWindow(const QVector<CANFrame> *frames, QWidget *paren
connect(MainWindow::getReference(), &MainWindow::framesUpdated, this, &FrameInfoWindow::updatedFrames);
connect(ui->btnSave, &QAbstractButton::clicked, this, &FrameInfoWindow::saveDetails);

connect(ui->check_0, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);
connect(ui->check_1, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);
connect(ui->check_2, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);
connect(ui->check_3, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);
connect(ui->check_4, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);
connect(ui->check_5, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);
connect(ui->check_6, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);
connect(ui->check_7, &QCheckBox::stateChanged, this, &FrameInfoWindow::changeGraphVisibility);


ui->graphHistogram->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes |
QCP::iSelectLegend | QCP::iSelectPlottables);
Expand Down Expand Up @@ -631,7 +640,7 @@ void FrameInfoWindow::updateDetailsWindow(QString newID)
ui->graphBytes->clearGraphs();
for (int graphs = 0; graphs < 8; graphs++)
{
ui->graphBytes->addGraph();
graphRef[graphs] = ui->graphBytes->addGraph();
ui->graphBytes->graph()->setData(byteGraphX, byteGraphY[graphs]);
ui->graphBytes->graph()->setPen(bytePens[graphs]);
}
Expand All @@ -652,6 +661,15 @@ void FrameInfoWindow::updateDetailsWindow(QString newID)
ui->timeHistogram->axisRect()->setupFullAxesBox();
ui->timeHistogram->rescaleAxes();
ui->timeHistogram->replot();

ui->check_0->setChecked(true);
ui->check_1->setChecked(true);
ui->check_2->setChecked(true);
ui->check_3->setChecked(true);
ui->check_4->setChecked(true);
ui->check_5->setChecked(true);
ui->check_6->setChecked(true);
ui->check_7->setChecked(true);
}
else
{
Expand Down Expand Up @@ -726,6 +744,24 @@ void FrameInfoWindow::saveDetails()
}
}

void FrameInfoWindow::changeGraphVisibility(int state){
QCheckBox *sender = qobject_cast<QCheckBox *>(QObject::sender());
if(sender){
sender->objectName();
int graphId = sender->objectName().right(1).toInt();
for (int k = 0; k < 8; k++)
{
if (k == graphId && graphRef[k] && graphRef[k]->data()){
graphRef[k]->setVisible(state);
qDebug() << graphId << state << k;
}
}
qDebug() << graphId << state;

ui->graphBytes->replot();
}
}

void FrameInfoWindow::dumpNode(QTreeWidgetItem* item, QFile *file, int indent)
{
for (int i = 0; i < indent; i++) file->write("\t");
Expand Down
5 changes: 5 additions & 0 deletions re/frameinfowindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "bus_protocols/j1939_handler.h"
#include "dbc/dbchandler.h"

#include "qcustomplot.h"

namespace Ui {
class FrameInfoWindow;
}
Expand All @@ -26,6 +28,7 @@ private slots:
void updateDetailsWindow(QString);
void updatedFrames(int);
void saveDetails();
void changeGraphVisibility(int state);

private:
Ui::FrameInfoWindow *ui;
Expand All @@ -39,6 +42,8 @@ private slots:
static QPen bytePens[8];
DBCHandler *dbcHandler;

QCPGraph *graphRef[8];

void refreshIDList();
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
Expand Down
6 changes: 5 additions & 1 deletion re/sniffer/sniffermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ QVariant SnifferModel::data(const QModelIndex &index, int role) const
{
case tc::DELTA:
return QString::number(item->getDelta(), 'f');
case tc::FREQUENCY:
return QString("%1 hz").arg(qRound(1.00 / item->getDelta()));
case tc::ID:
return QString("%1").arg(item->getId(), 5, 16, QLatin1Char(' ')).toUpper();
return "0x" + QString("%1").arg(item->getId(), 5, 16, QLatin1Char(' ')).toUpper();
default:
break;
}
Expand Down Expand Up @@ -148,6 +150,8 @@ QVariant SnifferModel::headerData(int section, Qt::Orientation orientation, int
{
case tc::DELTA:
return QString("Delta");
case tc::FREQUENCY:
return QString("Frequency");
case tc::ID:
return QString("ID");
default:
Expand Down
38 changes: 20 additions & 18 deletions re/sniffer/snifferwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ void SnifferWindow::readSettings()
resize(settings.value("Sniffer/WindowSize", QSize(1100, 750)).toSize());
move(Utility::constrainedWindowPos(settings.value("Sniffer/WindowPos", QPoint(50, 50)).toPoint()));
ui->treeView->setColumnWidth(0, settings.value("Sniffer/DeltaColumn", 110).toUInt());
ui->treeView->setColumnWidth(1, settings.value("Sniffer/IDColumn", 70).toUInt());
ui->treeView->setColumnWidth(2, settings.value("Sniffer/Data0Column", 92).toUInt());
ui->treeView->setColumnWidth(3, settings.value("Sniffer/Data1Column", 92).toUInt());
ui->treeView->setColumnWidth(4, settings.value("Sniffer/Data2Column", 92).toUInt());
ui->treeView->setColumnWidth(5, settings.value("Sniffer/Data3Column", 92).toUInt());
ui->treeView->setColumnWidth(6, settings.value("Sniffer/Data4Column", 92).toUInt());
ui->treeView->setColumnWidth(7, settings.value("Sniffer/Data5Column", 92).toUInt());
ui->treeView->setColumnWidth(8, settings.value("Sniffer/Data6Column", 92).toUInt());
ui->treeView->setColumnWidth(9, settings.value("Sniffer/Data7Column", 92).toUInt());
ui->treeView->setColumnWidth(1, settings.value("Sniffer/FrequencyColumn", 110).toUInt());
ui->treeView->setColumnWidth(2, settings.value("Sniffer/IDColumn", 70).toUInt());
ui->treeView->setColumnWidth(3, settings.value("Sniffer/Data0Column", 92).toUInt());
ui->treeView->setColumnWidth(4, settings.value("Sniffer/Data1Column", 92).toUInt());
ui->treeView->setColumnWidth(5, settings.value("Sniffer/Data2Column", 92).toUInt());
ui->treeView->setColumnWidth(6, settings.value("Sniffer/Data3Column", 92).toUInt());
ui->treeView->setColumnWidth(7, settings.value("Sniffer/Data4Column", 92).toUInt());
ui->treeView->setColumnWidth(8, settings.value("Sniffer/Data5Column", 92).toUInt());
ui->treeView->setColumnWidth(9, settings.value("Sniffer/Data6Column", 92).toUInt());
ui->treeView->setColumnWidth(10, settings.value("Sniffer/Data7Column", 92).toUInt());
}
}

Expand All @@ -103,15 +104,16 @@ void SnifferWindow::writeSettings()
settings.setValue("Sniffer/WindowSize", size());
settings.setValue("Sniffer/WindowPos", pos());
settings.setValue("Sniffer/DeltaColumn", ui->treeView->columnWidth(0));
settings.setValue("Sniffer/IDColumn", ui->treeView->columnWidth(1));
settings.setValue("Sniffer/Data0Column", ui->treeView->columnWidth(2));
settings.setValue("Sniffer/Data1Column", ui->treeView->columnWidth(3));
settings.setValue("Sniffer/Data2Column", ui->treeView->columnWidth(4));
settings.setValue("Sniffer/Data3Column", ui->treeView->columnWidth(5));
settings.setValue("Sniffer/Data4Column", ui->treeView->columnWidth(6));
settings.setValue("Sniffer/Data5Column", ui->treeView->columnWidth(7));
settings.setValue("Sniffer/Data6Column", ui->treeView->columnWidth(8));
settings.setValue("Sniffer/Data7Column", ui->treeView->columnWidth(9));
settings.setValue("Sniffer/FrequencyColumn", ui->treeView->columnWidth(1));
settings.setValue("Sniffer/IDColumn", ui->treeView->columnWidth(2));
settings.setValue("Sniffer/Data0Column", ui->treeView->columnWidth(3));
settings.setValue("Sniffer/Data1Column", ui->treeView->columnWidth(4));
settings.setValue("Sniffer/Data2Column", ui->treeView->columnWidth(5));
settings.setValue("Sniffer/Data3Column", ui->treeView->columnWidth(6));
settings.setValue("Sniffer/Data4Column", ui->treeView->columnWidth(7));
settings.setValue("Sniffer/Data5Column", ui->treeView->columnWidth(8));
settings.setValue("Sniffer/Data6Column", ui->treeView->columnWidth(9));
settings.setValue("Sniffer/Data7Column", ui->treeView->columnWidth(10));
}
}

Expand Down
1 change: 1 addition & 0 deletions re/sniffer/snifferwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class snifferWindow;
enum tc
{
DELTA = 0,
FREQUENCY,
ID,
DATA_0,
DATA_1,
Expand Down
Loading

0 comments on commit f379248

Please sign in to comment.