Cabana: fix possible crash when removing tabs (#26283)

fix dead loop
pull/26293/head
Dean Lee 3 years ago committed by GitHub
parent 9c7e375944
commit 6fed76695c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      tools/cabana/detailwidget.cc

@ -104,12 +104,7 @@ DetailWidget::DetailWidget(ChartsWidget *charts, QWidget *parent) : charts(chart
setMessage(tabbar->tabText(index)); setMessage(tabbar->tabText(index));
} }
}); });
QObject::connect(tabbar, &QTabBar::tabCloseRequested, [=](int index) { QObject::connect(tabbar, &QTabBar::tabCloseRequested, tabbar, &QTabBar::removeTab);
if (tabbar->currentIndex() == index) {
tabbar->setCurrentIndex(index == tabbar->count() - 1 ? index - 1 : index + 1);
}
tabbar->removeTab(index);
});
QObject::connect(charts, &ChartsWidget::chartOpened, [this](const QString &id, const Signal *sig) { updateChartState(id, sig, true); }); QObject::connect(charts, &ChartsWidget::chartOpened, [this](const QString &id, const Signal *sig) { updateChartState(id, sig, true); });
QObject::connect(charts, &ChartsWidget::chartClosed, [this](const QString &id, const Signal *sig) { updateChartState(id, sig, false); }); QObject::connect(charts, &ChartsWidget::chartClosed, [this](const QString &id, const Signal *sig) { updateChartState(id, sig, false); });
} }
@ -120,9 +115,14 @@ void DetailWidget::showTabBarContextMenu(const QPoint &pt) {
QMenu menu(this); QMenu menu(this);
menu.addAction(tr("Close Other Tabs")); menu.addAction(tr("Close Other Tabs"));
if (menu.exec(tabbar->mapToGlobal(pt))) { if (menu.exec(tabbar->mapToGlobal(pt))) {
for (int i = tabbar->count() - 1; i >= 0; --i) { tabbar->setCurrentIndex(index);
if (i != index) // remove all tabs before the one to keep
tabbar->removeTab(i); for (int i = 0; i < index; ++i) {
tabbar->removeTab(0);
}
// remove all tabs after the one to keep
while (tabbar->count() > 1) {
tabbar->removeTab(1);
} }
} }
} }

Loading…
Cancel
Save