Skip to content

Commit 3f6f56c

Browse files
committed
gui: use a timer to debounce 'select' commands
When select is used it triggers a redraw. In a script with many such commands the execution slow to a crawl. This introduces timers to debounce such calls by 100ms. Signed-off-by: Matt Liberty <[email protected]>
1 parent 59ef9a9 commit 3f6f56c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/gui/src/mainWindow.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
9090
charts_widget_(new ChartsWidget(this)),
9191
help_widget_(new HelpWidget(this)),
9292
find_dialog_(new FindObjectDialog(this)),
93-
goto_dialog_(new GotoLocationDialog(this, viewers_))
93+
goto_dialog_(new GotoLocationDialog(this, viewers_)),
94+
selection_timer_(std::make_unique<QTimer>()),
95+
highlight_timer_(std::make_unique<QTimer>())
9496
{
9597
// Size and position the window
9698
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
@@ -389,6 +391,13 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
389391
&MainWindow::displayUnitsChanged,
390392
goto_dialog_,
391393
&GotoLocationDialog::updateUnits);
394+
connect(selection_timer_.get(), &QTimer::timeout, [this]() {
395+
emit selectionChanged();
396+
});
397+
connect(highlight_timer_.get(),
398+
&QTimer::timeout,
399+
this,
400+
&MainWindow::highlightChanged);
392401

393402
createActions();
394403
createToolbars();
@@ -436,6 +445,12 @@ MainWindow::MainWindow(bool load_settings, QWidget* parent)
436445
= [this](const std::string& value, bool* ok) -> int {
437446
return convertStringToDBU(value, ok);
438447
};
448+
449+
selection_timer_->setSingleShot(true);
450+
highlight_timer_->setSingleShot(true);
451+
452+
selection_timer_->setInterval(100 /* ms */);
453+
highlight_timer_->setInterval(100 /* ms */);
439454
}
440455

441456
MainWindow::~MainWindow()
@@ -1117,7 +1132,7 @@ void MainWindow::addSelected(const SelectionSet& selections, bool find_in_cts)
11171132
}
11181133
status(std::string("Added ")
11191134
+ std::to_string(selected_.size() - prev_selected_size));
1120-
emit selectionChanged();
1135+
selection_timer_->start();
11211136

11221137
if (find_in_cts) {
11231138
emit findInCts(selections);
@@ -1161,7 +1176,7 @@ void MainWindow::addHighlighted(const SelectionSet& highlights,
11611176
group.insert(highlight);
11621177
}
11631178
}
1164-
emit highlightChanged();
1179+
highlight_timer_->start();
11651180
}
11661181

11671182
std::string MainWindow::addLabel(int x,
@@ -1862,4 +1877,4 @@ void MainWindow::reportSlackHistogramPaths(
18621877

18631878
timing_widget_->reportSlackHistogramPaths(report_pins, path_group_name);
18641879
}
1865-
} // namespace gui
1880+
} // namespace gui

src/gui/src/mainWindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ class MainWindow : public QMainWindow, public odb::dbDatabaseObserver
369369
std::map<HeatMapDataSource*, QAction*> heatmap_actions_;
370370

371371
std::unique_ptr<utl::Progress> cli_progress_ = nullptr;
372+
373+
std::unique_ptr<QTimer> selection_timer_;
374+
std::unique_ptr<QTimer> highlight_timer_;
372375
};
373376

374377
} // namespace gui

0 commit comments

Comments
 (0)