mirror of https://github.com/commaai/openpilot.git
Cabana: sort signal by start bit and keep cursor position after save (#26529)
sort signals by start bit and keep cursor position after save
old-commit-hash: e3c913bfa1
This commit is contained in:
parent
9fc4aa38b3
commit
78a2c19d0b
|
@ -166,19 +166,19 @@ void BinaryViewModel::setMessage(const QString &message_id) {
|
|||
row_count = dbc_msg->size;
|
||||
items.resize(row_count * column_count);
|
||||
int i = 0;
|
||||
for (auto &[name, sig] : dbc_msg->sigs) {
|
||||
auto [start, end] = getSignalRange(&sig);
|
||||
for (auto sig : dbc_msg->getSignals()) {
|
||||
auto [start, end] = getSignalRange(sig);
|
||||
for (int j = start; j <= end; ++j) {
|
||||
int bit_index = sig.is_little_endian ? bigEndianBitIndex(j) : j;
|
||||
int bit_index = sig->is_little_endian ? bigEndianBitIndex(j) : j;
|
||||
int idx = column_count * (bit_index / 8) + bit_index % 8;
|
||||
if (idx >= items.size()) {
|
||||
qWarning() << "signal " << name << "out of bounds.start_bit:" << sig.start_bit << "size:" << sig.size;
|
||||
qWarning() << "signal " << sig->name.c_str() << "out of bounds.start_bit:" << sig->start_bit << "size:" << sig->size;
|
||||
break;
|
||||
}
|
||||
if (j == start) sig.is_little_endian ? items[idx].is_lsb = true : items[idx].is_msb = true;
|
||||
if (j == end) sig.is_little_endian ? items[idx].is_msb = true : items[idx].is_lsb = true;
|
||||
if (j == start) sig->is_little_endian ? items[idx].is_lsb = true : items[idx].is_msb = true;
|
||||
if (j == end) sig->is_little_endian ? items[idx].is_msb = true : items[idx].is_lsb = true;
|
||||
items[idx].bg_color = getColor(i);
|
||||
items[idx].sigs.push_back(&sig);
|
||||
items[idx].sigs.push_back(sig);
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,15 @@ DBCManager *dbc() {
|
|||
return &dbc_manager;
|
||||
}
|
||||
|
||||
// DBCMsg
|
||||
|
||||
std::vector<const Signal*> DBCMsg::getSignals() const {
|
||||
std::vector<const Signal*> ret;
|
||||
for (auto &[name, sig] : sigs) ret.push_back(&sig);
|
||||
std::sort(ret.begin(), ret.end(), [](auto l, auto r) { return l->start_bit < r->start_bit; });
|
||||
return ret;
|
||||
}
|
||||
|
||||
// helper functions
|
||||
|
||||
static QVector<int> BIG_ENDIAN_START_BITS = []() {
|
||||
|
|
|
@ -9,6 +9,7 @@ struct DBCMsg {
|
|||
QString name;
|
||||
uint32_t size;
|
||||
std::map<QString, Signal> sigs;
|
||||
std::vector<const Signal*> getSignals() const;
|
||||
};
|
||||
|
||||
class DBCManager : public QObject {
|
||||
|
|
|
@ -149,7 +149,7 @@ void DetailWidget::dbcMsgChanged(int show_form_idx) {
|
|||
QStringList warnings;
|
||||
const DBCMsg *msg = dbc()->msg(msg_id);
|
||||
if (msg) {
|
||||
for (auto &[name, sig] : msg->sigs) {
|
||||
for (auto sig : msg->getSignals()) {
|
||||
SignalEdit *form = i < signal_list.size() ? signal_list[i] : nullptr;
|
||||
if (!form) {
|
||||
form = new SignalEdit(i);
|
||||
|
@ -162,8 +162,8 @@ void DetailWidget::dbcMsgChanged(int show_form_idx) {
|
|||
signals_layout->addWidget(form);
|
||||
signal_list.push_back(form);
|
||||
}
|
||||
form->setSignal(msg_id, &sig);
|
||||
form->setChartOpened(charts->isChartOpened(msg_id, &sig));
|
||||
form->setSignal(msg_id, sig);
|
||||
form->setChartOpened(charts->isChartOpened(msg_id, sig));
|
||||
++i;
|
||||
}
|
||||
if (msg->size != can->lastMessage(msg_id).dat.size())
|
||||
|
|
|
@ -116,11 +116,16 @@ SignalEdit::SignalEdit(int index, QWidget *parent) : form_idx(index), QWidget(pa
|
|||
hline->setFrameShadow(QFrame::Sunken);
|
||||
main_layout->addWidget(hline);
|
||||
|
||||
save_timer = new QTimer(this);
|
||||
save_timer->setInterval(300);
|
||||
save_timer->setSingleShot(true);
|
||||
save_timer->callOnTimeout(this, &SignalEdit::saveSignal);
|
||||
|
||||
QObject::connect(title, &ElidedLabel::clicked, this, &SignalEdit::showFormClicked);
|
||||
QObject::connect(plot_btn, &QToolButton::clicked, [this](bool checked) { emit showChart(msg_id, sig, checked); });
|
||||
QObject::connect(seek_btn, &QToolButton::clicked, [this]() { SignalFindDlg(msg_id, sig, this).exec(); });
|
||||
QObject::connect(remove_btn, &QToolButton::clicked, [this]() { emit remove(sig); });
|
||||
QObject::connect(form, &SignalForm::changed, this, &SignalEdit::saveSignal);
|
||||
QObject::connect(form, &SignalForm::changed, [this]() { save_timer->start(); });
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
}
|
||||
|
||||
|
@ -174,7 +179,9 @@ void SignalEdit::setChartOpened(bool opened) {
|
|||
void SignalEdit::updateForm(bool visible) {
|
||||
if (visible && sig) {
|
||||
form->changed_by_user = false;
|
||||
form->name->setText(sig->name.c_str());
|
||||
if (form->name->text() != sig->name.c_str()) {
|
||||
form->name->setText(sig->name.c_str());
|
||||
}
|
||||
form->endianness->setCurrentIndex(sig->is_little_endian ? 0 : 1);
|
||||
form->sign->setCurrentIndex(sig->is_signed ? 0 : 1);
|
||||
form->factor->setText(QString::number(sig->factor));
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QSpinBox>
|
||||
#include <QTimer>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "selfdrive/ui/qt/widgets/controls.h"
|
||||
|
@ -57,6 +58,7 @@ protected:
|
|||
QLabel *icon;
|
||||
int form_idx = 0;
|
||||
QToolButton *plot_btn;
|
||||
QTimer *save_timer;
|
||||
};
|
||||
|
||||
class SignalFindDlg : public QDialog {
|
||||
|
|
Loading…
Reference in New Issue