From b8c83bbfd75fbfbe885a4679ffcf073049e088de Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 14 Apr 2019 17:01:30 -0400 Subject: [PATCH] Fix parent for new graph window, fix empty graphs are impossible to selectively remove or edit, add associated signal to graphs so they bring up the proper signal in the list on the right in the editing window. --- re/graphingwindow.cpp | 18 +++++++++++++++++- re/graphingwindow.h | 1 + re/newgraphdialog.cpp | 33 +++++++++++++++++++++++++++++++-- re/newgraphdialog.h | 1 + 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/re/graphingwindow.cpp b/re/graphingwindow.cpp index b311623..7316fc5 100644 --- a/re/graphingwindow.cpp +++ b/re/graphingwindow.cpp @@ -1020,7 +1020,7 @@ void GraphingWindow::showParamsDialog(int idx = -1) { dbcHandler = DBCHandler::getReference(); - NewGraphDialog *thisDialog = new NewGraphDialog(dbcHandler); + NewGraphDialog *thisDialog = new NewGraphDialog(dbcHandler, this); if (idx > -1) { @@ -1096,7 +1096,23 @@ void GraphingWindow::createGraph(GraphParams ¶ms, bool createGraphParam) if (thisFrame.ID == params.ID) frameCache.append(thisFrame); } + //to fix weirdness where a graph that has no data won't be able to be edited, selected, or deleted properly + //we'll check for the condition that there is nothing to graph and add a single dummy frame to the cache + //that has all data bytes = 0. This allows the graph to be edited and deleted. No idea why you can't otherwise. + if (frameCache.count() == 0) + { + CANFrame dummy; + dummy.ID = params.ID; + dummy.bus = 0; + dummy.len = 8; + dummy.remote = false; + dummy.timestamp = 0; + for (int i = 0; i < 8; i++) dummy.data[i] = 0; + frameCache.append(dummy); + } + int numEntries = frameCache.count() / params.stride; + if (numEntries < 1) numEntries = 1; //could happen if stride is larger than frame count params.x.reserve(numEntries); params.y.reserve(numEntries); diff --git a/re/graphingwindow.h b/re/graphingwindow.h index cc79cbc..2d08220 100644 --- a/re/graphingwindow.h +++ b/re/graphingwindow.h @@ -26,6 +26,7 @@ public: QColor color; QCPGraph *ref; QString graphName; + DBC_SIGNAL *associatedSignal; //the below stuff is used for internal purposes only - code should be refactored so these can be private QVector x, y; double xbias; diff --git a/re/newgraphdialog.cpp b/re/newgraphdialog.cpp index 0297a39..1d0954e 100644 --- a/re/newgraphdialog.cpp +++ b/re/newgraphdialog.cpp @@ -32,6 +32,7 @@ NewGraphDialog::NewGraphDialog(DBCHandler *handler, QWidget *parent) : startBit = 0; dataLen = 1; + assocSignal = nullptr; loadMessages(); @@ -104,6 +105,9 @@ void NewGraphDialog::setParams(GraphParams ¶ms) ui->cbSigned->setChecked(params.isSigned); ui->cbIntel->setChecked(params.intelFormat); + assocSignal = params.associatedSignal; + qDebug() << "Signal addr: " << params.associatedSignal; + startBit = params.startBit; dataLen = params.numBits; ui->txtDataLen->setText(QString::number(dataLen)); @@ -113,6 +117,7 @@ void NewGraphDialog::setParams(GraphParams ¶ms) p.setColor(QPalette::Button, params.color); ui->colorSwatch->setPalette(p); loadMessages(); + loadSignals(0); drawBitfield(); } @@ -132,6 +137,8 @@ void NewGraphDialog::getParams(GraphParams ¶ms) params.startBit = startBit; params.numBits = dataLen; + params.associatedSignal = assocSignal; + //now catch stupidity and bring it to defaults if (params.mask == 0) params.mask = 0xFFFFFFFF; if (fabs(params.scale) < 0.00000001) params.scale = 1.0f; @@ -140,6 +147,7 @@ void NewGraphDialog::getParams(GraphParams ¶ms) void NewGraphDialog::loadMessages() { + DBC_MESSAGE *msg; ui->cbMessages->clear(); if (dbcHandler == NULL) return; if (dbcHandler->getFileCount() == 0) return; @@ -147,7 +155,16 @@ void NewGraphDialog::loadMessages() { for (int x = 0; x < dbcHandler->getFileByIdx(y)->messageHandler->getCount(); x++) { - ui->cbMessages->addItem(dbcHandler->getFileByIdx(y)->messageHandler->findMsgByIdx(x)->name); + msg = dbcHandler->getFileByIdx(y)->messageHandler->findMsgByIdx(x); + if (msg) + { + ui->cbMessages->addItem(msg->name); + if (assocSignal && msg->name == assocSignal->parentMessage->name) + { + ui->cbMessages->setCurrentIndex(ui->cbMessages->count() -1); + qDebug() << "Found my parent"; + } + } } } } @@ -160,12 +177,23 @@ void NewGraphDialog::loadSignals(int idx) //look it up based on index but by name is probably safer and this operation //is not time critical at all. DBC_MESSAGE *msg = dbcHandler->getFileByIdx(0)->messageHandler->findMsgByName(ui->cbMessages->currentText()); + DBC_SIGNAL *sig; if (msg == NULL) return; + ui->cbSignals->clear(); for (int x = 0; x < msg->sigHandler->getCount(); x++) { - ui->cbSignals->addItem(msg->sigHandler->findSignalByIdx(x)->name); + sig = msg->sigHandler->findSignalByIdx(x); + if (sig) + { + ui->cbSignals->addItem(sig->name); + if (assocSignal && sig->name == assocSignal->name) + { + ui->cbSignals->setCurrentIndex(ui->cbSignals->count() - 1); + qDebug() << "Found me"; + } + } } } @@ -242,4 +270,5 @@ void NewGraphDialog::copySignalToParamsUI() if (sig->valType == SIGNED_INT) ui->cbSigned->setChecked(true); else ui->cbSigned->setChecked(false); drawBitfield(); + assocSignal = sig; } diff --git a/re/newgraphdialog.h b/re/newgraphdialog.h index 365456d..1b8b20d 100644 --- a/re/newgraphdialog.h +++ b/re/newgraphdialog.h @@ -36,6 +36,7 @@ private: Ui::NewGraphDialog *ui; DBCHandler *dbcHandler; + DBC_SIGNAL *assocSignal; int startBit, dataLen; };