cabana: display chart count in tab (#27853)

display chart count in tabbar
old-commit-hash: f77930f569
beeps
Dean Lee 2 years ago committed by GitHub
parent aab590bcfb
commit e9bdfdd807
  1. 23
      tools/cabana/chart/chartswidget.cc
  2. 1
      tools/cabana/chart/chartswidget.h

@ -105,6 +105,7 @@ ChartsWidget::ChartsWidget(QWidget *parent) : align_timer(this), auto_scroll_tim
QObject::connect(reset_zoom_btn, &QToolButton::clicked, this, &ChartsWidget::zoomReset);
QObject::connect(&settings, &Settings::changed, this, &ChartsWidget::settingChanged);
QObject::connect(new_tab_btn, &QToolButton::clicked, this, &ChartsWidget::newTab);
QObject::connect(this, &ChartsWidget::seriesChanged, this, &ChartsWidget::updateTabBar);
QObject::connect(tabbar, &QTabBar::tabCloseRequested, this, &ChartsWidget::removeTab);
QObject::connect(tabbar, &QTabBar::currentChanged, [this](int index) {
if (index != -1) updateLayout(true);
@ -126,10 +127,8 @@ void ChartsWidget::newTab() {
static int tab_unique_id = 0;
int idx = tabbar->addTab("");
tabbar->setTabData(idx, tab_unique_id++);
for (int i = 0; i < tabbar->count(); ++i) {
tabbar->setTabText(i, QString("Tab %1").arg(i + 1));
}
tabbar->setCurrentIndex(idx);
updateTabBar();
}
void ChartsWidget::removeTab(int index) {
@ -139,6 +138,14 @@ void ChartsWidget::removeTab(int index) {
}
tab_charts.erase(id);
tabbar->removeTab(index);
updateTabBar();
}
void ChartsWidget::updateTabBar() {
for (int i = 0; i < tabbar->count(); ++i) {
const auto &charts_in_tab = tab_charts[tabbar->tabData(i).toInt()];
tabbar->setTabText(i, QString("Tab %1 (%2)").arg(i + 1).arg(charts_in_tab.count()));
}
}
void ChartsWidget::eventsMerged() {
@ -381,18 +388,19 @@ void ChartsWidget::removeChart(ChartView *chart) {
}
void ChartsWidget::removeAll() {
while (tabbar->count() > 1) {
tabbar->removeTab(1);
}
tab_charts.clear();
if (!charts.isEmpty()) {
for (auto c : charts) {
c->deleteLater();
}
charts.clear();
tab_charts.clear();
updateToolBar();
emit seriesChanged();
}
while (tabbar->count() > 1) {
tabbar->removeTab(1);
}
}
void ChartsWidget::alignCharts() {
@ -475,6 +483,7 @@ void ChartsContainer::dropEvent(QDropEvent *event) {
int to = w ? charts_widget->currentCharts().indexOf(w) + 1 : 0;
charts_widget->currentCharts().insert(to, chart);
charts_widget->updateLayout(true);
charts_widget->updateTabBar();
event->acceptProposedAction();
chart->startAnimation();
}

@ -67,6 +67,7 @@ private:
void stopAutoScroll();
void doAutoScroll();
void updateToolBar();
void updateTabBar();
void setMaxChartRange(int value);
void updateLayout(bool force = false);
void settingChanged();

Loading…
Cancel
Save