cabana: use QFormLayout (#25982)

pull/25983/head
Dean Lee 3 years ago committed by GitHub
parent 4cd3753d98
commit 7156633034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      tools/cabana/detailwidget.cc
  2. 81
      tools/cabana/signaledit.cc

@ -3,6 +3,7 @@
#include <QDebug> #include <QDebug>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFormLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QTimer> #include <QTimer>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -224,24 +225,20 @@ void HistoryLog::clear() {
EditMessageDialog::EditMessageDialog(const QString &id, QWidget *parent) : id(id), QDialog(parent) { EditMessageDialog::EditMessageDialog(const QString &id, QWidget *parent) : id(id), QDialog(parent) {
setWindowTitle(tr("Edit message")); setWindowTitle(tr("Edit message"));
QVBoxLayout *main_layout = new QVBoxLayout(this); QVBoxLayout *main_layout = new QVBoxLayout(this);
main_layout->addWidget(new QLabel(tr("ID: (%1)").arg(id)));
QFormLayout *form_layout = new QFormLayout();
form_layout->addRow("ID", new QLabel(id));
auto msg = const_cast<Msg *>(parser->getMsg(id)); auto msg = const_cast<Msg *>(parser->getMsg(id));
QHBoxLayout *h_layout = new QHBoxLayout();
h_layout->addWidget(new QLabel(tr("Name")));
h_layout->addStretch();
name_edit = new QLineEdit(this); name_edit = new QLineEdit(this);
name_edit->setText(msg ? msg->name.c_str() : "untitled"); name_edit->setText(msg ? msg->name.c_str() : "untitled");
h_layout->addWidget(name_edit); form_layout->addRow(tr("Name"), name_edit);
main_layout->addLayout(h_layout);
h_layout = new QHBoxLayout();
h_layout->addWidget(new QLabel(tr("Size")));
h_layout->addStretch();
size_spin = new QSpinBox(this); size_spin = new QSpinBox(this);
size_spin->setValue(msg ? msg->size : parser->can_msgs[id].dat.size()); size_spin->setValue(msg ? msg->size : parser->can_msgs[id].dat.size());
h_layout->addWidget(size_spin); form_layout->addRow(tr("Size"), size_spin);
main_layout->addLayout(h_layout);
main_layout->addLayout(form_layout);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
main_layout->addWidget(buttonBox); main_layout->addWidget(buttonBox);

@ -1,6 +1,7 @@
#include "tools/cabana/signaledit.h" #include "tools/cabana/signaledit.h"
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QFormLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QMessageBox> #include <QMessageBox>
@ -9,88 +10,48 @@
// SignalForm // SignalForm
SignalForm::SignalForm(const Signal &sig, QWidget *parent) : QWidget(parent) { SignalForm::SignalForm(const Signal &sig, QWidget *parent) : QWidget(parent) {
QVBoxLayout *v_layout = new QVBoxLayout(this); QFormLayout *form_layout = new QFormLayout(this);
QHBoxLayout *h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Name")));
name = new QLineEdit(sig.name.c_str()); name = new QLineEdit(sig.name.c_str());
h->addWidget(name); form_layout->addRow(tr("Name"), name);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Size")));
size = new QSpinBox(); size = new QSpinBox();
size->setValue(sig.size); size->setValue(sig.size);
h->addWidget(size); form_layout->addRow(tr("Size"), size);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Most significant bit")));
msb = new QSpinBox(); msb = new QSpinBox();
msb->setValue(sig.msb); msb->setValue(sig.msb);
h->addWidget(msb); form_layout->addRow(tr("Most significant bit"), msb);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Endianness")));
endianness = new QComboBox(); endianness = new QComboBox();
endianness->addItems({"Little", "Big"}); endianness->addItems({"Little", "Big"});
endianness->setCurrentIndex(sig.is_little_endian ? 0 : 1); endianness->setCurrentIndex(sig.is_little_endian ? 0 : 1);
h->addWidget(endianness); form_layout->addRow(tr("Endianness"), endianness);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("sign")));
sign = new QComboBox(); sign = new QComboBox();
sign->addItems({"Signed", "Unsigned"}); sign->addItems({"Signed", "Unsigned"});
sign->setCurrentIndex(sig.is_signed ? 0 : 1); sign->setCurrentIndex(sig.is_signed ? 0 : 1);
h->addWidget(sign); form_layout->addRow(tr("sign"), sign);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Factor")));
factor = new QSpinBox(); factor = new QSpinBox();
factor->setValue(sig.factor); factor->setValue(sig.factor);
h->addWidget(factor); form_layout->addRow(tr("Factor"), factor);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Offset")));
offset = new QSpinBox(); offset = new QSpinBox();
offset->setValue(sig.offset); offset->setValue(sig.offset);
h->addWidget(offset); form_layout->addRow(tr("Offset"), offset);
v_layout->addLayout(h);
// TODO: parse the following parameters in opendbc // TODO: parse the following parameters in opendbc
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Unit")));
unit = new QLineEdit(); unit = new QLineEdit();
h->addWidget(unit); form_layout->addRow(tr("Unit"), unit);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Comment")));
comment = new QLineEdit(); comment = new QLineEdit();
h->addWidget(comment); form_layout->addRow(tr("Comment"), comment);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Minimum value")));
min_val = new QSpinBox(); min_val = new QSpinBox();
h->addWidget(min_val); form_layout->addRow(tr("Minimum value"), min_val);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Maximum value")));
max_val = new QSpinBox(); max_val = new QSpinBox();
h->addWidget(max_val); form_layout->addRow(tr("Maximum value"), max_val);
v_layout->addLayout(h);
h = new QHBoxLayout();
h->addWidget(new QLabel(tr("Value descriptions")));
val_desc = new QLineEdit(); val_desc = new QLineEdit();
h->addWidget(val_desc); form_layout->addRow(tr("Value descriptions"), val_desc);
v_layout->addLayout(h);
} }
std::optional<Signal> SignalForm::getSignal() { std::optional<Signal> SignalForm::getSignal() {
@ -126,12 +87,9 @@ SignalEdit::SignalEdit(const QString &id, const Signal &sig, const QString &colo
title = new ElidedLabel(this); title = new ElidedLabel(this);
title->setText(sig.name.c_str()); title->setText(sig.name.c_str());
title->setStyleSheet(QString("font-weight:bold; color:%1").arg(color)); title->setStyleSheet(QString("font-weight:bold; color:%1").arg(color));
connect(title, &ElidedLabel::clicked, [=]() {
edit_container->isVisible() ? edit_container->hide() : edit_container->show();
icon->setText(edit_container->isVisible() ? "" : ">");
});
title_layout->addWidget(title); title_layout->addWidget(title);
title_layout->addStretch(); title_layout->addStretch();
plot_btn = new QPushButton("📈"); plot_btn = new QPushButton("📈");
plot_btn->setStyleSheet("font-size:16px"); plot_btn->setStyleSheet("font-size:16px");
plot_btn->setToolTip(tr("Show Plot")); plot_btn->setToolTip(tr("Show Plot"));
@ -148,16 +106,21 @@ SignalEdit::SignalEdit(const QString &id, const Signal &sig, const QString &colo
QHBoxLayout *h = new QHBoxLayout(); QHBoxLayout *h = new QHBoxLayout();
remove_btn = new QPushButton(tr("Remove Signal")); remove_btn = new QPushButton(tr("Remove Signal"));
QObject::connect(remove_btn, &QPushButton::clicked, this, &SignalEdit::remove);
h->addWidget(remove_btn); h->addWidget(remove_btn);
h->addStretch(); h->addStretch();
QPushButton *save_btn = new QPushButton(tr("Save")); QPushButton *save_btn = new QPushButton(tr("Save"));
QObject::connect(save_btn, &QPushButton::clicked, this, &SignalEdit::save);
h->addWidget(save_btn); h->addWidget(save_btn);
v_layout->addLayout(h); v_layout->addLayout(h);
edit_container->setVisible(false); edit_container->setVisible(false);
main_layout->addWidget(edit_container); main_layout->addWidget(edit_container);
QObject::connect(remove_btn, &QPushButton::clicked, this, &SignalEdit::remove);
QObject::connect(save_btn, &QPushButton::clicked, this, &SignalEdit::save);
QObject::connect(title, &ElidedLabel::clicked, [=]() {
edit_container->isVisible() ? edit_container->hide() : edit_container->show();
icon->setText(edit_container->isVisible() ? "" : ">");
});
} }
void SignalEdit::save() { void SignalEdit::save() {

Loading…
Cancel
Save