diff --git a/canframemodel.cpp b/canframemodel.cpp index 63f2a02..69d3b98 100644 --- a/canframemodel.cpp +++ b/canframemodel.cpp @@ -184,6 +184,7 @@ QVariant CANFrameModel::data(const QModelIndex &index, int role) const if (msg != NULL) { tempString.append("\r\n"); + tempString.append(msg->name + " " + msg->comment + "\r\n"); for (int j = 0; j < msg->msgSignals.length(); j++) { diff --git a/dbcmaineditor.cpp b/dbcmaineditor.cpp index 823793d..e6052f3 100644 --- a/dbcmaineditor.cpp +++ b/dbcmaineditor.cpp @@ -5,7 +5,7 @@ #include #include -DBCMainEditor::DBCMainEditor(DBCHandler *handler, QWidget *parent) : +DBCMainEditor::DBCMainEditor(DBCHandler *handler, const QVector *frames, QWidget *parent) : QDialog(parent), ui(new Ui::DBCMainEditor) { @@ -14,6 +14,7 @@ DBCMainEditor::DBCMainEditor(DBCHandler *handler, QWidget *parent) : readSettings(); dbcHandler = handler; + referenceFrames = frames; QStringList headers; headers << "Node Name" << "Comment"; @@ -208,16 +209,16 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) QString msgName; int msgLen; QString msgComment; + DBC_MESSAGE newMsg; DBC_NODE *node = dbcHandler->findNodeByIdx(ui->NodesTable->currentRow()); if (node == NULL) dbcHandler->findNodeByIdx(0); switch(col) { case 0: //msg id - msgID = ui->MessagesTable->item(row, col)->text().toInt(NULL, 16); + msgID = ui->MessagesTable->item(row, col)->text().toInt(NULL, 16); if (row == ui->MessagesTable->rowCount() - 1) //new record - { - DBC_MESSAGE newMsg; + { if (dbcHandler->findMsgByID(msgID) != NULL) { QMessageBox msg; @@ -229,6 +230,15 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) newMsg.ID = msgID; newMsg.name = ""; newMsg.sender = node; + newMsg.len = 0; + for (int i = 0; i < referenceFrames->length(); i++) + { + if (referenceFrames->at(i).ID == msgID) + { + newMsg.len = referenceFrames->at(i).len; + break; + } + } dbcHandler->dbc_messages.append(newMsg); } else //editing an existing record @@ -239,6 +249,8 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) inhibitCellChanged = true; replacement = new QTableWidgetItem(QString::number(msgID, 16)); ui->MessagesTable->setItem(row, col, replacement); + replacement = new QTableWidgetItem(QString::number(newMsg.len)); + ui->MessagesTable->setItem(row, 2, replacement); inhibitCellChanged = false; break; @@ -246,8 +258,7 @@ void DBCMainEditor::onCellChangedMessage(int row,int col) msgName = ui->MessagesTable->item(row, col)->text().simplified().replace(' ', '_'); if (msgName.length() == 0) return; if (row == ui->MessagesTable->rowCount() - 1) //new record - { - DBC_MESSAGE newMsg; + { if (dbcHandler->findMsgByName(msgName) != NULL) { QMessageBox msg; diff --git a/dbcmaineditor.h b/dbcmaineditor.h index 92ca593..36e8fd9 100644 --- a/dbcmaineditor.h +++ b/dbcmaineditor.h @@ -15,7 +15,7 @@ class DBCMainEditor : public QDialog Q_OBJECT public: - explicit DBCMainEditor(DBCHandler *handler, QWidget *parent = 0); + explicit DBCMainEditor(DBCHandler *handler, const QVector *frames, QWidget *parent = 0); ~DBCMainEditor(); private slots: @@ -31,6 +31,7 @@ private slots: private: Ui::DBCMainEditor *ui; DBCHandler *dbcHandler; + const QVector *referenceFrames; DBCSignalEditor *sigEditor; int currRow; bool inhibitCellChanged; diff --git a/dbcsignaleditor.cpp b/dbcsignaleditor.cpp index d4350cc..aae51f9 100644 --- a/dbcsignaleditor.cpp +++ b/dbcsignaleditor.cpp @@ -44,7 +44,7 @@ DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) : ui->signalsList->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->valuesTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onCustomMenuValues(QPoint))); ui->valuesTable->setContextMenuPolicy(Qt::CustomContextMenu); - + connect(ui->valuesTable, SIGNAL(cellChanged(int,int)), this, SLOT(onValuesCellChanged(int,int))); //now with 100% more lambda expressions just to make it interesting (and shorter, and easier...) connect(ui->cbIntelFormat, &QCheckBox::toggled, @@ -140,7 +140,7 @@ DBCSignalEditor::DBCSignalEditor(DBCHandler *handler, QWidget *parent) : { currentSignal->name = ui->txtName->text(); //need to update the list too. - //ui->signalsList->currentItem()->setText(currentSignal->name); + ui->signalsList->currentItem()->setText(currentSignal->name); }); @@ -190,13 +190,43 @@ void DBCSignalEditor::showEvent(QShowEvent* event) refreshSignalsList(); currentSignal = NULL; if (dbcMessage->msgSignals.count() > 0) - { + { currentSignal = &dbcMessage->msgSignals[0]; fillSignalForm(currentSignal); fillValueTable(currentSignal); } } +void DBCSignalEditor::onValuesCellChanged(int row,int col) +{ + if (inhibitCellChanged) return; + if (row == ui->valuesTable->rowCount() - 1) + { + DBC_VAL newVal; + newVal.value = 0; + newVal.descript = "No Description"; + currentSignal->valList.append(newVal); + qDebug() << "Created new entry in value list"; + + //QTableWidgetItem *widgetVal = new QTableWidgetItem(QString::number(newVal.value)); + //ui->valuesTable->setItem(row, 0, widgetVal); + //QTableWidgetItem *widgetDesc = new QTableWidgetItem(newVal.descript); + //ui->valuesTable->setItem(row, 1, widgetDesc); + + //add the blank at the end again + ui->valuesTable->insertRow(ui->valuesTable->rowCount()); + } + + if (col == 0) + { + currentSignal->valList[row].value = ui->valuesTable->item(row, col)->text().toInt(); + } + else if (col == 1) + { + currentSignal->valList[row].descript = ui->valuesTable->item(row, col)->text(); + } +} + void DBCSignalEditor::onCustomMenuSignals(QPoint point) { QMenu *menu = new QMenu(this); @@ -365,10 +395,16 @@ void DBCSignalEditor::fillSignalForm(DBC_SIGNAL *sig) void DBCSignalEditor::fillValueTable(DBC_SIGNAL *sig) { int rowIdx; + + inhibitCellChanged = true; + ui->valuesTable->clearContents(); ui->valuesTable->setRowCount(0); - if (sig == NULL) return; + if (sig == NULL) { + inhibitCellChanged = false; + return; + } for (int i = 0; i < sig->valList.count(); i++) { @@ -379,6 +415,11 @@ void DBCSignalEditor::fillValueTable(DBC_SIGNAL *sig) ui->valuesTable->setItem(rowIdx, 0, val); ui->valuesTable->setItem(rowIdx, 1, desc); } + + //Add a blank row at the end to allow for adding records easily + ui->valuesTable->insertRow(ui->valuesTable->rowCount()); + + inhibitCellChanged = false; } void DBCSignalEditor::clickSignalList(int row) diff --git a/dbcsignaleditor.h b/dbcsignaleditor.h index d19ae06..7004da3 100644 --- a/dbcsignaleditor.h +++ b/dbcsignaleditor.h @@ -21,6 +21,7 @@ public: private slots: void clickSignalList(int); void bitfieldClicked(int x, int y); + void onValuesCellChanged(int row,int col); void onCustomMenuSignals(QPoint); void onCustomMenuValues(QPoint); void addNewSignal(); @@ -32,6 +33,7 @@ private: DBCHandler *dbcHandler; DBC_MESSAGE *dbcMessage; DBC_SIGNAL *currentSignal; + bool inhibitCellChanged; void refreshSignalsList(); void fillSignalForm(DBC_SIGNAL *sig); diff --git a/mainwindow.cpp b/mainwindow.cpp index 5e5fda0..96e50fe 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -872,7 +872,7 @@ void MainWindow::showDBCEditor() { if (!dbcMainEditor) { - dbcMainEditor = new DBCMainEditor(dbcHandler); + dbcMainEditor = new DBCMainEditor(dbcHandler, model->getListReference()); } dbcMainEditor->show(); }