From 3ef905b68acc6358e3a07abf78c1ef17af40ff4b Mon Sep 17 00:00:00 2001 From: Collin Kidder Date: Sun, 17 Jan 2016 17:09:47 -0500 Subject: [PATCH] Added a file manager and hooked it up. It is now possible to load and edit multiple DBC files. --- SavvyCAN.pro | 9 ++-- dbchandler.cpp | 3 +- dbchandler.h | 2 +- dbcloadsavewindow.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++ dbcloadsavewindow.h | 41 +++++++++++++++ dbcloadsavewindow.ui | 74 ++++++++++++++++++++++++++ dbcmaineditor.cpp | 60 +++++++++++---------- dbcmaineditor.h | 3 ++ dbcsignaleditor.cpp | 20 ++++--- dbcsignaleditor.h | 2 + mainwindow.cpp | 64 +++++++++++------------ mainwindow.h | 6 +-- mainwindow.ui | 11 ++-- 13 files changed, 335 insertions(+), 78 deletions(-) create mode 100644 dbcloadsavewindow.cpp create mode 100644 dbcloadsavewindow.h create mode 100644 dbcloadsavewindow.ui diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 4e0c4a1..2657522 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -42,7 +42,8 @@ SOURCES += main.cpp\ scriptcontainer.cpp \ canfilter.cpp \ rangestatewindow.cpp \ - dbc_classes.cpp + dbc_classes.cpp \ + dbcloadsavewindow.cpp HEADERS += mainwindow.h \ can_structs.h \ @@ -72,7 +73,8 @@ HEADERS += mainwindow.h \ scriptingwindow.h \ scriptcontainer.h \ canfilter.h \ - rangestatewindow.h + rangestatewindow.h \ + dbcloadsavewindow.h FORMS += mainwindow.ui \ graphingwindow.ui \ @@ -90,7 +92,8 @@ FORMS += mainwindow.ui \ discretestatewindow.ui \ connectionwindow.ui \ scriptingwindow.ui \ - rangestatewindow.ui + rangestatewindow.ui \ + dbcloadsavewindow.ui DISTFILES += diff --git a/dbchandler.cpp b/dbchandler.cpp index 6075ddb..a12d863 100644 --- a/dbchandler.cpp +++ b/dbchandler.cpp @@ -735,7 +735,7 @@ void DBCHandler::saveDBCFile(int idx) //Otherwise add a new one. Well, always add a new one. //If a valid index is passed we'll remove that one and then commence //adding. Otherwise, just go straight to adding. -void DBCHandler::loadDBCFile(int idx) +DBCFile* DBCHandler::loadDBCFile(int idx) { if (idx > -1 && idx < loadedFiles.count()) removeDBCFile(idx); @@ -757,6 +757,7 @@ void DBCHandler::loadDBCFile(int idx) newFile.loadFile(filename); loadedFiles.append(newFile); } + return &loadedFiles.last(); } void DBCHandler::removeDBCFile(int idx) diff --git a/dbchandler.h b/dbchandler.h index 137fe5f..e6c2770 100644 --- a/dbchandler.h +++ b/dbchandler.h @@ -77,7 +77,7 @@ class DBCHandler: public QObject { Q_OBJECT public: - void loadDBCFile(int); + DBCFile* loadDBCFile(int); void saveDBCFile(int); void removeDBCFile(int); void removeAllFiles(); diff --git a/dbcloadsavewindow.cpp b/dbcloadsavewindow.cpp new file mode 100644 index 0000000..289f81e --- /dev/null +++ b/dbcloadsavewindow.cpp @@ -0,0 +1,118 @@ +#include "dbcloadsavewindow.h" +#include "ui_dbcloadsavewindow.h" + +DBCLoadSaveWindow::DBCLoadSaveWindow(DBCHandler *handler, const QVector *frames, QWidget *parent) : + QDialog(parent), + ui(new Ui::DBCLoadSaveWindow) +{ + + dbcHandler = handler; + referenceFrames = frames; + + ui->setupUi(this); + + QStringList header; + header << "Filename" << "Associated Bus"; + ui->tableFiles->setColumnCount(2); + ui->tableFiles->setHorizontalHeaderLabels(header); + ui->tableFiles->setColumnWidth(0, 355); + ui->tableFiles->setColumnWidth(1, 125); + + connect(ui->btnEdit, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::editFile); + connect(ui->btnLoad, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::loadFile); + connect(ui->btnMoveDown, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::moveDown); + connect(ui->btnMoveUp, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::moveUp); + connect(ui->btnRemove, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::removeFile); + connect(ui->btnSave, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::saveFile); + + editorWindow = new DBCMainEditor(handler, frames); +} + +DBCLoadSaveWindow::~DBCLoadSaveWindow() +{ + delete ui; +} + +void DBCLoadSaveWindow::loadFile() +{ + DBCFile *file = dbcHandler->loadDBCFile(-1); + int idx = ui->tableFiles->rowCount(); + ui->tableFiles->insertRow(ui->tableFiles->rowCount()); + ui->tableFiles->setItem(idx, 0, new QTableWidgetItem(file->getFullFilename())); + ui->tableFiles->setItem(idx, 1, new QTableWidgetItem("-1")); +} + +void DBCLoadSaveWindow::saveFile() +{ + int idx = ui->tableFiles->currentRow(); + if (idx < 0) return; + dbcHandler->saveDBCFile(idx); +} + +void DBCLoadSaveWindow::removeFile() +{ + int idx = ui->tableFiles->currentRow(); + if (idx < 0) return; + dbcHandler->removeDBCFile(idx); + ui->tableFiles->removeRow(idx); +} + +void DBCLoadSaveWindow::moveUp() +{ + int idx = ui->tableFiles->currentRow(); + if (idx < 1) return; + dbcHandler->swapFiles(idx - 1, idx); + swapTableRows(true); +} + +void DBCLoadSaveWindow::moveDown() +{ + int idx = ui->tableFiles->currentRow(); + if (idx < 0) return; + if (idx > (dbcHandler->getFileCount() - 2)) return; + dbcHandler->swapFiles(idx, idx + 1); + swapTableRows(false); +} + +void DBCLoadSaveWindow::editFile() +{ + int idx = ui->tableFiles->currentRow(); + if (idx < 0) return; + + editorWindow->setFileIdx(idx); + editorWindow->show(); +} + +void DBCLoadSaveWindow::swapTableRows(bool up) +{ + int idx = ui->tableFiles->currentRow(); + const int destIdx = (up ? idx-1 : idx+1); + Q_ASSERT(destIdx >= 0 && destIdx < ui->tableFiles->rowCount()); + + // take whole rows + QList sourceItems = takeRow(idx); + QList destItems = takeRow(destIdx); + + // set back in reverse order + setRow(idx, destItems); + setRow(destIdx, sourceItems); +} + +QList DBCLoadSaveWindow::takeRow(int row) +{ + QList rowItems; + for (int col = 0; col < ui->tableFiles->columnCount(); ++col) + { + rowItems << ui->tableFiles->takeItem(row, col); + } + return rowItems; +} + +void DBCLoadSaveWindow::setRow(int row, const QList& rowItems) +{ + for (int col = 0; col < ui->tableFiles->columnCount(); ++col) + { + ui->tableFiles->setItem(row, col, rowItems.at(col)); + } +} + diff --git a/dbcloadsavewindow.h b/dbcloadsavewindow.h new file mode 100644 index 0000000..b30de7e --- /dev/null +++ b/dbcloadsavewindow.h @@ -0,0 +1,41 @@ +#ifndef DBCLOADSAVEWINDOW_H +#define DBCLOADSAVEWINDOW_H + +#include +#include +#include "dbchandler.h" +#include "dbcmaineditor.h" + +namespace Ui { +class DBCLoadSaveWindow; +} + +class DBCLoadSaveWindow : public QDialog +{ + Q_OBJECT + +public: + explicit DBCLoadSaveWindow(DBCHandler *handler, const QVector *frames, QWidget *parent = 0); + ~DBCLoadSaveWindow(); + +private slots: + void loadFile(); + void saveFile(); + void removeFile(); + void moveUp(); + void moveDown(); + void editFile(); + +private: + Ui::DBCLoadSaveWindow *ui; + DBCHandler *dbcHandler; + const QVector *referenceFrames; + DBCMainEditor *editorWindow; + + void swapTableRows(bool up); + QList takeRow(int row); + void setRow(int row, const QList& rowItems); +}; + +#endif // DBCLOADSAVEWINDOW_H + diff --git a/dbcloadsavewindow.ui b/dbcloadsavewindow.ui new file mode 100644 index 0000000..ea48481 --- /dev/null +++ b/dbcloadsavewindow.ui @@ -0,0 +1,74 @@ + + + DBCLoadSaveWindow + + + + 0 + 0 + 506 + 665 + + + + DBC File Manager + + + + + + + + + + + Load + + + + + + + Remove + + + + + + + Move Up + + + + + + + + + + + Save + + + + + + + Edit + + + + + + + Move Down + + + + + + + + + + diff --git a/dbcmaineditor.cpp b/dbcmaineditor.cpp index eb3b573..7a82e9b 100644 --- a/dbcmaineditor.cpp +++ b/dbcmaineditor.cpp @@ -54,8 +54,8 @@ void DBCMainEditor::showEvent(QShowEvent* event) inhibitCellChanged = true; refreshNodesTable(); - if (dbcHandler->getFileByIdx(0)->dbc_nodes.count() > 0) - refreshMessagesTable(&dbcHandler->getFileByIdx(0)->dbc_nodes.at(0)); + if (dbcFile->dbc_nodes.count() > 0) + refreshMessagesTable(&dbcFile->dbc_nodes.at(0)); currRow = 0; inhibitCellChanged = false; @@ -67,6 +67,13 @@ DBCMainEditor::~DBCMainEditor() delete sigEditor; } +void DBCMainEditor::setFileIdx(int idx) +{ + if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return; + dbcFile = dbcHandler->getFileByIdx(idx); + fileIdx = idx; +} + void DBCMainEditor::closeEvent(QCloseEvent *event) { Q_UNUSED(event); @@ -123,9 +130,9 @@ void DBCMainEditor::deleteCurrentNode() if (nodeName.length() > 0 && nodeName.compare("Vector__XXX", Qt::CaseInsensitive) != 0) { ui->NodesTable->removeRow(thisRow); - dbcHandler->getFileByIdx(0)->dbc_nodes.removeAt(thisRow); + dbcFile->dbc_nodes.removeAt(thisRow); inhibitCellChanged = true; - refreshMessagesTable(&dbcHandler->getFileByIdx(0)->dbc_nodes[0]); + refreshMessagesTable(&dbcFile->dbc_nodes[0]); ui->NodesTable->selectRow(0); inhibitCellChanged = false; } @@ -137,7 +144,7 @@ void DBCMainEditor::deleteCurrentMessage() if (ui->MessagesTable->item(thisRow, 0)->text().length() > 0) { ui->MessagesTable->removeRow(thisRow); - dbcHandler->getFileByIdx(0)->messageHandler->removeMessageByIndex(thisRow); + dbcFile->messageHandler->removeMessageByIndex(thisRow); } } @@ -156,7 +163,7 @@ void DBCMainEditor::onCellChangedNode(int row,int col) QString newName = ui->NodesTable->item(row, col)->text().simplified().replace(' ', '_'); qDebug() << "new name: " << newName; if (newName.length() == 0) return; - if (dbcHandler->getFileByIdx(0)->findNodeByName(newName) != NULL) //duplicates an existing node! + if (dbcFile->findNodeByName(newName) != NULL) //duplicates an existing node! { QMessageBox msg; msg.setParent(0); @@ -165,8 +172,8 @@ void DBCMainEditor::onCellChangedNode(int row,int col) return; } newNode.name = newName; - dbcHandler->getFileByIdx(0)->dbc_nodes.append(newNode); - qDebug() << "# of nodes now " << dbcHandler->getFileByIdx(0)->dbc_nodes.count(); + dbcFile->dbc_nodes.append(newNode); + qDebug() << "# of nodes now " << dbcFile->dbc_nodes.count(); QTableWidgetItem *widgetName = new QTableWidgetItem(newName); inhibitCellChanged = true; ui->NodesTable->setItem(row, col, widgetName); @@ -178,7 +185,7 @@ void DBCMainEditor::onCellChangedNode(int row,int col) { if (col == 0) { - DBC_NODE *oldNode = dbcHandler->getFileByIdx(0)->findNodeByIdx(row); + DBC_NODE *oldNode = dbcFile->findNodeByIdx(row); QString nodeName = ui->NodesTable->item(row, col)->text().simplified().replace(' ', '_'); if (oldNode == NULL) return; if (row != 0) oldNode->name = nodeName; @@ -192,7 +199,7 @@ void DBCMainEditor::onCellChangedNode(int row,int col) { QString nodeName = ui->NodesTable->item(row, 0)->text().simplified().replace(' ', '_'); qDebug() << "searching for node " << nodeName; - DBC_NODE *thisNode = dbcHandler->getFileByIdx(0)->findNodeByName(nodeName); + DBC_NODE *thisNode = dbcFile->findNodeByName(nodeName); if (thisNode == NULL) return; thisNode->comment = ui->NodesTable->item(row, col)->text().simplified(); qDebug() << "New comment: " << thisNode->comment; @@ -213,7 +220,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) int msgLen; QString msgComment; DBC_MESSAGE newMsg; - DBC_NODE *node = dbcHandler->getFileByIdx(0)->findNodeByIdx(ui->NodesTable->currentRow()); + DBC_NODE *node = dbcFile->findNodeByIdx(ui->NodesTable->currentRow()); DBC_MESSAGE *msg; if (node == NULL) { @@ -224,14 +231,14 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) msgID = Utility::ParseStringToNum(ui->MessagesTable->item(row, 0)->text()); qDebug() << "Msg ID of edited: " << msgID; - msg = dbcHandler->getFileByIdx(0)->messageHandler->findMsgByID(msgID); + msg = dbcFile->messageHandler->findMsgByID(msgID); switch(col) { case 0: //msg id if (row == ui->MessagesTable->rowCount() - 1) //new record { - if (dbcHandler->getFileByIdx(0)->messageHandler->findMsgByID(msgID) != NULL) + if (dbcFile->messageHandler->findMsgByID(msgID) != NULL) { QMessageBox msg; msg.setParent(0); @@ -251,7 +258,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) break; } } - dbcHandler->getFileByIdx(0)->messageHandler->addMessage(newMsg); + dbcFile->messageHandler->addMessage(newMsg); } else //editing an existing record { @@ -270,7 +277,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) if (msgName.length() == 0) return; if (row == ui->MessagesTable->rowCount() - 1) //new record { - if (dbcHandler->getFileByIdx(0)->messageHandler->findMsgByName(msgName) != NULL) + if (dbcFile->messageHandler->findMsgByName(msgName) != NULL) { QMessageBox msg; msg.setParent(0); @@ -281,7 +288,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) newMsg.ID = -1; newMsg.name = msgName; newMsg.sender = node; - dbcHandler->getFileByIdx(0)->messageHandler->addMessage(newMsg); + dbcFile->messageHandler->addMessage(newMsg); } else { @@ -304,7 +311,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) newMsg.name = ""; newMsg.len = msgLen; newMsg.sender = node; - dbcHandler->getFileByIdx(0)->messageHandler->addMessage(newMsg); + dbcFile->messageHandler->addMessage(newMsg); } else //editing an existing record { @@ -328,7 +335,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) newMsg.len = 0; newMsg.comment = msgComment; newMsg.sender = node; - dbcHandler->getFileByIdx(0)->messageHandler->addMessage(newMsg); + dbcFile->messageHandler->addMessage(newMsg); } else //editing an existing record { @@ -363,7 +370,7 @@ void DBCMainEditor::onCellClickedNode(int row, int col) nodeName = item->text(); qDebug() << "Trying to find node with name " << nodeName; - DBC_NODE *node = dbcHandler->getFileByIdx(0)->findNodeByName(nodeName); + DBC_NODE *node = dbcFile->findNodeByName(nodeName); //qDebug() << "Address of node: " << (int)node; inhibitCellChanged = true; refreshMessagesTable(node); @@ -376,8 +383,9 @@ void DBCMainEditor::onCellClickedMessage(int row, int col) if (col == 3) //3 is the signals field. If clicked we go to the signals dialog { QString idString = ui->MessagesTable->item(row, 0)->text(); - DBC_MESSAGE *message = dbcHandler->getFileByIdx(0)->messageHandler->findMsgByID(Utility::ParseStringToNum(idString)); + DBC_MESSAGE *message = dbcFile->messageHandler->findMsgByID(Utility::ParseStringToNum(idString)); sigEditor->setMessageRef(message); + sigEditor->setFileIdx(fileIdx); sigEditor->exec(); //blocks this window from being active until we're done //now update the displayed # of signals inhibitCellChanged = true; @@ -394,17 +402,17 @@ void DBCMainEditor::refreshNodesTable() int rowIdx; - if (dbcHandler->getFileByIdx(0)->findNodeByName("Vector__XXX") == NULL) + if (dbcFile->findNodeByName("Vector__XXX") == NULL) { DBC_NODE newNode; newNode.name = "Vector__XXX"; newNode.comment = "Default node if no other node is specified"; - dbcHandler->getFileByIdx(0)->dbc_nodes.append(newNode); + dbcFile->dbc_nodes.append(newNode); } - for (int x = 0; x < dbcHandler->getFileByIdx(0)->dbc_nodes.count(); x++) + for (int x = 0; x < dbcFile->dbc_nodes.count(); x++) { - DBC_NODE node = dbcHandler->getFileByIdx(0)->dbc_nodes.at(x); + DBC_NODE node = dbcFile->dbc_nodes.at(x); QTableWidgetItem *nodeName = new QTableWidgetItem(node.name); QTableWidgetItem *nodeComment = new QTableWidgetItem(node.comment); rowIdx = ui->NodesTable->rowCount(); @@ -428,9 +436,9 @@ void DBCMainEditor::refreshMessagesTable(const DBC_NODE *node) if (node != NULL) { - for (int x = 0; x < dbcHandler->getFileByIdx(0)->messageHandler->getCount(); x++) + for (int x = 0; x < dbcFile->messageHandler->getCount(); x++) { - DBC_MESSAGE *msg = dbcHandler->getFileByIdx(0)->messageHandler->findMsgByIdx(x); + DBC_MESSAGE *msg = dbcFile->messageHandler->findMsgByIdx(x); if (msg->sender == node) { //many of these are simplistic first versions just to test functionality. diff --git a/dbcmaineditor.h b/dbcmaineditor.h index 0225cc8..07e8e11 100644 --- a/dbcmaineditor.h +++ b/dbcmaineditor.h @@ -18,6 +18,7 @@ class DBCMainEditor : public QDialog public: explicit DBCMainEditor(DBCHandler *handler, const QVector *frames, QWidget *parent = 0); ~DBCMainEditor(); + void setFileIdx(int idx); private slots: void onCellChangedNode(int,int); @@ -35,6 +36,8 @@ private: const QVector *referenceFrames; DBCSignalEditor *sigEditor; int currRow; + DBCFile *dbcFile; + int fileIdx; bool inhibitCellChanged; void refreshNodesTable(); diff --git a/dbcsignaleditor.cpp b/dbcsignaleditor.cpp index 5e1e395..c7f73e0 100644 --- a/dbcsignaleditor.cpp +++ b/dbcsignaleditor.cpp @@ -33,11 +33,6 @@ DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) : ui->comboType->addItem("DOUBLE PRECISION"); ui->comboType->addItem("STRING"); - for (int x = 0; x < dbcHandler->getFileByIdx(0)->dbc_nodes.count(); x++) - { - ui->comboReceiver->addItem(dbcHandler->getFileByIdx(0)->dbc_nodes[x].name); - } - connect(ui->signalsList, SIGNAL(currentRowChanged(int)), this, SLOT(clickSignalList(int))); connect(ui->bitfield, SIGNAL(gridClicked(int,int)), this, SLOT(bitfieldClicked(int,int))); connect(ui->signalsList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomMenuSignals(QPoint))); @@ -61,7 +56,7 @@ DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) : [=]() { if (currentSignal == NULL) return; - currentSignal->receiver = dbcHandler->getFileByIdx(0)->findNodeByName(ui->comboReceiver->currentText()); + currentSignal->receiver = dbcFile->findNodeByName(ui->comboReceiver->currentText()); }); connect(ui->comboType, &QComboBox::currentTextChanged, [=]() @@ -223,6 +218,17 @@ void DBCSignalEditor::closeEvent(QCloseEvent *event) writeSettings(); } +void DBCSignalEditor::setFileIdx(int idx) +{ + if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return; + dbcFile = dbcHandler->getFileByIdx(idx); + + for (int x = 0; x < dbcFile->dbc_nodes.count(); x++) + { + ui->comboReceiver->addItem(dbcFile->dbc_nodes[x].name); + } +} + void DBCSignalEditor::readSettings() { QSettings settings; @@ -326,7 +332,7 @@ void DBCSignalEditor::addNewSignal() newSig.intelByteOrder = true; newSig.max = 0.0; newSig.min = 0.0; - newSig.receiver = dbcHandler->getFileByIdx(0)->findNodeByIdx(0); + newSig.receiver = dbcFile->findNodeByIdx(0); newSig.signalSize = 1; newSig.startBit = 0; newSig.valType = UNSIGNED_INT; diff --git a/dbcsignaleditor.h b/dbcsignaleditor.h index beef97b..5d89e14 100644 --- a/dbcsignaleditor.h +++ b/dbcsignaleditor.h @@ -17,6 +17,7 @@ public: explicit DBCSignalEditor(DBCHandler *handler, QWidget *parent = 0); void setMessageRef(DBC_MESSAGE *msg); void showEvent(QShowEvent*); + void setFileIdx(int idx); ~DBCSignalEditor(); private slots: @@ -34,6 +35,7 @@ private: DBCHandler *dbcHandler; DBC_MESSAGE *dbcMessage; DBC_SIGNAL *currentSignal; + DBCFile *dbcFile; bool inhibitCellChanged; void refreshSignalsList(); diff --git a/mainwindow.cpp b/mainwindow.cpp index b50ca67..3975a78 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -94,6 +94,7 @@ MainWindow::MainWindow(QWidget *parent) : connectionWindow = NULL; scriptingWindow = NULL; rangeWindow = NULL; + dbcFileWindow = NULL; dbcHandler = new DBCHandler; bDirty = false; inhibitFilterUpdate = false; @@ -113,13 +114,10 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->action_Playback, &QAction::triggered, this, &MainWindow::showPlaybackWindow); connect(ui->actionFlow_View, &QAction::triggered, this, &MainWindow::showFlowViewWindow); connect(ui->action_Custom, &QAction::triggered, this, &MainWindow::showFrameSenderWindow); - connect(ui->actionLoad_DBC_File, &QAction::triggered, this, &MainWindow::handleLoadDBC); - connect(ui->actionSave_DBC_File, &QAction::triggered, this, &MainWindow::handleSaveDBC); connect(ui->canFramesView, &QAbstractItemView::clicked, this, &MainWindow::gridClicked); connect(ui->canFramesView, &QAbstractItemView::doubleClicked, this, &MainWindow::gridDoubleClicked); connect(ui->cbInterpret, &QAbstractButton::toggled, this, &MainWindow::interpretToggled); connect(ui->cbOverwrite, &QAbstractButton::toggled, this, &MainWindow::overwriteToggled); - connect(ui->actionEdit_Messages_Signals, &QAction::triggered, this, &MainWindow::showDBCEditor); connect(ui->btnCaptureToggle, &QAbstractButton::clicked, this, &MainWindow::toggleCapture); connect(ui->actionExit_Application, &QAction::triggered, this, &MainWindow::exitApp); connect(ui->actionFuzzy_Scope, &QAction::triggered, this, &MainWindow::showFuzzyScopeWindow); @@ -135,6 +133,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->btnFilterAll, &QAbstractButton::clicked, this, &MainWindow::filterSetAll); connect(ui->btnFilterNone, &QAbstractButton::clicked, this, &MainWindow::filterClearAll); connect(ui->actionFirmware_Uploader, &QAction::triggered, this, &MainWindow::showFirmwareUploaderWindow); + connect(ui->actionDBC_File_Manager, &QAction::triggered, this, &MainWindow::showDBCFileWindow); lbStatusConnected.setText(tr("Not connected")); updateFileStatus(); @@ -240,12 +239,36 @@ MainWindow::~MainWindow() delete rangeWindow; } + if (dbcFileWindow) + { + dbcFileWindow->close(); + delete dbcFileWindow; + } + delete ui; delete dbcHandler; model->clearFrames(); delete model; } +void MainWindow::exitApp() +{ + if (graphingWindow) graphingWindow->close(); + if (frameInfoWindow) frameInfoWindow->close(); + if (playbackWindow) playbackWindow->close(); + if (flowViewWindow) flowViewWindow->close(); + if (frameSenderWindow) frameSenderWindow->close(); + if (dbcMainEditor) dbcMainEditor->close(); + if (comparatorWindow) comparatorWindow->close(); + if (connectionWindow) connectionWindow->close(); + if (settingsDialog) settingsDialog->close(); + if (discreteStateWindow) discreteStateWindow->close(); + if (scriptingWindow) scriptingWindow->close(); + if (rangeWindow) rangeWindow->close(); + if (dbcFileWindow) dbcFileWindow->close(); + this->close(); +} + void MainWindow::closeEvent(QCloseEvent *event) { Q_UNUSED(event); @@ -753,18 +776,7 @@ void MainWindow::handleLoadFilters() } } -void MainWindow::handleLoadDBC() -{ - dbcHandler->loadDBCFile(-1); - - //lbStatusDatabase.setText(fileList[fileList.length() - 1] + tr(" loaded.")); -} - -void MainWindow::handleSaveDBC() -{ - dbcHandler->saveDBCFile(0); - //lbStatusDatabase.setText(fileList[fileList.length() - 1] + tr(" loaded.")); -} +//lbStatusDatabase.setText(fileList[fileList.length() - 1] + tr(" loaded.")); void MainWindow::handleSaveDecoded() { @@ -1064,19 +1076,6 @@ void MainWindow::showFuzzyScopeWindow() //not done yet } -void MainWindow::exitApp() -{ - if (graphingWindow) graphingWindow->close(); - if (frameInfoWindow) frameInfoWindow->close(); - if (playbackWindow) playbackWindow->close(); - if (flowViewWindow) flowViewWindow->close(); - if (frameSenderWindow) frameSenderWindow->close(); - if (dbcMainEditor) dbcMainEditor->close(); - if (comparatorWindow) comparatorWindow->close(); - if (connectionWindow) connectionWindow->close(); - this->close(); -} - void MainWindow::showFlowViewWindow() { if (!flowViewWindow) @@ -1098,14 +1097,13 @@ void MainWindow::showFlowViewWindow() flowViewWindow->show(); } -//this one always gets the unfiltered list intentionally. -void MainWindow::showDBCEditor() +void MainWindow::showDBCFileWindow() { - if (!dbcMainEditor) + if (!dbcFileWindow) { - dbcMainEditor = new DBCMainEditor(dbcHandler, model->getListReference()); + dbcFileWindow = new DBCLoadSaveWindow(dbcHandler, model->getListReference()); } - dbcMainEditor->show(); + dbcFileWindow->show(); } void MainWindow::showConnectionSettingsWindow() diff --git a/mainwindow.h b/mainwindow.h index 3bbb2e0..d377ac6 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -22,6 +22,7 @@ #include "connectionwindow.h" #include "scriptingwindow.h" #include "rangestatewindow.h" +#include "dbcloadsavewindow.h" namespace Ui { class MainWindow; @@ -42,8 +43,6 @@ private slots: void handleLoadFile(); void handleSaveFile(); void handleSaveFilteredFile(); - void handleLoadDBC(); - void handleSaveDBC(); void handleSaveFilters(); void handleLoadFilters(); void connButtonPress(); @@ -61,6 +60,7 @@ private slots: void showFirmwareUploaderWindow(); void showConnectionSettingsWindow(); void showScriptingWindow(); + void showDBCFileWindow(); void exitApp(); void handleSaveDecoded(); void changeBaudRates(); @@ -71,7 +71,6 @@ private slots: void gridDoubleClicked(QModelIndex); void interpretToggled(bool); void overwriteToggled(bool); - void showDBCEditor(); void toggleCapture(); void normalizeTiming(); void updateFilterList(); @@ -129,6 +128,7 @@ private: ConnectionWindow *connectionWindow; ScriptingWindow *scriptingWindow; RangeStateWindow *rangeWindow; + DBCLoadSaveWindow *dbcFileWindow; //various private storage QLabel lbStatusConnected; diff --git a/mainwindow.ui b/mainwindow.ui index b2dd3e8..07b6e44 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -230,9 +230,7 @@ - - - + @@ -355,7 +353,7 @@ Connect - + @@ -372,6 +370,11 @@ Single/Multi State + + + DBC File Manager + +