Qt: Elide redundant scan progress updates

Fixes UI locking up for ages when switching theme.
This commit is contained in:
Connor McLaughlin 2022-07-09 20:41:52 +10:00 committed by refractionpcsx2
parent a77f78f08f
commit f0f23a2c61
2 changed files with 10 additions and 5 deletions

View File

@ -204,6 +204,8 @@ void MainWindow::setupAdditionalUi()
m_status_progress_widget = new QProgressBar(m_ui.statusBar);
m_status_progress_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
m_status_progress_widget->setFixedSize(140, 16);
m_status_progress_widget->setMinimum(0);
m_status_progress_widget->setMaximum(100);
m_status_progress_widget->hide();
m_status_verbose_widget = new QLabel(m_ui.statusBar);
@ -820,8 +822,9 @@ void MainWindow::updateWindowState(bool force_visible)
void MainWindow::setProgressBar(int current, int total)
{
m_status_progress_widget->setValue(current);
m_status_progress_widget->setMaximum(total);
const int value = (current * 100) / total;
if (m_status_progress_widget->value() != value)
m_status_progress_widget->setValue(value);
if (m_status_progress_widget->isVisible())
return;

View File

@ -547,11 +547,14 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache,
(FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_HIDDEN_FILES),
&files);
u32 files_scanned = 0;
progress->SetProgressRange(static_cast<u32>(files.size()));
progress->SetProgressValue(0);
for (FILESYSTEM_FIND_DATA& ffd : files)
{
files_scanned++;
if (progress->IsCancelled() || !GameList::IsScannableFilename(ffd.FileName) ||
IsPathExcluded(excluded_paths, ffd.FileName))
{
@ -564,7 +567,6 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache,
AddFileFromCache(ffd.FileName, ffd.ModificationTime) ||
only_cache)
{
progress->IncrementProgressValue();
continue;
}
}
@ -572,10 +574,10 @@ void GameList::ScanDirectory(const char* path, bool recursive, bool only_cache,
// ownership of fp is transferred
progress->SetFormattedStatusText("Scanning '%s'...", FileSystem::GetDisplayNameFromPath(ffd.FileName).c_str());
ScanFile(std::move(ffd.FileName), ffd.ModificationTime);
progress->IncrementProgressValue();
progress->SetProgressValue(files_scanned);
}
progress->SetProgressValue(static_cast<u32>(files.size()));
progress->SetProgressValue(files_scanned);
progress->PopState();
}