diff --git a/language/backgroundparser/backgroundparser.h b/language/backgroundparser/backgroundparser.h --- a/language/backgroundparser/backgroundparser.h +++ b/language/backgroundparser/backgroundparser.h @@ -192,7 +192,7 @@ */ void parseDocuments(); - void updateProgressBar(); + void updateProgressData(); ///Disables processing for all jobs that have a worse priority than @param priority ///This can be used to temporarily limit the processing to only the most important jobs. @@ -229,6 +229,7 @@ void parseProgress(KDevelop::ParseJob*, float value, QString text); void startTimer(int delay); void aboutToQuit(); + void updateProgressBar(); private: friend class BackgroundParserPrivate; diff --git a/language/backgroundparser/backgroundparser.cpp b/language/backgroundparser/backgroundparser.cpp --- a/language/backgroundparser/backgroundparser.cpp +++ b/language/backgroundparser/backgroundparser.cpp @@ -197,10 +197,15 @@ m_doneParseJobs = 0; m_maxParseJobs = 0; m_neededPriority = BackgroundParser::WorstPriority; + m_progressMax = 0; + m_progressDone = 0; + m_progressTimer.setSingleShot(true); + m_progressTimer.setInterval(500); ThreadWeaver::setDebugLevel(true, 1); QObject::connect(&m_timer, &QTimer::timeout, m_parser, &BackgroundParser::parseDocuments); + QObject::connect(&m_progressTimer, &QTimer::timeout, m_parser, &BackgroundParser::updateProgressBar); } void startTimerThreadSafe(int delay) { @@ -347,7 +352,7 @@ } } - m_parser->updateProgressBar(); + m_parser->updateProgressData(); //We don't hide the progress-bar in updateProgressBar, so it doesn't permanently flash when a document is reparsed again and again. if(m_doneParseJobs == m_maxParseJobs @@ -511,6 +516,9 @@ int m_doneParseJobs; QHash m_jobProgress; int m_neededPriority; //The minimum priority needed for processed jobs + int m_progressMax; + int m_progressDone; + QTimer m_progressTimer; }; BackgroundParser::BackgroundParser(ILanguageController *languageController) @@ -561,7 +569,7 @@ { Q_UNUSED(text) d->m_jobProgress[job] = value; - updateProgressBar(); + updateProgressData(); } void BackgroundParser::revertAllRequests(QObject* notifyWhenReady) @@ -677,7 +685,7 @@ d->m_jobProgress.remove(parseJob); ++d->m_doneParseJobs; - updateProgressBar(); + updateProgressData(); } //Continue creating more parse-jobs @@ -744,10 +752,10 @@ void BackgroundParser::resume() { d->resume(); - updateProgressBar(); + updateProgressData(); } -void BackgroundParser::updateProgressBar() +void BackgroundParser::updateProgressData() { if (d->m_doneParseJobs >= d->m_maxParseJobs) { if(d->m_doneParseJobs > d->m_maxParseJobs) { @@ -761,7 +769,12 @@ additionalProgress += *it; } - emit showProgress(this, 0, d->m_maxParseJobs*1000, (additionalProgress + d->m_doneParseJobs)*1000); + d->m_progressMax = d->m_maxParseJobs*1000; + d->m_progressDone = (additionalProgress + d->m_doneParseJobs)*1000; + + if (!d->m_progressTimer.isActive()) { + d->m_progressTimer.start(); + } } } @@ -899,3 +912,8 @@ { d->m_loadingProjects.remove(project); } + +void BackgroundParser::updateProgressBar() +{ + emit showProgress(this, 0, d->m_progressMax, d->m_progressDone); +}