diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index 5d1dd96..7dc2e10 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -31,9 +31,9 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) nodeEditor = new DBCNodeEditor(this); //all three might potentially change the data stored and force the tree to be updated - connect(sigEditor, &DBCSignalEditor::updatedTreeInfo, this, &DBCMainEditor::updatedTreeInfo); - connect(msgEditor, &DBCMessageEditor::updatedTreeInfo, this, &DBCMainEditor::updatedTreeInfo); - connect(nodeEditor, &DBCNodeEditor::updatedTreeInfo, this, &DBCMainEditor::updatedTreeInfo); + connect(sigEditor, &DBCSignalEditor::updatedTreeInfo, this, &DBCMainEditor::updatedSignal); + connect(msgEditor, &DBCMessageEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); + connect(nodeEditor, &DBCNodeEditor::updatedTreeInfo, this, &DBCMainEditor::updatedNode); nodeIcon = QIcon(":/icons/images/node.png"); messageIcon = QIcon(":/icons/images/message.png"); @@ -266,6 +266,9 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index) void DBCMainEditor::refreshTree() { ui->treeDBC->clear(); + nodeToItem.clear(); + messageToItem.clear(); + signalToItem.clear(); if (dbcFile->findNodeByName("Vector__XXX") == nullptr) { @@ -275,18 +278,20 @@ void DBCMainEditor::refreshTree() dbcFile->dbc_nodes.append(newNode); } - foreach (DBC_NODE node, dbcFile->dbc_nodes) + for (int n = 0; n < dbcFile->dbc_nodes.count(); n++) { + DBC_NODE *node = &dbcFile->dbc_nodes[n]; QTreeWidgetItem *nodeItem = new QTreeWidgetItem(); - QString nodeInfo = node.name; - if (node.comment.count() > 0) nodeInfo.append(" - ").append(node.comment); + QString nodeInfo = node->name; + if (node->comment.count() > 0) nodeInfo.append(" - ").append(node->comment); nodeItem->setText(0, nodeInfo); nodeItem->setIcon(0, nodeIcon); nodeItem->setData(0, Qt::UserRole, 1); + nodeToItem.insert(node, nodeItem); for (int x = 0; x < dbcFile->messageHandler->getCount(); x++) { DBC_MESSAGE *msg = dbcFile->messageHandler->findMsgByIdx(x); - if (msg->sender->name == node.name) + if (msg->sender->name == node->name) { QTreeWidgetItem *msgItem = new QTreeWidgetItem(nodeItem); QString msgInfo = Utility::formatCANID(msg->ID) + " " + msg->name; @@ -294,6 +299,7 @@ void DBCMainEditor::refreshTree() msgItem->setText(0, msgInfo); msgItem->setIcon(0, messageIcon); msgItem->setData(0, Qt::UserRole, 2); + messageToItem.insert(msg, msgItem); for (int i = 0; i < msg->sigHandler->getCount(); i++) { DBC_SIGNAL *sig = msg->sigHandler->findSignalByIdx(i); @@ -305,6 +311,7 @@ void DBCMainEditor::refreshTree() else if (sig->isMultiplexor) sigItem->setIcon(0, multiplexorSignalIcon); else sigItem->setIcon(0, signalIcon); sigItem->setData(0, Qt::UserRole, 3); + signalToItem.insert(sig, sigItem); } } } @@ -313,7 +320,38 @@ void DBCMainEditor::refreshTree() ui->treeDBC->sortItems(0, Qt::SortOrder::AscendingOrder); //sort the display list for ease in viewing by mere mortals, helps me a lot. } -void DBCMainEditor::updatedTreeInfo(QString oldData, QString newData, int type) +void DBCMainEditor::updatedNode(DBC_NODE *node) { + if (nodeToItem.contains(node)) + { + QTreeWidgetItem *item = nodeToItem[node]; + QString nodeInfo = node->name; + if (node->comment.count() > 0) nodeInfo.append(" - ").append(node->comment); + item->setText(0, nodeInfo); + } + else qDebug() << "That node doesn't exist. That's a bug dude."; +} +void DBCMainEditor::updatedMessage(DBC_MESSAGE *msg) +{ + if (messageToItem.contains(msg)) + { + QTreeWidgetItem *item = messageToItem.value(msg); + QString msgInfo = Utility::formatCANID(msg->ID) + " " + msg->name; + if (msg->comment.count() > 0) msgInfo.append(" - ").append(msg->comment); + item->setText(0, msgInfo); + } + else qDebug() << "Shit?! That mesage doesn't exist. That's a bug dude."; +} + +void DBCMainEditor::updatedSignal(DBC_SIGNAL *sig) +{ + if (signalToItem.contains(sig)) + { + QTreeWidgetItem *item = signalToItem.value(sig); + QString sigInfo = sig->name; + if (sig->comment.count() > 0) sigInfo.append(" - ").append(sig->comment); + item->setText(0, sigInfo); + } + else qDebug() << "Shit?! That signal doesn't exist. That's a bug dude."; } diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index 6b83a4d..b16e940 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -25,7 +25,9 @@ public: void setFileIdx(int idx); public slots: - void updatedTreeInfo(QString oldData, QString newData, int type); + void updatedNode(DBC_NODE *node); + void updatedMessage(DBC_MESSAGE *msg); + void updatedSignal(DBC_SIGNAL *sig); private slots: void onTreeDoubleClicked(const QModelIndex &index); @@ -51,6 +53,9 @@ private: QIcon multiplexedSignalIcon; QList searchItems; int searchItemPos; + QMap nodeToItem; + QMap messageToItem; + QMap signalToItem; void showEvent(QShowEvent* event); void closeEvent(QCloseEvent *event); diff --git a/dbc/dbcmessageeditor.cpp b/dbc/dbcmessageeditor.cpp index 1ccdcb5..c388c17 100644 --- a/dbc/dbcmessageeditor.cpp +++ b/dbc/dbcmessageeditor.cpp @@ -18,6 +18,37 @@ DBCMessageEditor::DBCMessageEditor(QWidget *parent) : dbcHandler = DBCHandler::getReference(); dbcMessage = nullptr; + connect(ui->lineComment, &QLineEdit::editingFinished, + [=]() + { + if (dbcMessage == nullptr) return; + dbcMessage->comment = ui->lineComment->text(); + emit updatedTreeInfo(dbcMessage); + }); + + connect(ui->lineFrameID, &QLineEdit::editingFinished, + [=]() + { + if (dbcMessage == nullptr) return; + dbcMessage->ID = Utility::ParseStringToNum(ui->lineFrameID->text()); + emit updatedTreeInfo(dbcMessage); + }); + + connect(ui->lineMsgName, &QLineEdit::editingFinished, + [=]() + { + if (dbcMessage == nullptr) return; + dbcMessage->name = ui->lineMsgName->text().simplified().replace(' ', '_'); + emit updatedTreeInfo(dbcMessage); + }); + + connect(ui->lineFrameLen, &QLineEdit::editingFinished, + [=]() + { + if (dbcMessage == nullptr) return; + dbcMessage->len = Utility::ParseStringToNum(ui->lineFrameLen->text()); + }); + connect(ui->btnTextColor, &QAbstractButton::clicked, [=]() { diff --git a/dbc/dbcmessageeditor.h b/dbc/dbcmessageeditor.h index 79cfe0f..5388466 100644 --- a/dbc/dbcmessageeditor.h +++ b/dbc/dbcmessageeditor.h @@ -22,7 +22,7 @@ public: void refreshView(); signals: - void updatedTreeInfo(QString oldData, QString newData, int type); + void updatedTreeInfo(DBC_MESSAGE *msg); private: Ui::DBCMessageEditor *ui; diff --git a/dbc/dbcnodeeditor.cpp b/dbc/dbcnodeeditor.cpp index 62c269f..e321fe3 100644 --- a/dbc/dbcnodeeditor.cpp +++ b/dbc/dbcnodeeditor.cpp @@ -18,6 +18,22 @@ DBCNodeEditor::DBCNodeEditor(QWidget *parent) : dbcHandler = DBCHandler::getReference(); dbcNode = nullptr; + connect(ui->lineComment, &QLineEdit::editingFinished, + [=]() + { + if (dbcNode == nullptr) return; + dbcNode->comment = ui->lineComment->text(); + emit updatedTreeInfo(dbcNode); + }); + + connect(ui->lineMsgName, &QLineEdit::editingFinished, + [=]() + { + if (dbcNode == nullptr) return; + dbcNode->name = ui->lineMsgName->text(); + emit updatedTreeInfo(dbcNode); + }); + installEventFilter(this); } diff --git a/dbc/dbcnodeeditor.h b/dbc/dbcnodeeditor.h index 6e9b44d..3bd65e0 100644 --- a/dbc/dbcnodeeditor.h +++ b/dbc/dbcnodeeditor.h @@ -22,7 +22,7 @@ public: void refreshView(); signals: - void updatedTreeInfo(QString oldData, QString newData, int type); + void updatedTreeInfo(DBC_NODE *node); private: Ui::DBCNodeEditor *ui; diff --git a/dbc/dbcsignaleditor.cpp b/dbc/dbcsignaleditor.cpp index 12a2fc7..7fd4016 100644 --- a/dbc/dbcsignaleditor.cpp +++ b/dbc/dbcsignaleditor.cpp @@ -125,7 +125,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) : { if (currentSignal == nullptr) return; currentSignal->comment = ui->txtComment->text().simplified().replace(' ', '_'); - //updatedTreeInfo(); + emit updatedTreeInfo(currentSignal); }); connect(ui->txtUnitName, &QLineEdit::editingFinished, @@ -153,7 +153,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) : QString tempNameStr = ui->txtName->text().simplified().replace(' ', '_'); if (tempNameStr.length() > 0) currentSignal->name = tempNameStr; //need to update the tree too. - //updatedTreeInfo(); + emit updatedTreeInfo(currentSignal); }); connect(ui->txtMultiplexValue, &QLineEdit::editingFinished, diff --git a/dbc/dbcsignaleditor.h b/dbc/dbcsignaleditor.h index 4de69a5..0c69ea3 100644 --- a/dbc/dbcsignaleditor.h +++ b/dbc/dbcsignaleditor.h @@ -23,7 +23,7 @@ public: void refreshView(); signals: - void updatedTreeInfo(QString oldData, QString newData, int type); + void updatedTreeInfo(DBC_SIGNAL *sig); private slots: void bitfieldClicked(int x, int y); diff --git a/ui/dbcmessageeditor.ui b/ui/dbcmessageeditor.ui index e5ff6db..c4b3a2a 100644 --- a/ui/dbcmessageeditor.ui +++ b/ui/dbcmessageeditor.ui @@ -109,13 +109,6 @@ - - - - Close - - - diff --git a/ui/dbcnodeeditor.ui b/ui/dbcnodeeditor.ui index 80c521b..f56bd35 100644 --- a/ui/dbcnodeeditor.ui +++ b/ui/dbcnodeeditor.ui @@ -7,7 +7,7 @@ 0 0 311 - 128 + 88 @@ -38,13 +38,6 @@ - - - - Close - - -