mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
Cabana: improve DBC file selector (#26787)
old-commit-hash: 68272449e1775df2326f7f62d1f4868c701dff29
This commit is contained in:
@@ -32,8 +32,6 @@ void DBCManager::initMsgMap() {
|
||||
}
|
||||
|
||||
QString DBCManager::generateDBC() {
|
||||
if (!dbc) return {};
|
||||
|
||||
QString dbc_string;
|
||||
for (auto &[address, m] : msgs) {
|
||||
dbc_string += QString("BO_ %1 %2: %3 XXX\n").arg(address).arg(m.name).arg(m.size);
|
||||
|
||||
+34
-19
@@ -18,8 +18,6 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidgetAction>
|
||||
|
||||
#include "tools/replay/util.h"
|
||||
|
||||
static MainWindow *main_win = nullptr;
|
||||
void qLogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
|
||||
if (type == QtDebugMsg) std::cout << msg.toStdString() << std::endl;
|
||||
@@ -36,19 +34,13 @@ MainWindow::MainWindow() : QMainWindow() {
|
||||
splitter = new QSplitter(Qt::Horizontal, this);
|
||||
splitter->setHandleWidth(11);
|
||||
|
||||
// DBC file selector
|
||||
QWidget *messages_container = new QWidget(this);
|
||||
QVBoxLayout *messages_layout = new QVBoxLayout(messages_container);
|
||||
messages_layout->setContentsMargins(0, 0, 0, 0);
|
||||
dbc_combo = new QComboBox(this);
|
||||
auto dbc_names = dbc()->allDBCNames();
|
||||
for (const auto &name : dbc_names) {
|
||||
dbc_combo->addItem(QString::fromStdString(name));
|
||||
}
|
||||
dbc_combo->model()->sort(0);
|
||||
dbc_combo->setInsertPolicy(QComboBox::NoInsert);
|
||||
messages_layout->addWidget(dbc_combo);
|
||||
|
||||
// left panel
|
||||
dbc_combo = createDBCSelector();
|
||||
messages_layout->addWidget(dbc_combo);
|
||||
messages_widget = new MessagesWidget(this);
|
||||
messages_layout->addWidget(messages_widget);
|
||||
splitter->addWidget(messages_container);
|
||||
@@ -109,11 +101,7 @@ MainWindow::MainWindow() : QMainWindow() {
|
||||
QObject::connect(charts_widget, &ChartsWidget::dock, this, &MainWindow::dockCharts);
|
||||
QObject::connect(charts_widget, &ChartsWidget::rangeChanged, video_widget, &VideoWidget::rangeChanged);
|
||||
QObject::connect(can, &CANMessages::streamStarted, this, &MainWindow::loadDBCFromFingerprint);
|
||||
QObject::connect(dbc(), &DBCManager::DBCFileChanged, [this]() {
|
||||
detail_widget->undo_stack->clear();
|
||||
dbc_combo->setCurrentText(QFileInfo(dbc()->name()).baseName());
|
||||
setWindowTitle(tr("%1 - Cabana").arg(dbc()->name()));
|
||||
});
|
||||
QObject::connect(dbc(), &DBCManager::DBCFileChanged, this, &MainWindow::DBCFileChanged);
|
||||
QObject::connect(detail_widget->undo_stack, &QUndoStack::indexChanged, [this](int index) {
|
||||
setWindowTitle(tr("%1%2 - Cabana").arg(index > 0 ? "* " : "").arg(dbc()->name()));
|
||||
});
|
||||
@@ -149,6 +137,23 @@ void MainWindow::createActions() {
|
||||
help_menu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
|
||||
}
|
||||
|
||||
QComboBox *MainWindow::createDBCSelector() {
|
||||
QComboBox *c = new QComboBox(this);
|
||||
c->setEditable(true);
|
||||
c->lineEdit()->setPlaceholderText(tr("Select from an existing DBC file"));
|
||||
c->setInsertPolicy(QComboBox::NoInsert);
|
||||
c->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
||||
c->completer()->setFilterMode(Qt::MatchContains);
|
||||
|
||||
auto dbc_names = dbc()->allDBCNames();
|
||||
std::sort(dbc_names.begin(), dbc_names.end());
|
||||
for (const auto &name : dbc_names) {
|
||||
c->addItem(QString::fromStdString(name));
|
||||
}
|
||||
c->setCurrentIndex(-1);
|
||||
return c;
|
||||
}
|
||||
|
||||
void MainWindow::createStatusBar() {
|
||||
progress_bar = new QProgressBar();
|
||||
progress_bar->setRange(0, 100);
|
||||
@@ -164,9 +169,17 @@ void MainWindow::createShortcuts() {
|
||||
// TODO: add more shortcuts here.
|
||||
}
|
||||
|
||||
void MainWindow::DBCFileChanged() {
|
||||
detail_widget->undo_stack->clear();
|
||||
int index = dbc_combo->findText(QFileInfo(dbc()->name()).baseName());
|
||||
dbc_combo->setCurrentIndex(index);
|
||||
setWindowTitle(tr("%1 - Cabana").arg(dbc()->name()));
|
||||
}
|
||||
|
||||
void MainWindow::loadDBCFromName(const QString &name) {
|
||||
if (name != dbc()->name())
|
||||
if (name != dbc()->name()) {
|
||||
dbc()->open(name);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadDBCFromFile() {
|
||||
@@ -189,13 +202,15 @@ void MainWindow::loadDBCFromClipboard() {
|
||||
|
||||
void MainWindow::loadDBCFromFingerprint() {
|
||||
auto fingerprint = can->carFingerprint();
|
||||
fingerprint_label->setText(fingerprint);
|
||||
if (!fingerprint.isEmpty() && dbc()->name().isEmpty()) {
|
||||
fingerprint_label->setText(fingerprint.isEmpty() ? tr("Unknown Car") : fingerprint);
|
||||
if (!fingerprint.isEmpty()) {
|
||||
auto dbc_name = fingerprint_to_dbc[fingerprint];
|
||||
if (dbc_name != QJsonValue::Undefined) {
|
||||
loadDBCFromName(dbc_name.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
dbc()->open("New_DBC", "");
|
||||
}
|
||||
|
||||
void MainWindow::saveDBCToFile() {
|
||||
|
||||
@@ -34,9 +34,11 @@ signals:
|
||||
|
||||
protected:
|
||||
void createActions();
|
||||
QComboBox *createDBCSelector();
|
||||
void createStatusBar();
|
||||
void createShortcuts();
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void DBCFileChanged();
|
||||
void updateDownloadProgress(uint64_t cur, uint64_t total, bool success);
|
||||
void setOption();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user