Skip to content

Commit

Permalink
cabana: attach messageid to tabdata (#27368)
Browse files Browse the repository at this point in the history
old-commit-hash: 2c5e55c
  • Loading branch information
deanlee authored Feb 17, 2023
1 parent e31c5b2 commit 517a020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
20 changes: 9 additions & 11 deletions tools/cabana/detailwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
QObject::connect(tabbar, &QTabBar::customContextMenuRequested, this, &DetailWidget::showTabBarContextMenu);
QObject::connect(tabbar, &QTabBar::currentChanged, [this](int index) {
if (index != -1) {
setMessage(tabbar_ids[index]);
setMessage(tabbar->tabData(index).value<MessageId>());
}
});
QObject::connect(tabbar, &QTabBar::tabCloseRequested, [this](int index) {
tabbar_ids.removeAt(index);
tabbar->removeTab(index);
assert(tabbar_ids.size() == tabbar->count());
});
QObject::connect(charts, &ChartsWidget::seriesChanged, signal_view, &SignalView::updateChartState);
}
Expand All @@ -103,14 +101,11 @@ void DetailWidget::showTabBarContextMenu(const QPoint &pt) {
QMenu menu(this);
menu.addAction(tr("Close Other Tabs"));
if (menu.exec(tabbar->mapToGlobal(pt))) {
tabbar_ids.move(index, 0);
tabbar->moveTab(index, 0);
tabbar->setCurrentIndex(0);
while (tabbar->count() > 1) {
tabbar_ids.removeAt(1);
tabbar->removeTab(1);
}
assert(tabbar_ids.size() == tabbar->count());
}
}
}
Expand All @@ -121,21 +116,25 @@ void DetailWidget::removeAll() {
while (tabbar->count() > 0) {
tabbar->removeTab(0);
}
tabbar_ids.clear();
tabbar->blockSignals(false);
stacked_layout->setCurrentIndex(0);
}

void DetailWidget::setMessage(const MessageId &message_id) {
msg_id = message_id;
int index = tabbar_ids.indexOf(*msg_id);

tabbar->blockSignals(true);
int index = tabbar->count() - 1;
for (/**/; index >= 0; --index) {
if (tabbar->tabData(index).value<MessageId>() == message_id) break;
}
if (index == -1) {
tabbar_ids.append(*msg_id);
index = tabbar->addTab(message_id.toString());
tabbar->setTabData(index, QVariant::fromValue(message_id));
tabbar->setTabToolTip(index, msgName(message_id));
}
assert(tabbar->count() == tabbar_ids.size());
tabbar->setCurrentIndex(index);
tabbar->blockSignals(false);

setUpdatesEnabled(false);

Expand All @@ -144,7 +143,6 @@ void DetailWidget::setMessage(const MessageId &message_id) {
history_log->setMessage(*msg_id);

stacked_layout->setCurrentIndex(1);
tabbar->setCurrentIndex(index);
refresh();
splitter->setSizes({1, 2});

Expand Down
1 change: 0 additions & 1 deletion tools/cabana/detailwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class DetailWidget : public QWidget {
ElidedLabel *name_label;
QWidget *warning_widget;
QTabBar *tabbar;
QList<MessageId> tabbar_ids;
QTabWidget *tab_widget;
QAction *remove_msg_act;
LogsWidget *history_log;
Expand Down

0 comments on commit 517a020

Please sign in to comment.