Additional work to implement some of the editing in the signal/message editor. There is a long way to go still.
This commit is contained in:
@@ -266,6 +266,13 @@ DBC_NODE *DBCHandler::findNodeByName(QString name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBC_NODE *DBCHandler::findNodeByIdx(int idx)
|
||||
{
|
||||
if (idx < 0) return NULL;
|
||||
if (idx >= dbc_nodes.count()) return NULL;
|
||||
return &dbc_nodes[idx];
|
||||
}
|
||||
|
||||
DBC_MESSAGE *DBCHandler::findMsgByID(int id)
|
||||
{
|
||||
if (dbc_messages.length() == 0) return NULL;
|
||||
@@ -279,6 +286,13 @@ DBC_MESSAGE *DBCHandler::findMsgByID(int id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBC_MESSAGE *DBCHandler::findMsgByIdx(int idx)
|
||||
{
|
||||
if (idx < 0) return NULL;
|
||||
if (idx >= dbc_messages.count()) return NULL;
|
||||
return &dbc_messages[idx];
|
||||
}
|
||||
|
||||
DBC_SIGNAL *DBCHandler::findSignalByName(DBC_MESSAGE *msg, QString name)
|
||||
{
|
||||
if (msg == NULL) return NULL;
|
||||
@@ -293,6 +307,15 @@ DBC_SIGNAL *DBCHandler::findSignalByName(DBC_MESSAGE *msg, QString name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBC_SIGNAL *DBCHandler::findSignalByIdx(DBC_MESSAGE *msg, int idx)
|
||||
{
|
||||
if (msg == NULL) return NULL;
|
||||
if (msg->msgSignals.length() == 0) return NULL;
|
||||
if (idx < 0) return NULL;
|
||||
if (idx >= msg->msgSignals.count()) return NULL;
|
||||
return &msg->msgSignals[idx];
|
||||
}
|
||||
|
||||
//Dumps the messages, signals, values structs out in order to debugging console. Used only for debugging
|
||||
//not really meant for general consumption.
|
||||
void DBCHandler::listDebugging()
|
||||
|
||||
@@ -19,8 +19,13 @@ public:
|
||||
void listDebugging();
|
||||
QString processSignal(const CANFrame &frame, const DBC_SIGNAL &sig);
|
||||
DBC_NODE *findNodeByName(QString name);
|
||||
DBC_NODE *findNodeByIdx(int idx);
|
||||
|
||||
DBC_MESSAGE *findMsgByID(int id);
|
||||
DBC_MESSAGE *findMsgByIdx(int idx);
|
||||
|
||||
DBC_SIGNAL *findSignalByName(DBC_MESSAGE *msg, QString name);
|
||||
DBC_SIGNAL *findSignalByIdx(DBC_MESSAGE *msg, int idx);
|
||||
|
||||
QList<DBC_NODE> dbc_nodes;
|
||||
QList<DBC_MESSAGE> dbc_messages;
|
||||
|
||||
+82
-8
@@ -1,6 +1,8 @@
|
||||
#include "dbcmaineditor.h"
|
||||
#include "ui_dbcmaineditor.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
DBCMainEditor::DBCMainEditor(DBCHandler *handler, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DBCMainEditor)
|
||||
@@ -28,20 +30,29 @@ DBCMainEditor::DBCMainEditor(DBCHandler *handler, QWidget *parent) :
|
||||
ui->MessagesTable->setHorizontalHeaderLabels(headers2);
|
||||
ui->MessagesTable->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
|
||||
refreshNodesTable();
|
||||
refreshMessagesTable(&dbcHandler->dbc_nodes.at(0));
|
||||
currRow = 0;
|
||||
|
||||
connect(ui->NodesTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChangedNode(int,int)));
|
||||
connect(ui->NodesTable, SIGNAL(cellClicked(int,int)), this, SLOT(onCellClickedNode(int,int)));
|
||||
|
||||
|
||||
connect(ui->MessagesTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChangedMessage(int,int)));
|
||||
connect(ui->MessagesTable, SIGNAL(cellClicked(int,int)), this, SLOT(onCellClickedMessage(int,int)));
|
||||
|
||||
sigEditor = new DBCSignalEditor(handler);
|
||||
}
|
||||
|
||||
void DBCMainEditor::showEvent(QShowEvent* event)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
|
||||
inhibitCellChanged = true;
|
||||
refreshNodesTable();
|
||||
if (dbcHandler->dbc_nodes.count() > 0)
|
||||
refreshMessagesTable(&dbcHandler->dbc_nodes.at(0));
|
||||
|
||||
currRow = 0;
|
||||
inhibitCellChanged = false;
|
||||
}
|
||||
|
||||
DBCMainEditor::~DBCMainEditor()
|
||||
{
|
||||
delete ui;
|
||||
@@ -50,22 +61,83 @@ DBCMainEditor::~DBCMainEditor()
|
||||
|
||||
void DBCMainEditor::onCellChangedNode(int row,int col)
|
||||
{
|
||||
if (inhibitCellChanged) return;
|
||||
if (row == ui->NodesTable->rowCount() - 1)
|
||||
{
|
||||
//if this was the last row then it's new and we need to both
|
||||
//create another potentially new record underneath and also
|
||||
//add a node entry in the nodes list and store the record
|
||||
//That is, so long as the node name was filled out
|
||||
if (col == 0)
|
||||
{
|
||||
DBC_NODE newNode;
|
||||
QString newName = ui->NodesTable->item(row, col)->text().simplified().replace(' ', '_');
|
||||
qDebug() << "new name: " << newName;
|
||||
if (newName.length() == 0) return;
|
||||
if (dbcHandler->findNodeByName(newName) != NULL) //duplicates an existing node!
|
||||
{
|
||||
QMessageBox msg;
|
||||
msg.setText("An existing node with that name already exists! Aborting!");
|
||||
msg.show();
|
||||
return;
|
||||
}
|
||||
newNode.name = newName;
|
||||
dbcHandler->dbc_nodes.append(newNode);
|
||||
qDebug() << "# of nodes now " << dbcHandler->dbc_nodes.count();
|
||||
QTableWidgetItem *widgetName = new QTableWidgetItem(newName);
|
||||
inhibitCellChanged = true;
|
||||
ui->NodesTable->setItem(row, col, widgetName);
|
||||
ui->NodesTable->insertRow(ui->NodesTable->rowCount());
|
||||
inhibitCellChanged = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (col == 0)
|
||||
{
|
||||
DBC_NODE *oldNode = dbcHandler->findNodeByIdx(row);
|
||||
QString nodeName = ui->NodesTable->item(row, col)->text().simplified().replace(' ', '_');
|
||||
if (oldNode == NULL) return;
|
||||
oldNode->name = nodeName;
|
||||
inhibitCellChanged = true;
|
||||
QTableWidgetItem *widgetName = new QTableWidgetItem(nodeName);
|
||||
ui->NodesTable->setItem(row, col, widgetName);
|
||||
inhibitCellChanged = false;
|
||||
}
|
||||
if (col == 1) //must have been col 1 then
|
||||
{
|
||||
QString nodeName = ui->NodesTable->item(row, 0)->text().simplified().replace(' ', '_');
|
||||
qDebug() << "searching for node " << nodeName;
|
||||
DBC_NODE *thisNode = dbcHandler->findNodeByName(nodeName);
|
||||
if (thisNode == NULL) return;
|
||||
thisNode->comment = ui->NodesTable->item(row, col)->text().simplified();
|
||||
qDebug() << "New comment: " << thisNode->comment;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DBCMainEditor::onCellChangedMessage(int row,int col)
|
||||
{
|
||||
|
||||
if (inhibitCellChanged) return;
|
||||
if (row == ui->MessagesTable->rowCount() - 1)
|
||||
{
|
||||
ui->MessagesTable->insertRow(ui->MessagesTable->rowCount());
|
||||
}
|
||||
}
|
||||
|
||||
void DBCMainEditor::onCellClickedNode(int row, int col)
|
||||
{
|
||||
//reload messages list if the currently selected row has changed.
|
||||
//qDebug() << "Entered at row " << row << " col " << col;
|
||||
qDebug() << "Entered at row " << row << " col " << col;
|
||||
if (row != currRow)
|
||||
{
|
||||
currRow = row;
|
||||
QString nodeName = ui->NodesTable->item(currRow, 0)->text();
|
||||
QTableWidgetItem *item = ui->NodesTable->item(currRow, 0);
|
||||
QString nodeName;
|
||||
if (nodeName == NULL) return;
|
||||
|
||||
nodeName = item->text();
|
||||
qDebug() << "Trying to find node with name " << nodeName;
|
||||
DBC_NODE *node = dbcHandler->findNodeByName(nodeName);
|
||||
//qDebug() << "Address of node: " << (int)node;
|
||||
@@ -102,6 +174,7 @@ void DBCMainEditor::refreshNodesTable()
|
||||
ui->NodesTable->setItem(rowIdx, 1, nodeComment);
|
||||
}
|
||||
|
||||
//insert a fresh entry at the bottom that contains nothing
|
||||
ui->NodesTable->insertRow(ui->NodesTable->rowCount());
|
||||
}
|
||||
|
||||
@@ -140,5 +213,6 @@ void DBCMainEditor::refreshMessagesTable(const DBC_NODE *node)
|
||||
}
|
||||
}
|
||||
|
||||
//insert blank record that can be used to add new messages
|
||||
ui->MessagesTable->insertRow(ui->MessagesTable->rowCount());
|
||||
}
|
||||
|
||||
@@ -29,9 +29,11 @@ private:
|
||||
DBCHandler *dbcHandler;
|
||||
DBCSignalEditor *sigEditor;
|
||||
int currRow;
|
||||
bool inhibitCellChanged;
|
||||
|
||||
void refreshNodesTable();
|
||||
void refreshMessagesTable(const DBC_NODE *node);
|
||||
void showEvent(QShowEvent* event);
|
||||
};
|
||||
|
||||
#endif // DBCMAINEDITOR_H
|
||||
|
||||
Reference in New Issue
Block a user