From 27b58552df7219ec7d27b7c88a59ebe074f509ef Mon Sep 17 00:00:00 2001 From: Andy Huska Date: Wed, 21 Sep 2022 18:04:11 -0500 Subject: [PATCH] rebase working but definitely needs clean up for all the whatifs --- SavvyCAN.pro | 3 + canframemodel.cpp | 1 + dbc/dbchandler.cpp | 18 ++++ dbc/dbchandler.h | 1 + dbc/dbcmaineditor.cpp | 18 +++- dbc/dbcmaineditor.h | 2 + dbc/dbcnoderebaseeditor.cpp | 166 ++++++++++++++++++++++++++++++++++++ dbc/dbcnoderebaseeditor.h | 42 +++++++++ ui/dbcnoderebaseeditor.ui | 75 ++++++++++++++++ 9 files changed, 325 insertions(+), 1 deletion(-) create mode 100644 dbc/dbcnoderebaseeditor.cpp create mode 100644 dbc/dbcnoderebaseeditor.h create mode 100644 ui/dbcnoderebaseeditor.ui diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 9df479e..0a7094b 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -67,6 +67,7 @@ SOURCES += main.cpp\ dbc/dbcmaineditor.cpp \ dbc/dbcnodeeditor.cpp \ dbc/dbcsignaleditor.cpp \ + dbc/dbcnoderebaseeditor.cpp \ re/discretestatewindow.cpp \ re/filecomparatorwindow.cpp \ re/flowviewwindow.cpp \ @@ -100,6 +101,7 @@ HEADERS += mainwindow.h \ canframemodel.h \ connections/socketcand.h \ connections/mqtt_bus.h \ + dbc/dbcnoderebaseeditor.h \ mqtt/qmqtt.h \ mqtt/qmqtt_client.h \ mqtt/qmqtt_client_p.h \ @@ -188,6 +190,7 @@ FORMS += ui/candatagrid.ui \ ui/connectionwindow.ui \ ui/dbcloadsavewindow.ui \ ui/dbcmaineditor.ui \ + ui/dbcnoderebaseeditor.ui \ ui/dbcsignaleditor.ui \ ui/dbcnodeeditor.ui \ ui/discretestatewindow.ui \ diff --git a/canframemodel.cpp b/canframemodel.cpp index aef3a34..03bb5d7 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -380,6 +380,7 @@ void CANFrameModel::recalcOverwrite() //Then replace the old list of frames with just the unique list frames.clear(); frames.append(overWriteFrames.values().toVector()); + frames.reserve(preallocSize); filteredFrames.clear(); filteredFrames.reserve(preallocSize); diff --git a/dbc/dbchandler.cpp b/dbc/dbchandler.cpp index 9088bda..23523ec 100644 --- a/dbc/dbchandler.cpp +++ b/dbc/dbchandler.cpp @@ -177,6 +177,24 @@ DBC_MESSAGE* DBCMessageHandler::findMsgByPartialName(QString name) return nullptr; } +QList DBCMessageHandler::findMsgsByNode(DBC_NODE* node) +{ + QList messagesForNode; + + if (messages.count() == 0) + return messagesForNode; + + for (int i = 0; i < messages.count(); i++) + { + if (messages[i].sender == node) + { + messagesForNode.append(&messages[i]); + } + } + + return messagesForNode; +} + bool DBCMessageHandler::addMessage(DBC_MESSAGE &msg) { messages.append(msg); diff --git a/dbc/dbchandler.h b/dbc/dbchandler.h index 9e040cb..925bc8c 100644 --- a/dbc/dbchandler.h +++ b/dbc/dbchandler.h @@ -43,6 +43,7 @@ public: DBC_MESSAGE *findMsgByIdx(int idx); DBC_MESSAGE *findMsgByName(QString name); DBC_MESSAGE *findMsgByPartialName(QString name); + QList findMsgsByNode(DBC_NODE *node); bool addMessage(DBC_MESSAGE &msg); bool removeMessage(DBC_MESSAGE *msg); bool removeMessageByIndex(int idx); diff --git a/dbc/dbcmaineditor.cpp b/dbc/dbcmaineditor.cpp index d10fcc3..88e3753 100644 --- a/dbc/dbcmaineditor.cpp +++ b/dbc/dbcmaineditor.cpp @@ -38,11 +38,13 @@ DBCMainEditor::DBCMainEditor( const QVector *frames, QWidget *parent) sigEditor = new DBCSignalEditor(this); msgEditor = new DBCMessageEditor(this); nodeEditor = new DBCNodeEditor(this); + nodeRebaseEditor = new DBCNodeRebaseEditor(this); //all three might potentially change the data stored and force the tree to be updated connect(sigEditor, &DBCSignalEditor::updatedTreeInfo, this, &DBCMainEditor::updatedSignal); connect(msgEditor, &DBCMessageEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); connect(nodeEditor, &DBCNodeEditor::updatedTreeInfo, this, &DBCMainEditor::updatedNode); + connect(nodeRebaseEditor, &DBCNodeRebaseEditor::updatedTreeInfo, this, &DBCMainEditor::updatedMessage); nodeIcon = QIcon(":/icons/images/node.png"); messageIcon = QIcon(":/icons/images/message.png"); @@ -339,7 +341,21 @@ void DBCMainEditor::onTreeContextMenu(const QPoint & pos) void DBCMainEditor::onRebaseMessages() { - qDebug() << "rebase!!"; + QTreeWidgetItem* firstCol = ui->treeDBC->currentItem(); + bool ret = false; + DBC_MESSAGE *msg; + DBC_SIGNAL *sig; + DBC_NODE *node; + uint32_t msgID; + QString idString; + + idString = firstCol->text(0).split(" ")[0]; + node = dbcFile->findNodeByName(idString); + nodeRebaseEditor->setFileIdx(fileIdx); + nodeRebaseEditor->setNodeRef(node); + nodeRebaseEditor->refreshView(); + nodeRebaseEditor->setModal(true); + nodeRebaseEditor->show(); } void DBCMainEditor::onDuplicateNode() diff --git a/dbc/dbcmaineditor.h b/dbc/dbcmaineditor.h index dc8ea7c..62f0876 100644 --- a/dbc/dbcmaineditor.h +++ b/dbc/dbcmaineditor.h @@ -10,6 +10,7 @@ #include "dbcsignaleditor.h" #include "dbcmessageeditor.h" #include "dbcnodeeditor.h" +#include "dbcnoderebaseeditor.h" #include "utility.h" namespace Ui { @@ -55,6 +56,7 @@ private: DBCSignalEditor *sigEditor; DBCMessageEditor *msgEditor; DBCNodeEditor *nodeEditor; + DBCNodeRebaseEditor *nodeRebaseEditor; DBCFile *dbcFile; int fileIdx; QIcon nodeIcon; diff --git a/dbc/dbcnoderebaseeditor.cpp b/dbc/dbcnoderebaseeditor.cpp new file mode 100644 index 0000000..393b656 --- /dev/null +++ b/dbc/dbcnoderebaseeditor.cpp @@ -0,0 +1,166 @@ +#include "dbcnoderebaseeditor.h" +#include "ui_dbcnoderebaseeditor.h" + +#include +#include +#include +#include "helpwindow.h" +#include "utility.h" + +DBCNodeRebaseEditor::DBCNodeRebaseEditor(QWidget *parent) : + QDialog(parent), + ui(new Ui::DBCNodeRebaseEditor) +{ + ui->setupUi(this); + + readSettings(); + + dbcHandler = DBCHandler::getReference(); + dbcNode = nullptr; + + connect(ui->btnDoRebase, &QPushButton::pressed, + [=]() + { + if (dbcNode == nullptr) return; + if (lowestMsgId > 0x1FFFFFFFul) return; + + uint newBase = Utility::ParseStringToNum(ui->lineEdit->text()); + + if (newBase <= 0x1FFFFFFFul && newBase != lowestMsgId) + { + uint rebaseDiff = newBase - lowestMsgId; + + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + return; + } + + for (int i=0; iID += rebaseDiff; + emit updatedTreeInfo(messagesForNode[i]); + } + + dbcFile->setDirtyFlag(); + } + + + }); + +// 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); +// }); + + installEventFilter(this); +} + +DBCNodeRebaseEditor::~DBCNodeRebaseEditor() +{ + removeEventFilter(this); + delete ui; +} + +void DBCNodeRebaseEditor::closeEvent(QCloseEvent *event) +{ + Q_UNUSED(event); + writeSettings(); +} + +bool DBCNodeRebaseEditor::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyRelease) { + QKeyEvent *keyEvent = static_cast(event); + switch (keyEvent->key()) + { + case Qt::Key_F1: + HelpWindow::getRef()->showHelp("nodeeditor.md"); + break; + } + return true; + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } + return false; +} + +void DBCNodeRebaseEditor::setFileIdx(int idx) +{ + if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return; + dbcFile = dbcHandler->getFileByIdx(idx); +} + +void DBCNodeRebaseEditor::readSettings() +{ + QSettings settings; + if (settings.value("Main/SaveRestorePositions", false).toBool()) + { + resize(settings.value("DBCNodeRebaseEditor/WindowSize", QSize(312, 128)).toSize()); + move(Utility::constrainedWindowPos(settings.value("DBCNodeRebaseEditor/WindowPos", QPoint(100, 100)).toPoint())); + } +} + +void DBCNodeRebaseEditor::writeSettings() +{ + QSettings settings; + + if (settings.value("Main/SaveRestorePositions", false).toBool()) + { + settings.setValue("DBCNodeRebaseEditor/WindowSize", size()); + settings.setValue("DBCNodeRebaseEditor/WindowPos", pos()); + } +} + + +void DBCNodeRebaseEditor::setNodeRef(DBC_NODE *node) +{ + dbcNode = node; +} + +void DBCNodeRebaseEditor::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + + refreshView(); +} + +void DBCNodeRebaseEditor::refreshView() +{ + if(dbcNode) + { + QList messagesForNode = dbcFile->messageHandler->findMsgsByNode(dbcNode); + if(messagesForNode.count() == 0) + { + //?? + + } + + lowestMsgId = 0xFFFFFFFF; + + for (int i=0; iID < lowestMsgId) + lowestMsgId = messagesForNode[i]->ID; + } + + ui->lineOriginalBaseId->setText(Utility::formatCANID(lowestMsgId & 0x1FFFFFFFul)); + ui->lineMsgName->setText(dbcNode->name); + } + + //generateSampleText(); +} diff --git a/dbc/dbcnoderebaseeditor.h b/dbc/dbcnoderebaseeditor.h new file mode 100644 index 0000000..8e787f0 --- /dev/null +++ b/dbc/dbcnoderebaseeditor.h @@ -0,0 +1,42 @@ +#ifndef DBCNODEREBASEEDITOR_H +#define DBCNODEREBASEEDITOR_H + +#include +#include "dbc_classes.h" +#include "dbchandler.h" + +namespace Ui { +class DBCNodeRebaseEditor; +} + +class DBCNodeRebaseEditor : public QDialog +{ + Q_OBJECT + +public: + explicit DBCNodeRebaseEditor(QWidget *parent = nullptr); + ~DBCNodeRebaseEditor(); + void showEvent(QShowEvent*); + void setNodeRef(DBC_NODE *node); + void setFileIdx(int idx); + void refreshView(); + +signals: + void updatedTreeInfo(DBC_MESSAGE *msg); + +private: + Ui::DBCNodeRebaseEditor *ui; + + DBCHandler *dbcHandler; + DBC_NODE *dbcNode; + DBCFile *dbcFile; + + void closeEvent(QCloseEvent *event); + bool eventFilter(QObject *obj, QEvent *event); + void readSettings(); + void writeSettings(); + + uint lowestMsgId; +}; + +#endif // DBCNODEREBASEEDITOR_H diff --git a/ui/dbcnoderebaseeditor.ui b/ui/dbcnoderebaseeditor.ui new file mode 100644 index 0000000..58bc46c --- /dev/null +++ b/ui/dbcnoderebaseeditor.ui @@ -0,0 +1,75 @@ + + + DBCNodeRebaseEditor + + + + 0 + 0 + 303 + 159 + + + + Dialog + + + + + 10 + 20 + 283 + 116 + + + + + + + Node Name: + + + + + + + + + + Current Base ID: + + + + + + + + + + New Base ID: + + + + + + + + + + Rebase All Messages in Node + + + + + + + Cancel + + + + + + + + +