Skip to content

Commit

Permalink
Cleaned up all the UI elements and error checking for rebase and dupl…
Browse files Browse the repository at this point in the history
…icate
  • Loading branch information
Andy Huska committed Oct 9, 2022
1 parent b7491b8 commit 57a9d2f
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 112 deletions.
4 changes: 4 additions & 0 deletions connections/socketcand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ QString SocketCANd::decodeFrames(QString data, int busNum)
if(frameParsed.length() < 4)
{
qDebug() << "Received frame doesn't contain any data: " << data;

//todo
//this is not totally true, ive seen frames come through that look like < frame 1F020240 1664924225.371291 >
//if we found the closing token but theres no data then remove the message from the buffer
return data;
}

Expand Down
18 changes: 11 additions & 7 deletions dbc/dbcmaineditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,11 @@ void DBCMainEditor::onRebaseMessages()
node = dbcFile->findNodeByName(idString);
nodeRebaseEditor->setFileIdx(fileIdx);
nodeRebaseEditor->setNodeRef(node);
nodeRebaseEditor->refreshView();
nodeRebaseEditor->setModal(true);
nodeRebaseEditor->show();
if(nodeRebaseEditor->refreshView())
{
nodeRebaseEditor->setModal(true);
nodeRebaseEditor->show();
}
}

void DBCMainEditor::onDuplicateNode()
Expand All @@ -376,10 +378,12 @@ void DBCMainEditor::onDuplicateNode()
idString = firstCol->text(0).split(" ")[0];
node = dbcFile->findNodeByName(idString);
nodeDuplicateEditor->setFileIdx(fileIdx);
nodeDuplicateEditor->setNodeRef(node);
nodeDuplicateEditor->refreshView();
nodeDuplicateEditor->setModal(true);
nodeDuplicateEditor->show();
nodeDuplicateEditor->setNodeRef(node);
if(nodeDuplicateEditor->refreshView())
{
nodeDuplicateEditor->setModal(true);
nodeDuplicateEditor->show();
}
}

/*
Expand Down
131 changes: 82 additions & 49 deletions dbc/dbcnodeduplicateeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QSettings>
#include <QKeyEvent>
#include <QColorDialog>
#include <QMessageBox>
#include "helpwindow.h"
#include "utility.h"

Expand All @@ -18,58 +19,87 @@ DBCNodeDuplicateEditor::DBCNodeDuplicateEditor(QWidget *parent) :
dbcHandler = DBCHandler::getReference();
dbcNode = nullptr;

connect(ui->btnDuplicate, &QPushButton::pressed,
[=]()
connect(ui->btnDuplicate, &QPushButton::pressed,
[=]()
{
if (dbcNode == nullptr) return;
if (lowestMsgId > 0x1FFFFFFFul) return;

uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text());

if(newBase <= 0 || newBase > 0x1FFFFFFFul)
{
QMessageBox::question(this, "Invalid Address", "The new address is outside of the valid range.",
QMessageBox::Ok);
return;
}

if(newBase == lowestMsgId)
{
QMessageBox::question(this, "Invalid Address", "The new address is the same as the original.",
QMessageBox::Ok);
return;
}

uint rebaseDiff = newBase - lowestMsgId;

QList<DBC_MESSAGE*> messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode);
if(messagesForNode.count() == 0)
{
QMessageBox::question(this, "No Messages", "The node has no messages to duplicate.",
QMessageBox::Ok);
return;
}

if(ui->lineNodeName->text().isEmpty())
{
if (dbcNode == nullptr) return;
if (lowestMsgId > 0x1FFFFFFFul) return;
QMessageBox::question(this, "No Name", "The new node needs a name before it can be created.",
QMessageBox::Ok);
return;
}

QString newNodeName = ui->lineNodeName->text();
emit createNode(newNodeName);

uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text());
DBC_NODE *nodePtr = dbcFile->findNodeByName(newNodeName);

if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId)
if(nodePtr == nullptr)
{
QMessageBox::question(this, "Node Invalid", "There was an problem identifying the selected node.",
QMessageBox::Ok);
return;
}

for (int i=0; i<messagesForNode.count(); i++)
{
uint newMsgId = messagesForNode[i]->ID + rebaseDiff;

if(newMsgId < 0 || newMsgId > 0x1FFFFFFFul)
{
uint rebaseDiff = newBase - lowestMsgId;

QList<DBC_MESSAGE*> messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode);
if(messagesForNode.count() == 0)
{
return;
}

if(ui->lineNodeName->text().isEmpty())
{
//tell!
return;
}

QString newNodeName = ui->lineNodeName->text();
emit createNode(newNodeName);

DBC_NODE *nodePtr = dbcFile->findNodeByName(newNodeName);

if(nodePtr == nullptr)
{
//uhoh
return;
}

for (int i=0; i<messagesForNode.count(); i++)
{
uint newMsgId = messagesForNode[i]->ID + rebaseDiff;
emit cloneMessageToNode(nodePtr, messagesForNode[i], newMsgId);
}

dbcFile->setDirtyFlag();
emit nodeAdded();
QMessageBox::question(this, "Invalid Address Range", "The new starting address would cause a message to be outside of the valid address range.",
QMessageBox::Ok);
return;
}
});
}

connect(ui->btnCancel, &QPushButton::pressed,
[=]()
for (int i=0; i<messagesForNode.count(); i++)
{
uint newMsgId = messagesForNode[i]->ID + rebaseDiff;
emit cloneMessageToNode(nodePtr, messagesForNode[i], newMsgId);
}

dbcFile->setDirtyFlag();
emit nodeAdded();

this->close();

});
});

connect(ui->btnCancel, &QPushButton::pressed,
[=]()
{
this->close();
});

installEventFilter(this);
}
Expand Down Expand Up @@ -144,19 +174,20 @@ void DBCNodeDuplicateEditor::showEvent(QShowEvent* event)
refreshView();
}

void DBCNodeDuplicateEditor::refreshView()
bool DBCNodeDuplicateEditor::refreshView()
{
ui->lineNewBaseId->setText("");

if(dbcNode)
{
QList<DBC_MESSAGE*> messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode);
lowestMsgId = 0xFFFFFFFF;

if(messagesForNode.count() == 0)
{
//??

return false;
}

lowestMsgId = 0xFFFFFFFF;

for (int i=0; i<messagesForNode.count(); i++)
{
if(messagesForNode[i]->ID < lowestMsgId)
Expand All @@ -165,7 +196,9 @@ void DBCNodeDuplicateEditor::refreshView()

ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul));
ui->lineNodeName->setText(dbcNode->name + QString("_Copy"));

return true;
}

//generateSampleText();
return false;
}
2 changes: 1 addition & 1 deletion dbc/dbcnodeduplicateeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DBCNodeDuplicateEditor : public QDialog
void showEvent(QShowEvent*);
void setNodeRef(DBC_NODE *node);
void setFileIdx(int idx);
void refreshView();
bool refreshView();

signals:
void updatedTreeInfo(DBC_MESSAGE *msg);
Expand Down
114 changes: 68 additions & 46 deletions dbc/dbcnoderebaseeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QSettings>
#include <QKeyEvent>
#include <QColorDialog>
#include <QMessageBox>
#include "helpwindow.h"
#include "utility.h"

Expand All @@ -18,60 +19,78 @@ DBCNodeRebaseEditor::DBCNodeRebaseEditor(QWidget *parent) :
dbcHandler = DBCHandler::getReference();
dbcNode = nullptr;

connect(ui->btnDoRebase, &QPushButton::pressed,
[=]()
connect(ui->btnDoRebase, &QPushButton::pressed,
[=]()
{
if (dbcNode == nullptr)
{
if (dbcNode == nullptr) return;
if (lowestMsgId > 0x1FFFFFFFul) return;
QMessageBox::question(this, "Node Invalid", "There was an problem identifying the selected node.",
QMessageBox::Ok);
return;
}

uint newBase = Utility::ParseStringToNum(ui->lineEdit->text());
if (lowestMsgId > 0x1FFFFFFFul)
{
QMessageBox::question(this, "No Valid Messages", "The node has no valid messages to change.",
QMessageBox::Ok);
return;
}

if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId)
{
uint rebaseDiff = newBase - lowestMsgId;
uint newBase = Utility::ParseStringToNum(ui->lineNewBaseId->text());

QList<DBC_MESSAGE*> messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode);
if(messagesForNode.count() == 0)
{
return;
}
if(newBase <= 0 || newBase > 0x1FFFFFFFul)
{
QMessageBox::question(this, "Invalid Address", "The new address is outside of the valid range.",
QMessageBox::Ok);
return;
}

for (int i=0; i<messagesForNode.count(); i++)
{
messagesForNode[i]->ID += rebaseDiff;
emit updatedTreeInfo(messagesForNode[i]);
}
if(newBase == lowestMsgId)
{
QMessageBox::question(this, "Invalid Address", "The new address is the same as the original.",
QMessageBox::Ok);
return;
}

dbcFile->setDirtyFlag();
}
uint rebaseDiff = newBase - lowestMsgId;

QList<DBC_MESSAGE*> messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode);
if(messagesForNode.count() == 0)
{
QMessageBox::question(this, "No Messages", "The node has no messages to change.",
QMessageBox::Ok);
return;
}

for (int i=0; i<messagesForNode.count(); i++)
{
uint newMsgId = messagesForNode[i]->ID + rebaseDiff;

});
if(newMsgId < 0 || newMsgId > 0x1FFFFFFFul)
{
QMessageBox::question(this, "Invalid Address Range", "The new starting address would cause a message to be outside of the valid address range.",
QMessageBox::Ok);
return;
}
}

connect(ui->btnCancel, &QPushButton::pressed,
[=]()
for (int i=0; i<messagesForNode.count(); i++)
{
messagesForNode[i]->ID += rebaseDiff;
emit updatedTreeInfo(messagesForNode[i]);
}

dbcFile->setDirtyFlag();

});
this->close();

// connect(ui->lineOriginalBaseId, &QLineEdit::editingFinished,
// [=]()
// {
// if (dbcNode == nullptr) return;
// if (dbcNode->comment != ui->lineComment->text()) dbcFile->setDirtyFlag();
// dbcNode->comment = ui->lineComment->text();
// emit updatedTreeInfo(dbcNode);
// });
});

// connect(ui->lineMsgName, &QLineEdit::editingFinished,
// [=]()
// {
// if (dbcNode == nullptr) return;
// if (dbcNode->name != ui->lineMsgName->text()) dbcFile->setDirtyFlag();
// dbcNode->name = ui->lineMsgName->text();
// emit updatedTreeInfo(dbcNode);
// });
connect(ui->btnCancel, &QPushButton::pressed,
[=]()
{
this->close();
});

installEventFilter(this);
}
Expand Down Expand Up @@ -146,19 +165,20 @@ void DBCNodeRebaseEditor::showEvent(QShowEvent* event)
refreshView();
}

void DBCNodeRebaseEditor::refreshView()
bool DBCNodeRebaseEditor::refreshView()
{
ui->lineNewBaseId->setText("");

if(dbcNode)
{
QList<DBC_MESSAGE*> messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode);
lowestMsgId = 0xFFFFFFFF;

if(messagesForNode.count() == 0)
{
//??

return false;
}

lowestMsgId = 0xFFFFFFFF;

for (int i=0; i<messagesForNode.count(); i++)
{
if(messagesForNode[i]->ID < lowestMsgId)
Expand All @@ -167,7 +187,9 @@ void DBCNodeRebaseEditor::refreshView()

ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul));
ui->lineNodeName->setText(dbcNode->name);

return true;
}

//generateSampleText();
return false;
}
Loading

0 comments on commit 57a9d2f

Please sign in to comment.