Skip to content

Commit c8deea9

Browse files
committed
Add global analysis progress percentage & fix UI jitter
1 parent c4a64f1 commit c8deea9

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

src/library/analysis/dlganalysis.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "widget/wlibrary.h"
1212

1313
DlgAnalysis::DlgAnalysis(WLibrary* parent,
14-
UserSettingsPointer pConfig,
15-
Library* pLibrary)
14+
UserSettingsPointer pConfig,
15+
Library* pLibrary)
1616
: QWidget(parent),
1717
m_pConfig(pConfig),
1818
m_bAnalysisActive(false) {
@@ -41,7 +41,8 @@ DlgAnalysis::DlgAnalysis(WLibrary* parent,
4141

4242
QBoxLayout* box = qobject_cast<QBoxLayout*>(layout());
4343
VERIFY_OR_DEBUG_ASSERT(box) { // Assumes the form layout is a QVBox/QHBoxLayout!
44-
} else {
44+
}
45+
else {
4546
box->removeWidget(m_pTrackTablePlaceholder);
4647
m_pTrackTablePlaceholder->hide();
4748
box->insertWidget(1, m_pAnalysisLibraryTableView);
@@ -117,10 +118,8 @@ void DlgAnalysis::onSearch(const QString& text) {
117118
text, radioButtonRecentlyAdded->isChecked());
118119
}
119120

120-
void DlgAnalysis::tableSelectionChanged(const QItemSelection& selected,
121-
const QItemSelection& deselected) {
122-
Q_UNUSED(selected);
123-
Q_UNUSED(deselected);
121+
void DlgAnalysis::tableSelectionChanged(const QItemSelection&,
122+
const QItemSelection&) {
124123
bool tracksSelected = m_pAnalysisLibraryTableView->selectionModel()->hasSelection();
125124
pushButtonAnalyze->setEnabled(tracksSelected || m_bAnalysisActive);
126125
}
@@ -130,14 +129,14 @@ void DlgAnalysis::selectAll() {
130129
}
131130

132131
void DlgAnalysis::analyze() {
133-
//qDebug() << this << "analyze()";
132+
// qDebug() << this << "analyze()";
134133
if (m_bAnalysisActive) {
135134
emit stopAnalysis();
136135
} else {
137136
QList<AnalyzerScheduledTrack> tracks;
138137

139138
QModelIndexList selectedIndexes = m_pAnalysisLibraryTableView->selectionModel()->selectedRows();
140-
foreach(QModelIndex selectedIndex, selectedIndexes) {
139+
for (const auto& selectedIndex : std::as_const(selectedIndexes)) {
141140
TrackId trackId(m_pAnalysisLibraryTableModel->getFieldVariant(
142141
selectedIndex, ColumnCache::COLUMN_LIBRARYTABLE_ID));
143142
if (trackId.isValid()) {
@@ -149,7 +148,7 @@ void DlgAnalysis::analyze() {
149148
}
150149

151150
void DlgAnalysis::slotAnalysisActive(bool bActive) {
152-
//qDebug() << this << "slotAnalysisActive" << bActive;
151+
// qDebug() << this << "slotAnalysisActive" << bActive;
153152
m_bAnalysisActive = bActive;
154153
if (bActive) {
155154
pushButtonAnalyze->setChecked(true);
@@ -165,24 +164,23 @@ void DlgAnalysis::slotAnalysisActive(bool bActive) {
165164
}
166165

167166
void DlgAnalysis::onTrackAnalysisSchedulerProgress(
168-
AnalyzerProgress analyzerProgress, int finishedCount, int totalCount) {
169-
//qDebug() << this << "onTrackAnalysisSchedulerProgress" << analyzerProgress << finishedCount << totalCount;
167+
AnalyzerProgress, int finishedCount, int totalCount) {
168+
// qDebug() << this << "onTrackAnalysisSchedulerProgress" <<
169+
// analyzerProgress << finishedCount << totalCount;
170170
if (labelProgress->isEnabled()) {
171-
QString progressText;
172-
if (analyzerProgress >= kAnalyzerProgressNone) {
173-
QString progressPercent = QString::number(
174-
analyzerProgressPercent(analyzerProgress));
175-
progressText = tr("Analyzing %1% %2/%3").arg(
176-
progressPercent,
177-
QString::number(finishedCount),
178-
QString::number(totalCount));
179-
} else {
180-
// Omit to display any percentage
181-
progressText = tr("Analyzing %1/%2").arg(
182-
QString::number(finishedCount),
183-
QString::number(totalCount));
171+
int totalProgressPercent = 0;
172+
if (totalCount > 0) {
173+
totalProgressPercent = (finishedCount * 100) / totalCount;
174+
if (totalProgressPercent > 100) {
175+
totalProgressPercent = 100;
176+
}
184177
}
185-
labelProgress->setText(progressText);
178+
179+
labelProgress->setText(tr("Analyzing %1/%2")
180+
.arg(QString::number(finishedCount),
181+
QString::number(totalCount)) +
182+
QStringLiteral(" (%3%)").arg(
183+
QString::number(totalProgressPercent)));
186184
}
187185
}
188186

0 commit comments

Comments
 (0)