diff --git a/dbchandler.cpp b/dbchandler.cpp index 4de879c..2851c60 100644 --- a/dbchandler.cpp +++ b/dbchandler.cpp @@ -731,6 +731,13 @@ void DBCHandler::saveDBCFile(int idx) } } +int DBCHandler::createBlankFile() +{ + DBCFile newFile; + loadedFiles.append(newFile); + return loadedFiles.count(); +} + //the only reason to even bother sending the index is to see if //the user wants to replace an already loaded DBC. //Otherwise add a new one. Well, always add a new one. diff --git a/dbchandler.h b/dbchandler.h index e6c2770..80376da 100644 --- a/dbchandler.h +++ b/dbchandler.h @@ -86,6 +86,7 @@ public: int getFileCount(); DBCFile* getFileByIdx(int idx); DBCFile* getFileByName(QString name); + int createBlankFile(); private: QList loadedFiles; diff --git a/dbcloadsavewindow.cpp b/dbcloadsavewindow.cpp index 5b6c461..e66a9b5 100644 --- a/dbcloadsavewindow.cpp +++ b/dbcloadsavewindow.cpp @@ -24,6 +24,7 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(DBCHandler *handler, const QVectorbtnMoveUp, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::moveUp); connect(ui->btnRemove, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::removeFile); connect(ui->btnSave, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::saveFile); + connect(ui->btnNewDBC, &QAbstractButton::clicked, this, &DBCLoadSaveWindow::newFile); connect(ui->tableFiles, &QTableWidget::cellChanged, this, &DBCLoadSaveWindow::cellChanged); connect(ui->tableFiles, &QTableWidget::cellDoubleClicked, this, &DBCLoadSaveWindow::cellDoubleClicked); @@ -35,6 +36,15 @@ DBCLoadSaveWindow::~DBCLoadSaveWindow() delete ui; } +void DBCLoadSaveWindow::newFile() +{ + int idx = dbcHandler->createBlankFile(); + idx = ui->tableFiles->rowCount(); + ui->tableFiles->insertRow(ui->tableFiles->rowCount()); + ui->tableFiles->setItem(idx, 0, new QTableWidgetItem("UNNAMEDFILE")); + ui->tableFiles->setItem(idx, 1, new QTableWidgetItem("-1")); +} + void DBCLoadSaveWindow::loadFile() { DBCFile *file = dbcHandler->loadDBCFile(-1); @@ -49,6 +59,8 @@ void DBCLoadSaveWindow::saveFile() int idx = ui->tableFiles->currentRow(); if (idx < 0) return; dbcHandler->saveDBCFile(idx); + //then update the list to show the new file name (if it changed) + ui->tableFiles->setItem(idx, 0, new QTableWidgetItem(dbcHandler->getFileByIdx(idx)->getFullFilename())); } void DBCLoadSaveWindow::removeFile() @@ -87,12 +99,21 @@ void DBCLoadSaveWindow::editFile() void DBCLoadSaveWindow::cellChanged(int row, int col) { - + if (col == 1) //the bus column + { + DBCFile *file = dbcHandler->getFileByIdx(row); + int bus = ui->tableFiles->item(row, col)->text().toInt(); + if (bus > -2 && bus < 2) + { + file->setAssocBus(bus); + } + } } void DBCLoadSaveWindow::cellDoubleClicked(int row, int col) { - + editorWindow->setFileIdx(row); + editorWindow->show(); } void DBCLoadSaveWindow::swapTableRows(bool up) diff --git a/dbcloadsavewindow.h b/dbcloadsavewindow.h index 2ccdd55..41e33ac 100644 --- a/dbcloadsavewindow.h +++ b/dbcloadsavewindow.h @@ -27,6 +27,7 @@ private slots: void editFile(); void cellChanged(int row, int col); void cellDoubleClicked(int row, int col); + void newFile(); private: Ui::DBCLoadSaveWindow *ui; diff --git a/dbcloadsavewindow.ui b/dbcloadsavewindow.ui index ea48481..d32abf1 100644 --- a/dbcloadsavewindow.ui +++ b/dbcloadsavewindow.ui @@ -17,6 +17,13 @@ + + + + Create new DBC + + +