More implementation of signal/message editing

This commit is contained in:
Collin Kidder
2015-06-09 20:40:54 -04:00
parent faedc6da3d
commit 27ab4aade7
4 changed files with 145 additions and 4 deletions
+14
View File
@@ -288,11 +288,25 @@ DBC_MESSAGE *DBCHandler::findMsgByID(int id)
DBC_MESSAGE *DBCHandler::findMsgByIdx(int idx) DBC_MESSAGE *DBCHandler::findMsgByIdx(int idx)
{ {
if (dbc_messages.length() == 0) return NULL;
if (idx < 0) return NULL; if (idx < 0) return NULL;
if (idx >= dbc_messages.count()) return NULL; if (idx >= dbc_messages.count()) return NULL;
return &dbc_messages[idx]; return &dbc_messages[idx];
} }
DBC_MESSAGE *DBCHandler::findMsgByName(QString name)
{
if (dbc_messages.length() == 0) return NULL;
for (int i = 0; i < dbc_messages.length(); i++)
{
if (dbc_messages[i].name.compare(name, Qt::CaseInsensitive))
{
return &dbc_messages[i];
}
}
return NULL;
}
DBC_SIGNAL *DBCHandler::findSignalByName(DBC_MESSAGE *msg, QString name) DBC_SIGNAL *DBCHandler::findSignalByName(DBC_MESSAGE *msg, QString name)
{ {
if (msg == NULL) return NULL; if (msg == NULL) return NULL;
+1
View File
@@ -23,6 +23,7 @@ public:
DBC_MESSAGE *findMsgByID(int id); DBC_MESSAGE *findMsgByID(int id);
DBC_MESSAGE *findMsgByIdx(int idx); DBC_MESSAGE *findMsgByIdx(int idx);
DBC_MESSAGE *findMsgByName(QString name);
DBC_SIGNAL *findSignalByName(DBC_MESSAGE *msg, QString name); DBC_SIGNAL *findSignalByName(DBC_MESSAGE *msg, QString name);
DBC_SIGNAL *findSignalByIdx(DBC_MESSAGE *msg, int idx); DBC_SIGNAL *findSignalByIdx(DBC_MESSAGE *msg, int idx);
+125 -2
View File
@@ -120,6 +120,125 @@ void DBCMainEditor::onCellChangedNode(int row,int col)
void DBCMainEditor::onCellChangedMessage(int row,int col) void DBCMainEditor::onCellChangedMessage(int row,int col)
{ {
if (inhibitCellChanged) return; if (inhibitCellChanged) return;
QTableWidgetItem *replacement = NULL;
int msgID;
QString msgName;
int msgLen;
QString msgComment;
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);
if (row == ui->MessagesTable->rowCount() - 1) //new record
{
DBC_MESSAGE newMsg;
if (dbcHandler->findMsgByID(msgID) != NULL)
{
QMessageBox msg;
msg.setText("An existing msg with that ID already exists! Aborting!");
msg.show();
return;
}
newMsg.ID = msgID;
newMsg.name = "";
newMsg.sender = node;
dbcHandler->dbc_messages.append(newMsg);
}
else //editing an existing record
{
DBC_MESSAGE *msg = dbcHandler->findMsgByIdx(row);
msg->ID = msgID;
}
inhibitCellChanged = true;
replacement = new QTableWidgetItem(QString::number(msgID, 16));
ui->MessagesTable->setItem(row, col, replacement);
inhibitCellChanged = false;
break;
case 1: //msg name
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;
msg.setText("An existing msg with that name already exists! Aborting!");
msg.show();
return;
}
newMsg.ID = -1;
newMsg.name = msgName;
newMsg.sender = node;
dbcHandler->dbc_messages.append(newMsg);
}
else
{
DBC_MESSAGE *msg = dbcHandler->findMsgByIdx(row);
msg->name = msgName;
}
inhibitCellChanged = true;
replacement = new QTableWidgetItem(msgName);
ui->MessagesTable->setItem(row, col, replacement);
inhibitCellChanged = false;
break;
case 2: //data length
msgLen = ui->MessagesTable->item(row, col)->text().toInt();
if (msgLen < 0) msgLen = 0;
if (msgLen > 8) msgLen = 8;
if (row == ui->MessagesTable->rowCount() - 1) //new record
{
DBC_MESSAGE newMsg;
newMsg.ID = -1;
newMsg.name = "";
newMsg.len = msgLen;
newMsg.sender = node;
dbcHandler->dbc_messages.append(newMsg);
}
else //editing an existing record
{
DBC_MESSAGE *msg = dbcHandler->findMsgByIdx(row);
msg->len = msgLen;
}
inhibitCellChanged = true;
replacement = new QTableWidgetItem(QString::number(msgLen, 16));
ui->MessagesTable->setItem(row, col, replacement);
inhibitCellChanged = false;
break;
case 3: //signals (number) - we don't handle anything here. User cannot directly change this value
break;
case 4: //comment
msgComment = ui->MessagesTable->item(row, col)->text().simplified();
if (row == ui->MessagesTable->rowCount() - 1) //new record
{
DBC_MESSAGE newMsg;
newMsg.ID = -1;
newMsg.name = "";
newMsg.len = 0;
newMsg.comment = msgComment;
newMsg.sender = node;
dbcHandler->dbc_messages.append(newMsg);
}
else //editing an existing record
{
DBC_MESSAGE *msg = dbcHandler->findMsgByIdx(row);
msg->comment = msgComment;
}
inhibitCellChanged = true;
replacement = new QTableWidgetItem(msgComment);
ui->MessagesTable->setItem(row, col, replacement);
inhibitCellChanged = false;
break;
}
if (row == ui->MessagesTable->rowCount() - 1) if (row == ui->MessagesTable->rowCount() - 1)
{ {
ui->MessagesTable->insertRow(ui->MessagesTable->rowCount()); ui->MessagesTable->insertRow(ui->MessagesTable->rowCount());
@@ -129,19 +248,21 @@ void DBCMainEditor::onCellChangedMessage(int row,int col)
void DBCMainEditor::onCellClickedNode(int row, int col) void DBCMainEditor::onCellClickedNode(int row, int col)
{ {
//reload messages list if the currently selected row has changed. //reload messages list if the currently selected row has changed.
qDebug() << "Entered at row " << row << " col " << col; qDebug() << "Clicked at row " << row << " col " << col;
if (row != currRow) if (row != currRow)
{ {
currRow = row; currRow = row;
QTableWidgetItem *item = ui->NodesTable->item(currRow, 0); QTableWidgetItem *item = ui->NodesTable->item(currRow, 0);
QString nodeName; QString nodeName;
if (nodeName == NULL) return; if (item == NULL) return;
nodeName = item->text(); nodeName = item->text();
qDebug() << "Trying to find node with name " << nodeName; qDebug() << "Trying to find node with name " << nodeName;
DBC_NODE *node = dbcHandler->findNodeByName(nodeName); DBC_NODE *node = dbcHandler->findNodeByName(nodeName);
//qDebug() << "Address of node: " << (int)node; //qDebug() << "Address of node: " << (int)node;
inhibitCellChanged = true;
refreshMessagesTable(node); refreshMessagesTable(node);
inhibitCellChanged = false;
} }
} }
@@ -183,6 +304,8 @@ void DBCMainEditor::refreshMessagesTable(const DBC_NODE *node)
ui->MessagesTable->clearContents(); ui->MessagesTable->clearContents();
ui->MessagesTable->setRowCount(0); ui->MessagesTable->setRowCount(0);
qDebug() << "In refreshMessagesTable";
int rowIdx; int rowIdx;
if (node != NULL) if (node != NULL)
+3
View File
@@ -46,9 +46,12 @@ void DBCSignalEditor::showEvent(QShowEvent* event)
QDialog::showEvent(event); QDialog::showEvent(event);
refreshSignalsList(); refreshSignalsList();
if (dbcMessage->msgSignals.count() > 0)
{
fillSignalForm(&dbcMessage->msgSignals[0]); fillSignalForm(&dbcMessage->msgSignals[0]);
fillValueTable(&dbcMessage->msgSignals[0]); fillValueTable(&dbcMessage->msgSignals[0]);
} }
}
void DBCSignalEditor::refreshSignalsList() void DBCSignalEditor::refreshSignalsList()
{ {