Skip to content

Commit

Permalink
Fix for DBC editor bugs that crept in during conversion to qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
collin80 committed Oct 31, 2024
1 parent d710753 commit de83dc6
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 22 deletions.
12 changes: 12 additions & 0 deletions dbc/dbchandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ bool DBCMessageHandler::addMessage(DBC_MESSAGE *msg)
return true;
}

bool DBCMessageHandler::changeMessageID(DBC_MESSAGE *msg, quint32 oldID)
{
//remove existing entry, add new entry with proper ID mapping
if (messages.contains(oldID))
{
messages.insert(msg->ID, msg);
messages.remove(oldID);
return true;
}
return false;
}

bool DBCMessageHandler::removeMessage(uint32_t ID)
{
if (messages.count() == 0) return false;
Expand Down
1 change: 1 addition & 0 deletions dbc/dbchandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DBCMessageHandler: public QObject
QList<DBC_MESSAGE*> findMsgsByNode(DBC_NODE *node);
QList<DBC_MESSAGE*> getMsgsAsList();
bool addMessage(DBC_MESSAGE *msg);
bool changeMessageID(DBC_MESSAGE *msg, quint32 oldID);
bool removeMessage(uint32_t ID);
bool removeMessage(QString name);
void removeAllMessages();
Expand Down
60 changes: 48 additions & 12 deletions dbc/dbcmaineditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
idString = firstCol->text(0).split(" ")[0];
msgID = static_cast<uint32_t>(Utility::ParseStringToNum(idString));
msg = dbcFile->messageHandler->findMsgByID(msgID);
//msg = itemToMessage[firstCol];
msgEditor->setMessageRef(msg);
msgEditor->setFileIdx(fileIdx);
//msgEditor->setWindowModality(Qt::WindowModal);
Expand All @@ -296,6 +297,7 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
if (nameString.contains("(")) nameString = nameString.split(" ")[1];
else nameString = nameString.split(" ")[0];
sig = msg->sigHandler->findSignalByName(nameString);
//sig = itemToSignal[firstCol];
if (sig)
{
sigEditor->setSignalRef(sig);
Expand Down Expand Up @@ -494,8 +496,14 @@ void DBCMainEditor::updatedNode(DBC_NODE *node)
else qDebug() << "That node doesn't exist. That's a bug dude.";
}

void DBCMainEditor::updatedMessage(DBC_MESSAGE *msg)
void DBCMainEditor::updatedMessage(DBC_MESSAGE *msg, quint32 orig_ID)
{
//if ID was changed then the messagehandler must be told to update its QMap as well.
if (msg->ID != orig_ID)
{
dbcFile->messageHandler->changeMessageID(msg, orig_ID);
}

if (messageToItem.contains(msg))
{
QTreeWidgetItem *item = messageToItem.value(msg);
Expand Down Expand Up @@ -675,7 +683,7 @@ void DBCMainEditor::newMessage()
nodeItem = msgItem->parent();
}
if (typ == DBCItemTypes::NODE){
msgItem = nodeItem;
msgItem = nullptr; //we have no message, just a node selected
}

//if there was a comment this will find the location of the comment and snip it out.
Expand Down Expand Up @@ -709,15 +717,15 @@ void DBCMainEditor::newMessage()
else
{
msgPtr->name = nodeName + "Msg" + QString::number(randGen.bounded(500));
msgPtr->ID = 0;
msgPtr->ID = 0x003;
msgPtr->len = 8;
msgPtr->bgColor = QApplication::palette().color(QPalette::Base);
}
}
else
{
msgPtr->name = nodeName + "Msg" + QString::number(randGen.bounded(500));
msgPtr->ID = 0;
msgPtr->ID = 0x004;
msgPtr->len = 8;
}
msgPtr->sender = node;
Expand All @@ -743,23 +751,41 @@ void DBCMainEditor::newSignal()
QTreeWidgetItem *parentItem = nullptr;
msgItem = ui->treeDBC->currentItem();
parentItem = msgItem;
if (!msgItem) return; //nothing selected!
if (!msgItem)
{
qDebug() << "Nothing selected!";
return; //nothing selected!
}
int typ = msgItem->data(0, Qt::UserRole).toInt();
if (typ == DBCItemTypes::NODE) return; //can't add signals to a node!
if (typ == DBCItemTypes::NODE)
{
qDebug() << "Can't add signals to a node!";
return; //can't add signals to a node!
}
if (typ == DBCItemTypes::SIG)
{
sigItem = msgItem;
msgItem = msgItem->parent();
parentItem = msgItem;
//walk up the tree to find the parent msg
while (msgItem && msgItem->data(0, Qt::UserRole).toInt() != DBCItemTypes::MESG) msgItem = msgItem->parent();
if (!msgItem) return; //something bad happened. abort.
if (!msgItem)
{
qDebug() << "Could not find parent message to attach signal to!";
return; //something bad happened. abort.
}
}

QString idString = msgItem->text(0).split(" ")[0];
int msgID = static_cast<uint32_t>(Utility::ParseStringToNum(idString));
DBC_MESSAGE *msg = dbcFile->messageHandler->findMsgByID(msgID);
if (!msg) return; //null pointers are a bummer. Do not follow them.
DBCMessageHandler *msgHandler = dbcFile->messageHandler;

DBC_MESSAGE *msg = msgHandler->findMsgByID(msgID);
if (!msg)
{
qDebug() << "Could not find data structure for message 0x" << QString::number(msgID, 16) << ". Aborting!";
return; //null pointers are a bummer. Do not follow them.
}
DBC_SIGNAL *sigPtr = new DBC_SIGNAL;
if (sigItem)
{
Expand Down Expand Up @@ -841,8 +867,8 @@ void DBCMainEditor::deleteCurrentTreeItem()
qDebug() << "Could not find the node in the map. That should not happen.";
}
}

break;

case DBCItemTypes::MESG: //cascades to removing all signals too.
idString = currItem->text(0).split(" ")[0];
msgID = static_cast<uint32_t>(Utility::ParseStringToNum(idString));
Expand All @@ -864,6 +890,7 @@ void DBCMainEditor::deleteCurrentTreeItem()
}
}
break;

case DBCItemTypes::SIG: //no cascade, just this one signal.
confirmDialog = QMessageBox::question(this, "Really?", "Are you sure you want to delete this signal?",
QMessageBox::Yes|QMessageBox::No);
Expand Down Expand Up @@ -957,13 +984,22 @@ void DBCMainEditor::deleteMessage(DBC_MESSAGE *msg)
void DBCMainEditor::deleteSignal(DBC_SIGNAL *sig)
{
qDebug() << "Signal about to vanish.";
if (!signalToItem.contains(sig)) return;
if (!signalToItem.contains(sig))
{
qDebug() << "Could not find signal in signalToItem collection! Aborting!";
return;
}
QTreeWidgetItem *currItem = signalToItem[sig];
if (!currItem)
{
qDebug() << "currItem was null in deleteSignal. Aborting!";
return;
}
sig->parentMessage->sigHandler->removeSignal(sig->name);

itemToSignal.remove(currItem);
signalToItem.remove(sig);
ui->treeDBC->removeItemWidget(currItem, 0);
//delete currItem; //already removed by above remove call
delete currItem; //should have been removed above but do we need to call this anyway?!
dbcFile->setDirtyFlag();
}
2 changes: 1 addition & 1 deletion dbc/dbcmaineditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DBCMainEditor : public QDialog

public slots:
void updatedNode(DBC_NODE *node);
void updatedMessage(DBC_MESSAGE *msg);
void updatedMessage(DBC_MESSAGE *msg, quint32 orig_id);
void updatedSignal(DBC_SIGNAL *sig);

private slots:
Expand Down
15 changes: 10 additions & 5 deletions dbc/dbcmessageeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
if (suppressEditCallbacks) return;
if (dbcMessage->comment != ui->lineComment->text()) dbcFile->setDirtyFlag();
dbcMessage->comment = ui->lineComment->text();
emit updatedTreeInfo(dbcMessage);
emit updatedTreeInfo(dbcMessage, origID);
});

connect(ui->lineFrameID, &QLineEdit::editingFinished,
Expand All @@ -36,7 +36,11 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
if (suppressEditCallbacks) return;
if ((dbcMessage->ID & 0x1FFFFFFFul) != Utility::ParseStringToNum(ui->lineFrameID->text())) dbcFile->setDirtyFlag();
dbcMessage->ID = Utility::ParseStringToNum(ui->lineFrameID->text());
emit updatedTreeInfo(dbcMessage);

if (dbcMessage->ID > 0x7FF) dbcMessage->extendedID = true;
else dbcMessage->extendedID = false;

emit updatedTreeInfo(dbcMessage, origID);
});

connect(ui->lineMsgName, &QLineEdit::editingFinished,
Expand All @@ -46,7 +50,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
if (suppressEditCallbacks) return;
if (dbcMessage->name != ui->lineMsgName->text().simplified().replace(' ', '_')) dbcFile->setDirtyFlag();
dbcMessage->name = ui->lineMsgName->text().simplified().replace(' ', '_');
emit updatedTreeInfo(dbcMessage);
emit updatedTreeInfo(dbcMessage, origID);
});

connect(ui->lineFrameLen, &QLineEdit::editingFinished,
Expand All @@ -67,7 +71,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
if (!node) return;
if (node != dbcMessage->sender) dbcFile->setDirtyFlag();
dbcMessage->sender = node;
emit updatedTreeInfo(dbcMessage);
emit updatedTreeInfo(dbcMessage, origID);
});

connect(ui->comboSender->lineEdit(), &QLineEdit::editingFinished,
Expand All @@ -87,7 +91,7 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) :
}
if (node != dbcMessage->sender) dbcFile->setDirtyFlag();
dbcMessage->sender = node;
emit updatedTreeInfo(dbcMessage);
emit updatedTreeInfo(dbcMessage, origID);
});

connect(ui->btnTextColor, &QAbstractButton::clicked,
Expand Down Expand Up @@ -206,6 +210,7 @@ void DBCMessageEditor::writeSettings()
void DBCMessageEditor::setMessageRef(DBC_MESSAGE *msg)
{
dbcMessage = msg;
origID = msg->ID;
}

void DBCMessageEditor::showEvent(QShowEvent* event)
Expand Down
3 changes: 2 additions & 1 deletion dbc/dbcmessageeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DBCMessageEditor : public QDialog
void refreshView();

signals:
void updatedTreeInfo(DBC_MESSAGE *msg);
void updatedTreeInfo(DBC_MESSAGE *msg, quint32 orig_id);

private:
Ui::DBCMessageEditor *ui;
Expand All @@ -31,6 +31,7 @@ class DBCMessageEditor : public QDialog
DBC_MESSAGE *dbcMessage;
DBCFile *dbcFile;
bool suppressEditCallbacks;
quint32 origID;

void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
Expand Down
2 changes: 1 addition & 1 deletion dbc/dbcnodeduplicateeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DBCNodeDuplicateEditor : public QDialog
bool refreshView();

signals:
void updatedTreeInfo(DBC_MESSAGE *msg);
void updatedTreeInfo(DBC_MESSAGE *msg, quint32 origID);
void createNode(QString nodeName);
void cloneMessageToNode(DBC_NODE *parentNode, DBC_MESSAGE *source, uint newMsgId);
void nodeAdded();
Expand Down
2 changes: 1 addition & 1 deletion dbc/dbcnoderebaseeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ DBCNodeRebaseEditor::DBCNodeRebaseEditor(QWidget *parent) :
for (int i = 0; i < messagesForNode.count(); i++)
{
messagesForNode[i]->ID += rebaseDiff;
emit updatedTreeInfo(messagesForNode[i]);
emit updatedTreeInfo(messagesForNode[i], messagesForNode[i]->ID);
}

dbcFile->setDirtyFlag();
Expand Down
2 changes: 1 addition & 1 deletion dbc/dbcnoderebaseeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DBCNodeRebaseEditor : public QDialog
bool refreshView();

signals:
void updatedTreeInfo(DBC_MESSAGE *msg);
void updatedTreeInfo(DBC_MESSAGE *msg, quint32 origID);

private:
Ui::DBCNodeRebaseEditor *ui;
Expand Down

0 comments on commit de83dc6

Please sign in to comment.