Added more functionality for new DBC editing system. Tweaked graphics of CANDataGrid a bit.

This commit is contained in:
Collin Kidder
2020-07-22 19:15:16 -04:00
parent 38ab58d92a
commit c89bc43795
13 changed files with 525 additions and 171 deletions
+61 -145
View File
@@ -22,10 +22,18 @@ DBCMainEditor::DBCMainEditor( const QVector<CANFrame> *frames, QWidget *parent)
connect(ui->btnSearch, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearch);
connect(ui->lineSearch, &QLineEdit::returnPressed, this, &DBCMainEditor::handleSearch);
connect(ui->btnSearchNext, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearchForward);
connect(ui->btnSearchPrev, &QAbstractButton::clicked, this, &DBCMainEditor::handleSearchBackward);
connect(ui->treeDBC, &QTreeWidget::doubleClicked, this, &DBCMainEditor::onTreeDoubleClicked);
sigEditor = new DBCSignalEditor(this);
msgEditor = new DBCMessageEditor(this);
nodeEditor = new DBCNodeEditor(this);
//all three might potentially change the data stored and force the tree to be updated
connect(sigEditor, &DBCSignalEditor::updatedTreeInfo, this, &DBCMainEditor::updatedTreeInfo);
connect(msgEditor, &DBCMessageEditor::updatedTreeInfo, this, &DBCMainEditor::updatedTreeInfo);
connect(nodeEditor, &DBCNodeEditor::updatedTreeInfo, this, &DBCMainEditor::updatedTreeInfo);
nodeIcon = QIcon(":/icons/images/node.png");
messageIcon = QIcon(":/icons/images/message.png");
@@ -60,6 +68,8 @@ DBCMainEditor::~DBCMainEditor()
removeEventFilter(this);
delete ui;
delete sigEditor;
delete msgEditor;
delete nodeEditor;
}
bool DBCMainEditor::eventFilter(QObject *obj, QEvent *event)
@@ -71,6 +81,12 @@ bool DBCMainEditor::eventFilter(QObject *obj, QEvent *event)
case Qt::Key_F1:
HelpWindow::getRef()->showHelp("dbc_editor.html");
break;
case Qt::Key_F3:
handleSearchForward();
break;
case Qt::Key_F4:
handleSearchBackward();
break;
}
return true;
} else {
@@ -160,78 +176,36 @@ void DBCMainEditor::deleteCurrentTreeItem()
void DBCMainEditor::handleSearch()
{
/*
uint32_t msgId = Utility::ParseStringToNum(ui->lineSearch->text());
if (ui->radioID->isChecked())
searchItems = ui->treeDBC->findItems(ui->lineSearch->text(),Qt::MatchContains | Qt::MatchRecursive);
qDebug() << "Search returned " << searchItems.count() << "items.";
if (searchItems.count() > 0)
{
DBC_MESSAGE *msg = dbcFile->messageHandler->findMsgByID(msgId);
if (msg)
{
DBC_NODE *node = msg->sender;
if (node)
{
QString nodeName = node->name;
for (int i = 0; i < ui->NodesTable->rowCount(); i++)
{
QTableWidgetItem *item = ui->NodesTable->item(i, 0);
if (item->text() == nodeName)
{
item->setSelected(true);
ui->NodesTable->scrollToItem(item);
onCellClickedNode(i, 0);
for (int j = 0; j < ui->MessagesTable->rowCount(); j++)
{
QTableWidgetItem *msgItem = ui->MessagesTable->item(j, 0);
if (!msgItem) break;
if (Utility::ParseStringToNum(msgItem->text()) == msgId)
{
msgItem->setSelected(true);
ui->MessagesTable->scrollToItem(msgItem);
onCellClickedMessage(j, 0);
break;
}
}
break;
}
}
}
}
ui->treeDBC->setCurrentItem(searchItems[0]);
searchItemPos = 0;
ui->lblSearchPos->setText("Search Results: " + QString::number(searchItemPos + 1) + " of " + QString::number(searchItems.count()));
}
if (ui->radioName->isChecked())
else
{
DBC_MESSAGE *msg = dbcFile->messageHandler->findMsgByPartialName(ui->lineSearch->text());
if (msg)
{
DBC_NODE *node = msg->sender;
if (node)
{
QString nodeName = node->name;
for (int i = 0; i < ui->NodesTable->rowCount(); i++)
{
QTableWidgetItem *item = ui->NodesTable->item(i, 0);
if (item->text() == nodeName)
{
item->setSelected(true);
ui->NodesTable->scrollToItem(item);
onCellClickedNode(i, 0);
for (int j = 0; j < ui->MessagesTable->rowCount(); j++)
{
QTableWidgetItem *msgItem = ui->MessagesTable->item(j, 1);
if (!msgItem) break;
if (msgItem->text().contains(ui->lineSearch->text(), Qt::CaseInsensitive))
{
msgItem->setSelected(true);
ui->MessagesTable->scrollToItem(msgItem);
onCellClickedMessage(j, 0);
break;
}
}
break;
}
}
}
}
} */
ui->lblSearchPos->setText("Search Results: 0 of 0");
}
}
void DBCMainEditor::handleSearchForward()
{
if (searchItems.count() == 0) return;
if (searchItemPos < searchItems.count() - 1) searchItemPos++;
else searchItemPos = 0;
ui->treeDBC->setCurrentItem(searchItems[searchItemPos]);
ui->lblSearchPos->setText("Search Results: " + QString::number(searchItemPos + 1) + " of " + QString::number(searchItems.count()));
}
void DBCMainEditor::handleSearchBackward()
{
if (searchItems.count() == 0) return;
if (searchItemPos > 0) searchItemPos--;
else searchItemPos = searchItems.count() - 1;
ui->treeDBC->setCurrentItem(searchItems[searchItemPos]);
ui->lblSearchPos->setText("Search Results: " + QString::number(searchItemPos + 1) + " of " + QString::number(searchItems.count()));
}
//Double clicking is interpreted as a desire to edit the given item.
@@ -243,6 +217,7 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
bool ret = false;
DBC_MESSAGE *msg;
DBC_SIGNAL *sig;
DBC_NODE *node;
uint32_t msgID;
QString idString;
@@ -251,6 +226,12 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
switch (firstCol->data(0, Qt::UserRole).toInt())
{
case 1: //a node
idString = firstCol->text(0).split(" ")[0];
node = dbcFile->findNodeByName(idString);
nodeEditor->setFileIdx(fileIdx);
nodeEditor->setNodeRef(node);
nodeEditor->refreshView();
nodeEditor->show();
break;
case 2: //a message
idString = firstCol->text(0).split(" ")[0];
@@ -258,8 +239,9 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
msg = dbcFile->messageHandler->findMsgByID(msgID);
msgEditor->setMessageRef(msg);
msgEditor->setFileIdx(fileIdx);
msgEditor->setWindowModality(Qt::WindowModal);
msgEditor->exec(); //blocks this window from being active until we're done
//msgEditor->setWindowModality(Qt::WindowModal);
msgEditor->refreshView();
msgEditor->show(); //show allows the rest of the forms to keep going
break;
case 3: //a signal
idString = firstCol->parent()->text(0).split(" ")[0];
@@ -269,82 +251,11 @@ void DBCMainEditor::onTreeDoubleClicked(const QModelIndex &index)
sigEditor->setSignalRef(sig);
sigEditor->setMessageRef(msg);
sigEditor->setFileIdx(fileIdx);
sigEditor->setWindowModality(Qt::WindowModal);
sigEditor->exec(); //blocks this window from being active until we're done
//sigEditor->setWindowModality(Qt::WindowModal);
sigEditor->refreshView();
sigEditor->show();
break;
}
/* if (col == 3) //3 is the signals field. If clicked we go to the signals dialog
{
QTableWidgetItem* msg = ui->MessagesTable->item(row, 0);
if(msg) {
QString idString = msg->text();
DBC_MESSAGE *message = dbcFile->messageHandler->findMsgByID(static_cast<uint32_t>(Utility::ParseStringToNum(idString)));
sigEditor->setMessageRef(message);
sigEditor->setFileIdx(fileIdx);
sigEditor->setWindowModality(Qt::WindowModal);
sigEditor->exec(); //blocks this window from being active until we're done
//now update the displayed # of signals
inhibitCellChanged = true;
QTableWidgetItem *replacement = new QTableWidgetItem(QString::number(message->sigHandler->getCount()));
ui->MessagesTable->setItem(row, col, replacement);
inhibitCellChanged = false;
}
}
if (col == 4)
{
QColor newColor = QColorDialog::getColor(thisItem->background().color());
thisItem->setBackground(newColor);
if(!firstCol) return;
msgID = Utility::ParseStringToNum2(firstCol->text(), &ret);
msg = dbcFile->messageHandler->findMsgByID(msgID);
if (msg)
{
msg->fgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = msg->findAttrValByName("GenMsgForegroundColor");
if (val)
{
val->value = newColor.name();
}
else
{
DBC_ATTRIBUTE_VALUE newVal;
newVal.attrName = "GenMsgForegroundColor";
newVal.value = newColor.name();
msg->attributes.append(newVal);
}
}
}
if (col == 5)
{
QColor newColor = QColorDialog::getColor(thisItem->background().color());
thisItem->setBackground(newColor);
if(!firstCol) return;
msgID = Utility::ParseStringToNum2(firstCol->text(), &ret);
msg = dbcFile->messageHandler->findMsgByID(msgID);
if (msg)
{
msg->bgColor = newColor;
DBC_ATTRIBUTE_VALUE *val = msg->findAttrValByName("GenMsgBackgroundColor");
if (val)
{
val->value = newColor.name();
}
else
{
DBC_ATTRIBUTE_VALUE newVal;
newVal.attrName = "GenMsgBackgroundColor";
newVal.value = newColor.name();
msg->attributes.append(newVal);
}
}
} */
}
@@ -401,3 +312,8 @@ void DBCMainEditor::refreshTree()
}
ui->treeDBC->sortItems(0, Qt::SortOrder::AscendingOrder); //sort the display list for ease in viewing by mere mortals, helps me a lot.
}
void DBCMainEditor::updatedTreeInfo(QString oldData, QString newData, int type)
{
}
+11 -2
View File
@@ -4,9 +4,11 @@
#include <QDialog>
#include <QDebug>
#include <QIcon>
#include <QTreeWidget>
#include "dbchandler.h"
#include "dbcsignaleditor.h"
#include "dbcmessageeditor.h"
#include "dbcnodeeditor.h"
#include "utility.h"
namespace Ui {
@@ -22,11 +24,16 @@ public:
~DBCMainEditor();
void setFileIdx(int idx);
public slots:
void updatedTreeInfo(QString oldData, QString newData, int type);
private slots:
void onTreeDoubleClicked(const QModelIndex &index);
void onCustomMenuTree(QPoint);
void deleteCurrentTreeItem();
void handleSearch();
void handleSearchForward();
void handleSearchBackward();
private:
Ui::DBCMainEditor *ui;
@@ -34,6 +41,7 @@ private:
const QVector<CANFrame> *referenceFrames;
DBCSignalEditor *sigEditor;
DBCMessageEditor *msgEditor;
DBCNodeEditor *nodeEditor;
DBCFile *dbcFile;
int fileIdx;
QIcon nodeIcon;
@@ -41,14 +49,15 @@ private:
QIcon signalIcon;
QIcon multiplexorSignalIcon;
QIcon multiplexedSignalIcon;
QList<QTreeWidgetItem *> searchItems;
int searchItemPos;
void refreshTree();
void showEvent(QShowEvent* event);
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
void readSettings();
void writeSettings();
void refreshTree();
};
#endif // DBCMAINEDITOR_H
+4 -1
View File
@@ -19,6 +19,10 @@ public:
void showEvent(QShowEvent*);
void setMessageRef(DBC_MESSAGE *msg);
void setFileIdx(int idx);
void refreshView();
signals:
void updatedTreeInfo(QString oldData, QString newData, int type);
private:
Ui::DBCMessageEditor *ui;
@@ -31,7 +35,6 @@ private:
bool eventFilter(QObject *obj, QEvent *event);
void readSettings();
void writeSettings();
void refreshView();
void generateSampleText();
};
+130
View File
@@ -0,0 +1,130 @@
#include "dbcnodeeditor.h"
#include "ui_dbcnodeeditor.h"
#include <QSettings>
#include <QKeyEvent>
#include <QColorDialog>
#include "helpwindow.h"
#include "utility.h"
DBCNodeEditor::DBCNodeEditor(QWidget *parent) :
QDialog(parent),
ui(new Ui::DBCNodeEditor)
{
ui->setupUi(this);
readSettings();
dbcHandler = DBCHandler::getReference();
dbcNode = nullptr;
installEventFilter(this);
}
DBCNodeEditor::~DBCNodeEditor()
{
removeEventFilter(this);
delete ui;
}
void DBCNodeEditor::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
writeSettings();
}
bool DBCNodeEditor::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyRelease) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key())
{
case Qt::Key_F1:
HelpWindow::getRef()->showHelp("nodeeditor.html");
break;
}
return true;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
return false;
}
void DBCNodeEditor::setFileIdx(int idx)
{
if (idx < 0 || idx > dbcHandler->getFileCount() - 1) return;
dbcFile = dbcHandler->getFileByIdx(idx);
}
void DBCNodeEditor::readSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
resize(settings.value("DBCNodeEditor/WindowSize", QSize(312, 128)).toSize());
move(settings.value("DBCNodeEditor/WindowPos", QPoint(100, 100)).toPoint());
}
}
void DBCNodeEditor::writeSettings()
{
QSettings settings;
if (settings.value("Main/SaveRestorePositions", false).toBool())
{
settings.setValue("DBCNodeEditor/WindowSize", size());
settings.setValue("DBCNodeEditor/WindowPos", pos());
}
}
void DBCNodeEditor::setNodeRef(DBC_NODE *node)
{
dbcNode = node;
}
void DBCNodeEditor::showEvent(QShowEvent* event)
{
QDialog::showEvent(event);
refreshView();
}
void DBCNodeEditor::refreshView()
{
ui->lineComment->setText(dbcNode->comment);
ui->lineMsgName->setText(dbcNode->name);
//generateSampleText();
}
void DBCNodeEditor::generateSampleText()
{
/*
QBrush fg, bg;
if (dbcMessage->fgColor.isValid()) fg = QBrush(dbcMessage->fgColor);
else fg = QBrush(QColor(dbcFile->findAttributeByName("GenMsgForegroundColor")->defaultValue.toString()));
if (dbcMessage->bgColor.isValid()) bg = QBrush(dbcMessage->bgColor);
else bg = QBrush(QColor(dbcFile->findAttributeByName("GenMsgBackgroundColor")->defaultValue.toString()));
ui->listSample->clear();
QListWidgetItem *item = new QListWidgetItem("Test String");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("0x20F TestMsg");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("20 FF 10 A1 BB CC 4D");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
item = new QListWidgetItem("1024.3434");
item->setForeground(fg);
item->setBackground(bg);
ui->listSample->addItem(item);
*/
}
+41
View File
@@ -0,0 +1,41 @@
#ifndef DBCNODEEDITOR_H
#define DBCNODEEDITOR_H
#include <QDialog>
#include "dbc_classes.h"
#include "dbchandler.h"
namespace Ui {
class DBCNodeEditor;
}
class DBCNodeEditor : public QDialog
{
Q_OBJECT
public:
explicit DBCNodeEditor(QWidget *parent = nullptr);
~DBCNodeEditor();
void showEvent(QShowEvent*);
void setNodeRef(DBC_NODE *node);
void setFileIdx(int idx);
void refreshView();
signals:
void updatedTreeInfo(QString oldData, QString newData, int type);
private:
Ui::DBCNodeEditor *ui;
DBCHandler *dbcHandler;
DBC_NODE *dbcNode;
DBCFile *dbcFile;
void closeEvent(QCloseEvent *event);
bool eventFilter(QObject *obj, QEvent *event);
void readSettings();
void writeSettings();
void generateSampleText();
};
#endif // DBCNODEEDITOR_H
+11 -2
View File
@@ -125,6 +125,7 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
{
if (currentSignal == nullptr) return;
currentSignal->comment = ui->txtComment->text().simplified().replace(' ', '_');
//updatedTreeInfo();
});
connect(ui->txtUnitName, &QLineEdit::editingFinished,
@@ -151,8 +152,8 @@ DBCSignalEditor::DBCSignalEditor(QWidget *parent) :
if (currentSignal == nullptr) return;
QString tempNameStr = ui->txtName->text().simplified().replace(' ', '_');
if (tempNameStr.length() > 0) currentSignal->name = tempNameStr;
//need to update the list too.
//ui->signalsList->currentItem()->setText(currentSignal->name);
//need to update the tree too.
//updatedTreeInfo();
});
connect(ui->txtMultiplexValue, &QLineEdit::editingFinished,
@@ -286,6 +287,12 @@ void DBCSignalEditor::showEvent(QShowEvent* event)
fillValueTable(currentSignal);
}
void DBCSignalEditor::refreshView()
{
fillSignalForm(currentSignal);
fillValueTable(currentSignal);
}
void DBCSignalEditor::onValuesCellChanged(int row,int col)
{
if (inhibitCellChanged) return;
@@ -519,6 +526,7 @@ void DBCSignalEditor::generateUsedBits()
{
int byt = y / 8;
usedBits[byt] |= 1 << (y % 8);
ui->bitfield->setUsedSignalNum(y, x);
}
}
else //big endian / motorola format
@@ -529,6 +537,7 @@ void DBCSignalEditor::generateUsedBits()
{
int byt = startBit / 8;
usedBits[byt] |= 1 << (startBit % 8);
ui->bitfield->setUsedSignalNum(startBit, x);
size--;
if ((startBit % 8) == 0) startBit += 15;
else startBit--;
+4
View File
@@ -20,6 +20,10 @@ public:
void setSignalRef(DBC_SIGNAL *sig);
void showEvent(QShowEvent*);
~DBCSignalEditor();
void refreshView();
signals:
void updatedTreeInfo(QString oldData, QString newData, int type);
private slots:
void bitfieldClicked(int x, int y);