Added ability to create new DBC files from the DBC file manager,

hooked up ability to change associated bus for DBC files.
This commit is contained in:
Collin Kidder
2016-01-21 20:49:51 -05:00
parent a42d9532d7
commit c41815e628
5 changed files with 39 additions and 2 deletions
+7
View File
@@ -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.
+1
View File
@@ -86,6 +86,7 @@ public:
int getFileCount();
DBCFile* getFileByIdx(int idx);
DBCFile* getFileByName(QString name);
int createBlankFile();
private:
QList<DBCFile> loadedFiles;
+23 -2
View File
@@ -24,6 +24,7 @@ DBCLoadSaveWindow::DBCLoadSaveWindow(DBCHandler *handler, const QVector<CANFrame
connect(ui->btnMoveUp, &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)
+1
View File
@@ -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;
+7
View File
@@ -17,6 +17,13 @@
<item>
<widget class="QTableWidget" name="tableFiles"/>
</item>
<item>
<widget class="QPushButton" name="btnNewDBC">
<property name="text">
<string>Create new DBC</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>