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.
This commit is contained in:
Collin Kidder
2019-04-14 17:01:30 -04:00
parent 1ff3426627
commit b8c83bbfd7
4 changed files with 50 additions and 3 deletions
+17 -1
View File
@@ -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 &params, 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);
+1
View File
@@ -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<double> x, y;
double xbias;
+31 -2
View File
@@ -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 &params)
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 &params)
p.setColor(QPalette::Button, params.color);
ui->colorSwatch->setPalette(p);
loadMessages();
loadSignals(0);
drawBitfield();
}
@@ -132,6 +137,8 @@ void NewGraphDialog::getParams(GraphParams &params)
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 &params)
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;
}
+1
View File
@@ -36,6 +36,7 @@ private:
Ui::NewGraphDialog *ui;
DBCHandler *dbcHandler;
DBC_SIGNAL *assocSignal;
int startBit, dataLen;
};