mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 12:02:09 +08:00
Cabana: support deleting message (#26418)
delete message old-commit-hash: 59bf2fc0085420b13b7854d1a106c1706d7df265
This commit is contained in:
@@ -45,9 +45,13 @@ ChartsWidget::ChartsWidget(QWidget *parent) : QWidget(parent) {
|
||||
QObject::connect(dbc(), &DBCManager::DBCFileChanged, [this]() { removeAll(nullptr); });
|
||||
QObject::connect(dbc(), &DBCManager::signalRemoved, this, &ChartsWidget::removeAll);
|
||||
QObject::connect(dbc(), &DBCManager::signalUpdated, this, &ChartsWidget::signalUpdated);
|
||||
QObject::connect(dbc(), &DBCManager::msgUpdated, [this](const QString &msg_id) {
|
||||
QObject::connect(dbc(), &DBCManager::msgRemoved, [this](uint32_t address) {
|
||||
for (auto c : charts.toVector())
|
||||
if (DBCManager::parseId(c->id).second == address) removeChart(c);
|
||||
});
|
||||
QObject::connect(dbc(), &DBCManager::msgUpdated, [this](uint32_t address) {
|
||||
for (auto c : charts) {
|
||||
if (c->id == msg_id) c->updateTitle();
|
||||
if (DBCManager::parseId(c->id).second == address) c->updateTitle();
|
||||
}
|
||||
});
|
||||
QObject::connect(can, &CANMessages::eventsMerged, this, &ChartsWidget::eventsMerged);
|
||||
|
||||
+23
-12
@@ -10,23 +10,23 @@ DBCManager::~DBCManager() {}
|
||||
|
||||
void DBCManager::open(const QString &dbc_file_name) {
|
||||
dbc = const_cast<DBC *>(dbc_lookup(dbc_file_name.toStdString()));
|
||||
msg_map.clear();
|
||||
for (auto &msg : dbc->msgs) {
|
||||
msg_map[msg.address] = &msg;
|
||||
}
|
||||
updateMsgMap();
|
||||
emit DBCFileChanged();
|
||||
}
|
||||
|
||||
void DBCManager::open(const QString &name, const QString &content) {
|
||||
std::istringstream stream(content.toStdString());
|
||||
dbc = const_cast<DBC *>(dbc_parse_from_stream(name.toStdString(), stream));
|
||||
msg_map.clear();
|
||||
for (auto &msg : dbc->msgs) {
|
||||
msg_map[msg.address] = &msg;
|
||||
}
|
||||
updateMsgMap();
|
||||
emit DBCFileChanged();
|
||||
}
|
||||
|
||||
void DBCManager::updateMsgMap() {
|
||||
msg_map.clear();
|
||||
for (auto &msg : dbc->msgs)
|
||||
msg_map[msg.address] = &msg;
|
||||
}
|
||||
|
||||
QString DBCManager::generateDBC() {
|
||||
if (!dbc) return {};
|
||||
|
||||
@@ -49,14 +49,25 @@ QString DBCManager::generateDBC() {
|
||||
}
|
||||
|
||||
void DBCManager::updateMsg(const QString &id, const QString &name, uint32_t size) {
|
||||
if (auto m = const_cast<Msg *>(msg(id))) {
|
||||
auto [bus, address] = parseId(id);
|
||||
if (auto m = const_cast<Msg *>(msg(address))) {
|
||||
m->name = name.toStdString();
|
||||
m->size = size;
|
||||
} else {
|
||||
m = &dbc->msgs.emplace_back(Msg{.address = parseId(id).second, .name = name.toStdString(), .size = size});
|
||||
msg_map[m->address] = m;
|
||||
m = &dbc->msgs.emplace_back(Msg{.address = address, .name = name.toStdString(), .size = size});
|
||||
msg_map[address] = m;
|
||||
}
|
||||
emit msgUpdated(address);
|
||||
}
|
||||
|
||||
void DBCManager::removeMsg(const QString &id) {
|
||||
uint32_t address = parseId(id).second;
|
||||
auto it = std::find_if(dbc->msgs.begin(), dbc->msgs.end(), [address](auto &m) { return m.address == address; });
|
||||
if (it != dbc->msgs.end()) {
|
||||
dbc->msgs.erase(it);
|
||||
updateMsgMap();
|
||||
emit msgRemoved(address);
|
||||
}
|
||||
emit msgUpdated(id);
|
||||
}
|
||||
|
||||
void DBCManager::addSignal(const QString &id, const Signal &sig) {
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
inline QString name() const { return dbc ? dbc->name.c_str() : ""; }
|
||||
|
||||
void updateMsg(const QString &id, const QString &name, uint32_t size);
|
||||
void removeMsg(const QString &id);
|
||||
inline const DBC *getDBC() const { return dbc; }
|
||||
inline const Msg *msg(const QString &id) const { return msg(parseId(id).second); }
|
||||
inline const Msg *msg(uint32_t address) const {
|
||||
@@ -34,10 +35,12 @@ signals:
|
||||
void signalAdded(const Signal *sig);
|
||||
void signalRemoved(const Signal *sig);
|
||||
void signalUpdated(const Signal *sig);
|
||||
void msgUpdated(const QString &id);
|
||||
void msgUpdated(uint32_t address);
|
||||
void msgRemoved(uint32_t address);
|
||||
void DBCFileChanged();
|
||||
|
||||
private:
|
||||
void updateMsgMap();
|
||||
DBC *dbc = nullptr;
|
||||
std::unordered_map<uint32_t, const Msg *> msg_map;
|
||||
};
|
||||
|
||||
@@ -33,20 +33,21 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
||||
title_frame->setFrameShape(QFrame::StyledPanel);
|
||||
|
||||
// message title
|
||||
QHBoxLayout *title_layout = new QHBoxLayout();
|
||||
title_layout->addWidget(new QLabel("time:"));
|
||||
toolbar = new QToolBar(this);
|
||||
toolbar->addWidget(new QLabel("time:"));
|
||||
time_label = new QLabel(this);
|
||||
time_label->setStyleSheet("font-weight:bold");
|
||||
title_layout->addWidget(time_label);
|
||||
title_layout->addStretch();
|
||||
toolbar->addWidget(time_label);
|
||||
name_label = new QLabel(this);
|
||||
name_label->setStyleSheet("font-weight:bold;");
|
||||
title_layout->addWidget(name_label);
|
||||
title_layout->addStretch();
|
||||
edit_btn = new QPushButton(tr("Edit"), this);
|
||||
edit_btn->setVisible(false);
|
||||
title_layout->addWidget(edit_btn);
|
||||
frame_layout->addLayout(title_layout);
|
||||
name_label->setAlignment(Qt::AlignCenter);
|
||||
name_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
toolbar->addWidget(name_label);
|
||||
toolbar->addAction("🖍", this, &DetailWidget::editMsg)->setToolTip(tr("Edit Message"));
|
||||
remove_msg_act = toolbar->addAction("X", this, &DetailWidget::removeMsg);
|
||||
remove_msg_act->setToolTip(tr("Remove Message"));
|
||||
toolbar->setVisible(false);
|
||||
frame_layout->addWidget(toolbar);
|
||||
|
||||
// warning
|
||||
warning_widget = new QWidget(this);
|
||||
@@ -85,7 +86,6 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
||||
history_log = new HistoryLog(this);
|
||||
container_layout->addWidget(history_log);
|
||||
|
||||
QObject::connect(edit_btn, &QPushButton::clicked, this, &DetailWidget::editMsg);
|
||||
QObject::connect(binary_view, &BinaryView::resizeSignal, this, &DetailWidget::resizeSignal);
|
||||
QObject::connect(binary_view, &BinaryView::addSignal, this, &DetailWidget::addSignal);
|
||||
QObject::connect(can, &CANMessages::updated, this, &DetailWidget::updateState);
|
||||
@@ -171,7 +171,8 @@ void DetailWidget::dbcMsgChanged(int show_form_idx) {
|
||||
warnings.push_back(tr("Message size (%1) is incorrect.").arg(msg->size));
|
||||
}
|
||||
|
||||
edit_btn->setVisible(true);
|
||||
toolbar->setVisible(!msg_id.isEmpty());
|
||||
remove_msg_act->setEnabled(msg != nullptr);
|
||||
name_label->setText(msgName(msg_id));
|
||||
|
||||
binary_view->setMessage(msg_id);
|
||||
@@ -210,16 +211,27 @@ void DetailWidget::updateChartState(const QString &id, const Signal *sig, bool o
|
||||
}
|
||||
|
||||
void DetailWidget::editMsg() {
|
||||
auto msg = dbc()->msg(msg_id);
|
||||
QString name = msgName(msg_id);
|
||||
int size = msg ? msg->size : can->lastMessage(msg_id).dat.size();
|
||||
EditMessageDialog dlg(msg_id, name, size, this);
|
||||
QString id = msg_id;
|
||||
auto msg = dbc()->msg(id);
|
||||
int size = msg ? msg->size : can->lastMessage(id).dat.size();
|
||||
EditMessageDialog dlg(id, msgName(id), size, this);
|
||||
if (dlg.exec()) {
|
||||
dbc()->updateMsg(msg_id, dlg.name_edit->text(), dlg.size_spin->value());
|
||||
dbc()->updateMsg(id, dlg.name_edit->text(), dlg.size_spin->value());
|
||||
dbcMsgChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DetailWidget::removeMsg() {
|
||||
QString id = msg_id;
|
||||
if (auto msg = dbc()->msg(id)) {
|
||||
QString text = tr("Are you sure you want to remove '%1'").arg(msg->name.c_str());
|
||||
if (QMessageBox::Yes == QMessageBox::question(this, tr("Remove Message"), text)) {
|
||||
dbc()->removeMsg(id);
|
||||
dbcMsgChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DetailWidget::addSignal(int from, int to) {
|
||||
if (auto msg = dbc()->msg(msg_id)) {
|
||||
Signal sig = {};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QTabBar>
|
||||
#include <QToolBar>
|
||||
|
||||
#include "tools/cabana/binaryview.h"
|
||||
#include "tools/cabana/chartswidget.h"
|
||||
@@ -34,15 +35,17 @@ private:
|
||||
void saveSignal(const Signal *sig, const Signal &new_sig);
|
||||
void removeSignal(const Signal *sig);
|
||||
void editMsg();
|
||||
void removeMsg();
|
||||
void showForm();
|
||||
void updateState();
|
||||
|
||||
QString msg_id;
|
||||
QLabel *name_label, *time_label, *warning_label;
|
||||
QWidget *warning_widget;
|
||||
QPushButton *edit_btn;
|
||||
QWidget *signals_container;
|
||||
QTabBar *tabbar;
|
||||
QToolBar *toolbar;
|
||||
QAction *remove_msg_act;
|
||||
HistoryLog *history_log;
|
||||
BinaryView *binary_view;
|
||||
QScrollArea *scroll;
|
||||
|
||||
@@ -38,15 +38,18 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) {
|
||||
QObject::connect(can, &CANMessages::msgsReceived, model, &MessageListModel::msgsReceived);
|
||||
QObject::connect(dbc(), &DBCManager::DBCFileChanged, model, &MessageListModel::sortMessages);
|
||||
QObject::connect(dbc(), &DBCManager::msgUpdated, model, &MessageListModel::sortMessages);
|
||||
QObject::connect(dbc(), &DBCManager::msgRemoved, model, &MessageListModel::sortMessages);
|
||||
QObject::connect(table_widget->selectionModel(), &QItemSelectionModel::currentChanged, [=](const QModelIndex ¤t, const QModelIndex &previous) {
|
||||
if (current.isValid() && current.row() < model->msgs.size()) {
|
||||
current_msg_id = model->msgs[current.row()];
|
||||
emit msgSelectionChanged(current_msg_id);
|
||||
if (model->msgs[current.row()] != current_msg_id) {
|
||||
current_msg_id = model->msgs[current.row()];
|
||||
emit msgSelectionChanged(current_msg_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
QObject::connect(model, &MessageListModel::modelReset, [this]() {
|
||||
if (int row = model->msgs.indexOf(current_msg_id); row != -1)
|
||||
table_widget->selectionModel()->select(model->index(row, 0), QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect);
|
||||
table_widget->selectionModel()->setCurrentIndex(model->index(row, 0), QItemSelectionModel::Rows | QItemSelectionModel::ClearAndSelect);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user