Cabana: Move history logs to a tabbed widget (#26481)

* tabwidget

* cleanup

* update state  before show

* cleanup

* remove spacing

* fix right panel stretch issue

* fix missing }
old-commit-hash: 8e91ce1eb4
This commit is contained in:
Dean Lee 2022-11-15 11:09:19 +08:00 committed by GitHub
parent dd16344a1b
commit 53922eaed4
6 changed files with 47 additions and 46 deletions

View File

@ -64,31 +64,35 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
frame_layout->addWidget(warning_widget);
main_layout->addWidget(title_frame);
QWidget *container = new QWidget(this);
QVBoxLayout *container_layout = new QVBoxLayout(container);
container_layout->setSpacing(0);
container_layout->setContentsMargins(0, 0, 0, 0);
scroll = new QScrollArea(this);
scroll->setWidget(container);
scroll->setWidgetResizable(true);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
main_layout->addWidget(scroll);
// msg widget
QWidget *msg_widget = new QWidget(this);
QVBoxLayout *msg_layout = new QVBoxLayout(msg_widget);
msg_layout->setContentsMargins(0, 0, 0, 0);
// binary view
binary_view = new BinaryView(this);
container_layout->addWidget(binary_view);
msg_layout->addWidget(binary_view);
// signals
signals_layout = new QVBoxLayout();
container_layout->addLayout(signals_layout);
signals_layout->setSpacing(0);
msg_layout->addLayout(signals_layout);
msg_layout->addStretch(0);
// history log
scroll = new QScrollArea(this);
scroll->setFrameShape(QFrame::NoFrame);
scroll->setWidget(msg_widget);
scroll->setWidgetResizable(true);
scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tab_widget = new QTabWidget(this);
tab_widget->setTabPosition(QTabWidget::South);
tab_widget->addTab(scroll, "Msg");
history_log = new HistoryLog(this);
container_layout->addWidget(history_log);
tab_widget->addTab(history_log, "Logs");
main_layout->addWidget(tab_widget);
QObject::connect(binary_view, &BinaryView::resizeSignal, this, &DetailWidget::resizeSignal);
QObject::connect(binary_view, &BinaryView::addSignal, this, &DetailWidget::addSignal);
QObject::connect(tab_widget, &QTabWidget::currentChanged, [this]() { updateState(); });
QObject::connect(can, &CANMessages::msgsReceived, this, &DetailWidget::updateState);
QObject::connect(dbc(), &DBCManager::DBCFileChanged, [this]() { dbcMsgChanged(); });
QObject::connect(tabbar, &QTabBar::customContextMenuRequested, this, &DetailWidget::showTabBarContextMenu);
@ -151,6 +155,7 @@ void DetailWidget::dbcMsgChanged(int show_form_idx) {
form = new SignalEdit(i);
QObject::connect(form, &SignalEdit::remove, this, &DetailWidget::removeSignal);
QObject::connect(form, &SignalEdit::save, this, &DetailWidget::saveSignal);
QObject::connect(form, &SignalEdit::showFormClicked, this, &DetailWidget::showFormClicked);
QObject::connect(form, &SignalEdit::highlight, binary_view, &BinaryView::highlight);
QObject::connect(binary_view, &BinaryView::signalHovered, form, &SignalEdit::signalHovered);
QObject::connect(form, &SignalEdit::showChart, charts, &ChartsWidget::showChart);
@ -176,16 +181,26 @@ void DetailWidget::dbcMsgChanged(int show_form_idx) {
warning_label->setText(warnings.join('\n'));
warning_widget->setVisible(!warnings.isEmpty());
QTimer::singleShot(1, [this]() { setUpdatesEnabled(true); });
setUpdatesEnabled(true);
}
void DetailWidget::updateState(const QHash<QString, CanData> * msgs) {
time_label->setText(QString::number(can->currentSec(), 'f', 3));
if (!msgs->contains(msg_id))
if (msg_id.isEmpty() || (msgs && !msgs->contains(msg_id)))
return;
binary_view->updateState();
history_log->updateState();
if (tab_widget->currentIndex() == 0)
binary_view->updateState();
else
history_log->updateState();
}
void DetailWidget::showFormClicked() {
auto s = qobject_cast<SignalEdit *>(sender());
setUpdatesEnabled(false);
for (auto f : signal_list)
f->updateForm(f == s && !f->isFormVisible());
setUpdatesEnabled(true);
}
void DetailWidget::updateChartState(const QString &id, const Signal *sig, bool opened) {

View File

@ -1,7 +1,7 @@
#pragma once
#include <QScrollArea>
#include <QTabBar>
#include <QTabWidget>
#include <QToolBar>
#include <QUndoStack>
@ -28,6 +28,7 @@ public:
QUndoStack *undo_stack = nullptr;
private:
void showFormClicked();
void updateChartState(const QString &id, const Signal *sig, bool opened);
void showTabBarContextMenu(const QPoint &pt);
void addSignal(int start_bit, int size, bool little_endian);
@ -36,13 +37,14 @@ private:
void removeSignal(const Signal *sig);
void editMsg();
void removeMsg();
void updateState(const QHash<QString, CanData> * msgs);
void updateState(const QHash<QString, CanData> * msgs = nullptr);
QString msg_id;
QLabel *name_label, *time_label, *warning_label;
QWidget *warning_widget;
QVBoxLayout *signals_layout;
QTabBar *tabbar;
QTabWidget *tab_widget;
QToolBar *toolbar;
QAction *remove_msg_act;
HistoryLog *history_log;

View File

@ -86,10 +86,8 @@ HistoryLog::HistoryLog(QWidget *parent) : QTableView(parent) {
horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | (Qt::Alignment)Qt::TextWordWrap);
horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
verticalHeader()->setVisible(false);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
setFrameShape(QFrame::NoFrame);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
setStyleSheet("QTableView::item { border:0px; padding-left:5px; padding-right:5px; }");
}

View File

@ -72,7 +72,7 @@ MainWindow::MainWindow() : QMainWindow() {
video_widget = new VideoWidget(this);
r_layout->addWidget(video_widget, 0, Qt::AlignTop);
r_layout->addWidget(charts_widget);
r_layout->addWidget(charts_widget, 1);
main_layout->addWidget(right_container);
setCentralWidget(central_widget);
@ -192,9 +192,10 @@ void MainWindow::saveDBCToFile() {
if (!file_name.isEmpty()) {
settings.last_dir = QFileInfo(file_name).absolutePath();
QFile file(file_name);
if (file.open(QIODevice::WriteOnly))
if (file.open(QIODevice::WriteOnly)) {
file.write(dbc()->generateDBC().toUtf8());
detail_widget->undo_stack->clear();
}
}
}
@ -216,7 +217,7 @@ void MainWindow::updateDownloadProgress(uint64_t cur, uint64_t total, bool succe
void MainWindow::dockCharts(bool dock) {
if (dock && floating_window) {
floating_window->removeEventFilter(charts_widget);
r_layout->addWidget(charts_widget);
r_layout->addWidget(charts_widget, 1);
floating_window->deleteLater();
floating_window = nullptr;
} else if (!dock && !floating_window) {

View File

@ -4,7 +4,6 @@
#include <QFormLayout>
#include <QHBoxLayout>
#include <QScrollArea>
#include <QTimer>
#include <QToolBar>
#include <QVBoxLayout>
@ -189,26 +188,12 @@ void SignalEdit::updateForm(bool visible) {
icon->setText(visible ? "" : "> ");
}
void SignalEdit::showFormClicked() {
parentWidget()->setUpdatesEnabled(false);
for (auto &edit : parentWidget()->findChildren<SignalEdit*>())
edit->updateForm(edit == this && !form->isVisible());
QTimer::singleShot(1, [this]() { parentWidget()->setUpdatesEnabled(true); });
}
void SignalEdit::signalHovered(const Signal *s) {
auto bg_color = sig == s ? hoverColor(getColor(form_idx)) : QColor(getColor(form_idx));
auto color = sig == s ? "white" : "black";
color_label->setStyleSheet(QString("color:%1; background-color:%2").arg(color).arg(bg_color.name()));
}
void SignalEdit::hideEvent(QHideEvent *event) {
msg_id = "";
sig = nullptr;
updateForm(false);
QWidget::hideEvent(event);
}
void SignalEdit::enterEvent(QEvent *event) {
emit highlight(sig);
QWidget::enterEvent(event);

View File

@ -34,6 +34,8 @@ public:
void setSignal(const QString &msg_id, const Signal *sig);
void setChartOpened(bool opened);
void signalHovered(const Signal *sig);
void updateForm(bool show);
inline bool isFormVisible() const { return form->isVisible(); }
const Signal *sig = nullptr;
QString msg_id;
@ -42,14 +44,12 @@ signals:
void showChart(const QString &name, const Signal *sig, bool show);
void remove(const Signal *sig);
void save(const Signal *sig, const Signal &new_sig);
void showFormClicked();
protected:
void hideEvent(QHideEvent *event) override;
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
void saveSignal();
void updateForm(bool show);
void showFormClicked();
SignalForm *form = nullptr;
ElidedLabel *title;