cabana: add setting to choose preferred drag direction for new signals (#27932)

old-commit-hash: 0f22bb50de
beeps
Willem Melching 2 years ago committed by GitHub
parent 40caca7e24
commit 21f2724815
  1. 14
      tools/cabana/binaryview.cc
  2. 12
      tools/cabana/settings.cc
  3. 9
      tools/cabana/settings.h

@ -239,7 +239,19 @@ std::tuple<int, int, bool> BinaryView::getSelection(QModelIndex index) {
if (index.column() == 8) { if (index.column() == 8) {
index = model->index(index.row(), 7); index = model->index(index.row(), 7);
} }
bool is_lb = (resize_sig && resize_sig->is_little_endian) || (!resize_sig && index < anchor_index); bool is_lb = true;
if (resize_sig) {
is_lb = resize_sig->is_little_endian;
} else if (settings.drag_direction == Settings::DragDirection::MsbFirst) {
is_lb = index < anchor_index;
} else if (settings.drag_direction == Settings::DragDirection::LsbFirst) {
is_lb = !(index < anchor_index);
} else if (settings.drag_direction == Settings::DragDirection::AlwaysLE) {
is_lb = true;
} else if (settings.drag_direction == Settings::DragDirection::AlwaysBE) {
is_lb = false;
}
int cur_bit_idx = get_bit_index(index, is_lb); int cur_bit_idx = get_bit_index(index, is_lb);
int anchor_bit_idx = get_bit_index(anchor_index, is_lb); int anchor_bit_idx = get_bit_index(anchor_index, is_lb);
auto [start_bit, end_bit] = std::minmax(cur_bit_idx, anchor_bit_idx); auto [start_bit, end_bit] = std::minmax(cur_bit_idx, anchor_bit_idx);

@ -37,6 +37,7 @@ void Settings::save() {
s.setValue("multiple_lines_bytes", multiple_lines_bytes); s.setValue("multiple_lines_bytes", multiple_lines_bytes);
s.setValue("log_livestream", log_livestream); s.setValue("log_livestream", log_livestream);
s.setValue("log_path", log_path); s.setValue("log_path", log_path);
s.setValue("drag_direction", drag_direction);
} }
void Settings::load() { void Settings::load() {
@ -59,6 +60,7 @@ void Settings::load() {
multiple_lines_bytes = s.value("multiple_lines_bytes", true).toBool(); multiple_lines_bytes = s.value("multiple_lines_bytes", true).toBool();
log_livestream = s.value("log_livestream", true).toBool(); log_livestream = s.value("log_livestream", true).toBool();
log_path = s.value("log_path").toString(); log_path = s.value("log_path").toString();
drag_direction = (Settings::DragDirection)s.value("drag_direction", 0).toInt();
if (log_path.isEmpty()) { if (log_path.isEmpty()) {
log_path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/cabana_live_stream/"; log_path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/cabana_live_stream/";
} }
@ -91,6 +93,14 @@ SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) {
form_layout->addRow(tr("Max Cached Minutes"), cached_minutes); form_layout->addRow(tr("Max Cached Minutes"), cached_minutes);
main_layout->addWidget(groupbox); main_layout->addWidget(groupbox);
groupbox = new QGroupBox("New Signal Settings");
form_layout = new QFormLayout(groupbox);
drag_direction = new QComboBox(this);
drag_direction->addItems({tr("MSB First"), tr("LSB First"), tr("Always Little Endian"), tr("Always Big Endian")});
drag_direction->setCurrentIndex(settings.drag_direction);
form_layout->addRow(tr("Drag Direction"), drag_direction);
main_layout->addWidget(groupbox);
groupbox = new QGroupBox("Chart"); groupbox = new QGroupBox("Chart");
form_layout = new QFormLayout(groupbox); form_layout = new QFormLayout(groupbox);
chart_series_type = new QComboBox(this); chart_series_type = new QComboBox(this);
@ -114,6 +124,7 @@ SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) {
path_layout->addWidget(browse_btn); path_layout->addWidget(browse_btn);
main_layout->addWidget(log_livestream); main_layout->addWidget(log_livestream);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply);
main_layout->addWidget(buttonBox); main_layout->addWidget(buttonBox);
main_layout->addStretch(1); main_layout->addStretch(1);
@ -151,6 +162,7 @@ void SettingsDlg::save() {
settings.chart_height = chart_height->value(); settings.chart_height = chart_height->value();
settings.log_livestream = log_livestream->isChecked(); settings.log_livestream = log_livestream->isChecked();
settings.log_path = log_path->text(); settings.log_path = log_path->text();
settings.drag_direction = (Settings::DragDirection)drag_direction->currentIndex();
settings.save(); settings.save();
emit settings.changed(); emit settings.changed();
} }

@ -15,6 +15,13 @@ class Settings : public QObject {
Q_OBJECT Q_OBJECT
public: public:
enum DragDirection {
MsbFirst,
LsbFirst,
AlwaysLE,
AlwaysBE,
};
Settings(); Settings();
void save(); void save();
void load(); void load();
@ -37,6 +44,7 @@ public:
QByteArray window_state; QByteArray window_state;
QStringList recent_files; QStringList recent_files;
QByteArray message_header_state; QByteArray message_header_state;
DragDirection drag_direction;
signals: signals:
void changed(); void changed();
@ -55,6 +63,7 @@ public:
QComboBox *theme; QComboBox *theme;
QGroupBox *log_livestream; QGroupBox *log_livestream;
QLineEdit *log_path; QLineEdit *log_path;
QComboBox *drag_direction;
}; };
extern Settings settings; extern Settings settings;

Loading…
Cancel
Save