mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-27 13:03:52 +08:00
cabana: add keyboard shortcuts to binary view (#27338)
* cabana: add keyboard shortcuts to binary view * typo * whitespace * keep signal highlighted
This commit is contained in:
@@ -7,9 +7,11 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
#include <QShortcut>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "tools/cabana/commands.h"
|
||||
#include "tools/cabana/signaledit.h"
|
||||
#include "tools/cabana/streams/abstractstream.h"
|
||||
|
||||
// BinaryView
|
||||
@@ -38,6 +40,63 @@ BinaryView::BinaryView(QWidget *parent) : QTableView(parent) {
|
||||
|
||||
QObject::connect(dbc(), &DBCManager::DBCFileChanged, this, &BinaryView::refresh);
|
||||
QObject::connect(UndoStack::instance(), &QUndoStack::indexChanged, this, &BinaryView::refresh);
|
||||
|
||||
addShortcuts();
|
||||
}
|
||||
|
||||
void BinaryView::addShortcuts() {
|
||||
// Delete (x, backspace, delete)
|
||||
QShortcut *shortcut_delete_x = new QShortcut(QKeySequence(Qt::Key_X), this);
|
||||
QShortcut *shortcut_delete_backspace = new QShortcut(QKeySequence(Qt::Key_Backspace), this);
|
||||
QShortcut *shortcut_delete_delete = new QShortcut(QKeySequence(Qt::Key_Delete), this);
|
||||
QObject::connect(shortcut_delete_delete, &QShortcut::activated, shortcut_delete_x, &QShortcut::activated);
|
||||
QObject::connect(shortcut_delete_backspace, &QShortcut::activated, shortcut_delete_x, &QShortcut::activated);
|
||||
QObject::connect(shortcut_delete_x, &QShortcut::activated, [=]{
|
||||
if (hovered_sig != nullptr) {
|
||||
emit removeSignal(hovered_sig);
|
||||
hovered_sig = nullptr;
|
||||
}
|
||||
});
|
||||
|
||||
// Change endianness (e)
|
||||
QShortcut *shortcut_endian = new QShortcut(QKeySequence(Qt::Key_E), this);
|
||||
QObject::connect(shortcut_endian, &QShortcut::activated, [=]{
|
||||
if (hovered_sig != nullptr) {
|
||||
const Signal *hovered_sig_prev = hovered_sig;
|
||||
Signal s = *hovered_sig;
|
||||
s.is_little_endian = !s.is_little_endian;
|
||||
emit editSignal(hovered_sig, s);
|
||||
|
||||
hovered_sig = nullptr;
|
||||
highlight(hovered_sig_prev);
|
||||
}
|
||||
});
|
||||
|
||||
// Change signedness (s)
|
||||
QShortcut *shortcut_sign = new QShortcut(QKeySequence(Qt::Key_S), this);
|
||||
QObject::connect(shortcut_sign, &QShortcut::activated, [=]{
|
||||
if (hovered_sig != nullptr) {
|
||||
const Signal *hovered_sig_prev = hovered_sig;
|
||||
Signal s = *hovered_sig;
|
||||
s.is_signed = !s.is_signed;
|
||||
emit editSignal(hovered_sig, s);
|
||||
|
||||
hovered_sig = nullptr;
|
||||
highlight(hovered_sig_prev);
|
||||
}
|
||||
});
|
||||
|
||||
// Open chart (c, p, g)
|
||||
QShortcut *shortcut_plot = new QShortcut(QKeySequence(Qt::Key_P), this);
|
||||
QShortcut *shortcut_plot_g = new QShortcut(QKeySequence(Qt::Key_G), this);
|
||||
QShortcut *shortcut_plot_c = new QShortcut(QKeySequence(Qt::Key_C), this);
|
||||
QObject::connect(shortcut_plot_g, &QShortcut::activated, shortcut_plot, &QShortcut::activated);
|
||||
QObject::connect(shortcut_plot_c, &QShortcut::activated, shortcut_plot, &QShortcut::activated);
|
||||
QObject::connect(shortcut_plot, &QShortcut::activated, [=]{
|
||||
if (hovered_sig != nullptr) {
|
||||
emit showChart(model->msg_id, hovered_sig, true, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QSize BinaryView::minimumSizeHint() const {
|
||||
|
||||
@@ -68,8 +68,12 @@ signals:
|
||||
void signalHovered(const Signal *sig);
|
||||
void addSignal(int start_bit, int size, bool little_endian);
|
||||
void resizeSignal(const Signal *sig, int from, int size);
|
||||
void removeSignal(const Signal *sig);
|
||||
void editSignal(const Signal *origin_s, Signal &s);
|
||||
void showChart(const QString &name, const Signal *sig, bool show, bool merge);
|
||||
|
||||
private:
|
||||
void addShortcuts();
|
||||
void refresh();
|
||||
std::tuple<int, int, bool> getSelection(QModelIndex index);
|
||||
void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags flags) override;
|
||||
|
||||
@@ -74,6 +74,9 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
|
||||
QObject::connect(binary_view, &BinaryView::addSignal, signal_view->model, &SignalModel::addSignal);
|
||||
QObject::connect(binary_view, &BinaryView::signalHovered, signal_view, &SignalView::signalHovered);
|
||||
QObject::connect(binary_view, &BinaryView::signalClicked, signal_view, &SignalView::expandSignal);
|
||||
QObject::connect(binary_view, &BinaryView::editSignal, signal_view->model, &SignalModel::saveSignal);
|
||||
QObject::connect(binary_view, &BinaryView::removeSignal, signal_view->model, &SignalModel::removeSignal);
|
||||
QObject::connect(binary_view, &BinaryView::showChart, charts, &ChartsWidget::showChart);
|
||||
QObject::connect(signal_view, &SignalView::showChart, charts, &ChartsWidget::showChart);
|
||||
QObject::connect(signal_view, &SignalView::highlight, binary_view, &BinaryView::highlight);
|
||||
QObject::connect(tab_widget, &QTabWidget::currentChanged, [this]() { updateState(); });
|
||||
|
||||
Reference in New Issue
Block a user