diff options
Diffstat (limited to 'src/libs/installer/progresscoordinator.cpp')
-rw-r--r-- | src/libs/installer/progresscoordinator.cpp | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/libs/installer/progresscoordinator.cpp b/src/libs/installer/progresscoordinator.cpp index a0f664357..e55f4b8bb 100644 --- a/src/libs/installer/progresscoordinator.cpp +++ b/src/libs/installer/progresscoordinator.cpp @@ -54,13 +54,13 @@ uint qHash(QPointer<QObject> key) QT_END_NAMESPACE ProgressCoordinator::ProgressCoordinator(QObject *parent) - : QObject(parent), - m_currentCompletePercentage(0), - m_currentBasePercentage(0), - m_manualAddedPercentage(0), - m_reservedPercentage(0), - m_undoMode(false), - m_reachedPercentageBeforeUndo(0) + : QObject(parent) + , m_currentCompletePercentage(0) + , m_currentBasePercentage(0) + , m_manualAddedPercentage(0) + , m_reservedPercentage(0) + , m_undoMode(false) + , m_reachedPercentageBeforeUndo(0) { // it has to be in the main thread to be able refresh the ui with processEvents Q_ASSERT(thread() == qApp->thread()); @@ -103,6 +103,14 @@ void ProgressCoordinator::registerPartProgress(QObject *sender, const char *sign Q_ASSERT(isConnected); } + +/*! + This slot gets the progress changed signals from different tasks. The values 0 and 1 are handled as + special values. + + 0 - is just ignored, so you can use a timer which gives the progress, e.g. like a downloader does. + 1 - means the task is finished, even if there comes another 1 from that task, so it will be ignored. +*/ void ProgressCoordinator::partProgressChanged(double fraction) { if (fraction < 0 || fraction > 1) { @@ -110,6 +118,16 @@ void ProgressCoordinator::partProgressChanged(double fraction) return; } + // no fraction no change + if (fraction == 0) + return; + + // ignore senders sending 100% multiple times + if (fraction == 1 && m_senderPendingCalculatedPercentageHash.contains(sender()) + && m_senderPendingCalculatedPercentageHash.value(sender()) == 0) { + return; + } + double partProgressSize = m_senderPartProgressSizeHash.value(sender(), 0); if (partProgressSize == 0) { qWarning() << "It seems that this sender was not registered in the right way:" << sender(); @@ -137,9 +155,9 @@ void ProgressCoordinator::partProgressChanged(double fraction) newCurrentCompletePercentage = 100; } - if (qRound(m_currentCompletePercentage) < qRound(newCurrentCompletePercentage)) { - qFatal("This should not happen!"); - } + // In undo mode, the progress has to go backward, new has to be smaller than current + if (qRound(m_currentCompletePercentage) < qRound(newCurrentCompletePercentage)) + qDebug("Something is wrong with the calculation of the progress."); m_currentCompletePercentage = newCurrentCompletePercentage; if (fraction == 1) { @@ -170,12 +188,13 @@ void ProgressCoordinator::partProgressChanged(double fraction) newCurrentCompletePercentage = 100; } - if (qRound(m_currentCompletePercentage) > qRound(newCurrentCompletePercentage)) { - qFatal("This should not happen!"); - } + // In normal mode, the progress has to go forward, new has to be larger than current + if (qRound(m_currentCompletePercentage) > qRound(newCurrentCompletePercentage)) + qDebug("Something is wrong with the calculation of the progress."); + m_currentCompletePercentage = newCurrentCompletePercentage; - if (fraction == 1 || fraction == 0) { + if (fraction == 1) { m_currentBasePercentage = m_currentBasePercentage + pendingCalculatedPartPercentage; m_senderPendingCalculatedPercentageHash.insert(sender(), 0); } else { |