|
|
@ -1,12 +1,13 @@ |
|
|
|
#include "tools/cabana/messageswidget.h" |
|
|
|
#include "tools/cabana/messageswidget.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <QComboBox> |
|
|
|
|
|
|
|
#include <QCompleter> |
|
|
|
#include <QCompleter> |
|
|
|
|
|
|
|
#include <QDialogButtonBox> |
|
|
|
#include <QFontDatabase> |
|
|
|
#include <QFontDatabase> |
|
|
|
#include <QHeaderView> |
|
|
|
#include <QHeaderView> |
|
|
|
#include <QLineEdit> |
|
|
|
#include <QLineEdit> |
|
|
|
#include <QPushButton> |
|
|
|
#include <QPushButton> |
|
|
|
#include <QSortFilterProxyModel> |
|
|
|
#include <QSortFilterProxyModel> |
|
|
|
|
|
|
|
#include <QTextEdit> |
|
|
|
#include <QVBoxLayout> |
|
|
|
#include <QVBoxLayout> |
|
|
|
|
|
|
|
|
|
|
|
#include "tools/cabana/dbcmanager.h" |
|
|
|
#include "tools/cabana/dbcmanager.h" |
|
|
@ -16,20 +17,23 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) { |
|
|
|
|
|
|
|
|
|
|
|
// DBC file selector
|
|
|
|
// DBC file selector
|
|
|
|
QHBoxLayout *dbc_file_layout = new QHBoxLayout(); |
|
|
|
QHBoxLayout *dbc_file_layout = new QHBoxLayout(); |
|
|
|
QComboBox *combo = new QComboBox(this); |
|
|
|
dbc_combo = new QComboBox(this); |
|
|
|
auto dbc_names = dbc()->allDBCNames(); |
|
|
|
auto dbc_names = dbc()->allDBCNames(); |
|
|
|
for (const auto &name : dbc_names) { |
|
|
|
for (const auto &name : dbc_names) { |
|
|
|
combo->addItem(QString::fromStdString(name)); |
|
|
|
dbc_combo->addItem(QString::fromStdString(name)); |
|
|
|
} |
|
|
|
} |
|
|
|
combo->model()->sort(0); |
|
|
|
dbc_combo->model()->sort(0); |
|
|
|
combo->setEditable(true); |
|
|
|
dbc_combo->setEditable(true); |
|
|
|
combo->setCurrentText(QString()); |
|
|
|
dbc_combo->setCurrentText(QString()); |
|
|
|
combo->setInsertPolicy(QComboBox::NoInsert); |
|
|
|
dbc_combo->setInsertPolicy(QComboBox::NoInsert); |
|
|
|
combo->completer()->setCompletionMode(QCompleter::PopupCompletion); |
|
|
|
dbc_combo->completer()->setCompletionMode(QCompleter::PopupCompletion); |
|
|
|
QFont font; |
|
|
|
QFont font; |
|
|
|
font.setBold(true); |
|
|
|
font.setBold(true); |
|
|
|
combo->lineEdit()->setFont(font); |
|
|
|
dbc_combo->lineEdit()->setFont(font); |
|
|
|
dbc_file_layout->addWidget(combo); |
|
|
|
dbc_file_layout->addWidget(dbc_combo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QPushButton *load_from_paste = new QPushButton(tr("Load from paste"), this); |
|
|
|
|
|
|
|
dbc_file_layout->addWidget(load_from_paste); |
|
|
|
|
|
|
|
|
|
|
|
dbc_file_layout->addStretch(); |
|
|
|
dbc_file_layout->addStretch(); |
|
|
|
QPushButton *save_btn = new QPushButton(tr("Save DBC"), this); |
|
|
|
QPushButton *save_btn = new QPushButton(tr("Save DBC"), this); |
|
|
@ -64,7 +68,8 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) { |
|
|
|
// signals/slots
|
|
|
|
// signals/slots
|
|
|
|
QObject::connect(filter, &QLineEdit::textChanged, proxy_model, &QSortFilterProxyModel::setFilterFixedString); |
|
|
|
QObject::connect(filter, &QLineEdit::textChanged, proxy_model, &QSortFilterProxyModel::setFilterFixedString); |
|
|
|
QObject::connect(can, &CANMessages::updated, model, &MessageListModel::updateState); |
|
|
|
QObject::connect(can, &CANMessages::updated, model, &MessageListModel::updateState); |
|
|
|
QObject::connect(combo, SIGNAL(activated(const QString &)), SLOT(dbcSelectionChanged(const QString &))); |
|
|
|
QObject::connect(dbc_combo, SIGNAL(activated(const QString &)), SLOT(dbcSelectionChanged(const QString &))); |
|
|
|
|
|
|
|
QObject::connect(load_from_paste, &QPushButton::clicked, this, &MessagesWidget::loadFromPaste); |
|
|
|
QObject::connect(save_btn, &QPushButton::clicked, [=]() { |
|
|
|
QObject::connect(save_btn, &QPushButton::clicked, [=]() { |
|
|
|
// TODO: save DBC to file
|
|
|
|
// TODO: save DBC to file
|
|
|
|
}); |
|
|
|
}); |
|
|
@ -75,7 +80,7 @@ MessagesWidget::MessagesWidget(QWidget *parent) : QWidget(parent) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// For test purpose
|
|
|
|
// For test purpose
|
|
|
|
combo->setCurrentText("toyota_nodsu_pt_generated"); |
|
|
|
dbc_combo->setCurrentText("toyota_nodsu_pt_generated"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MessagesWidget::dbcSelectionChanged(const QString &dbc_file) { |
|
|
|
void MessagesWidget::dbcSelectionChanged(const QString &dbc_file) { |
|
|
@ -84,6 +89,14 @@ void MessagesWidget::dbcSelectionChanged(const QString &dbc_file) { |
|
|
|
table_widget->sortByColumn(0, Qt::AscendingOrder); |
|
|
|
table_widget->sortByColumn(0, Qt::AscendingOrder); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MessagesWidget::loadFromPaste() { |
|
|
|
|
|
|
|
LoadDBCDialog dlg(this); |
|
|
|
|
|
|
|
if (dlg.exec()) { |
|
|
|
|
|
|
|
dbc()->open("from paste", dlg.dbc_edit->toPlainText()); |
|
|
|
|
|
|
|
dbc_combo->setCurrentText("loaded from paste"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MessageListModel
|
|
|
|
// MessageListModel
|
|
|
|
|
|
|
|
|
|
|
|
QVariant MessageListModel::headerData(int section, Qt::Orientation orientation, int role) const { |
|
|
|
QVariant MessageListModel::headerData(int section, Qt::Orientation orientation, int role) const { |
|
|
@ -133,3 +146,17 @@ void MessageListModel::updateState() { |
|
|
|
emit dataChanged(index(0, 0), index(row_count - 1, 3), {Qt::DisplayRole}); |
|
|
|
emit dataChanged(index(0, 0), index(row_count - 1, 3), {Qt::DisplayRole}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoadDBCDialog::LoadDBCDialog(QWidget *parent) : QDialog(parent) { |
|
|
|
|
|
|
|
QVBoxLayout *main_layout = new QVBoxLayout(this); |
|
|
|
|
|
|
|
dbc_edit = new QTextEdit(this); |
|
|
|
|
|
|
|
dbc_edit->setAcceptRichText(false); |
|
|
|
|
|
|
|
dbc_edit->setPlaceholderText(tr("paste DBC file here")); |
|
|
|
|
|
|
|
main_layout->addWidget(dbc_edit); |
|
|
|
|
|
|
|
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
|
|
|
|
|
|
|
main_layout->addWidget(buttonBox); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFixedWidth(640); |
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); |
|
|
|
|
|
|
|
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); |
|
|
|
|
|
|
|
} |
|
|
|