Fix resetting logc & progress bar

This commit is contained in:
ItsDrike 2025-02-26 14:58:24 +01:00
parent c58697b126
commit 12caef0a51
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0

View file

@ -3,7 +3,7 @@
#include <cmath> #include <cmath>
FactorizationController::FactorizationController(QObject* parent) : FactorizationController::FactorizationController(QObject* parent) :
QObject{parent}, m_isRunning(false), m_useSqrtOptimization(true), m_iterationsPerCycle(1), m_currentFactNumber(0), m_currentFactor(0), m_stopFactor(0) { QObject{parent}, m_isRunning(false), m_useSqrtOptimization(true), m_iterationsPerCycle(1), m_currentFactNumber(0), m_originalNumber(0), m_currentFactor(0), m_stopFactor(0) {
assert(connect(&m_timer, &QTimer::timeout, this, &FactorizationController::onTimerTick)); assert(connect(&m_timer, &QTimer::timeout, this, &FactorizationController::onTimerTick));
} }
@ -16,6 +16,10 @@ long long FactorizationController::curFactNumber() const {
} }
int FactorizationController::progress() const { int FactorizationController::progress() const {
// If the original number is set to 0, the computation wasn't yet initialized / was reset.
if (m_originalNumber == 0)
return 0;
// If current factor is at or below 2 already, we must be done, // If current factor is at or below 2 already, we must be done,
// stopFactor can never be less than 2, that makes no sense. // stopFactor can never be less than 2, that makes no sense.
if (m_currentFactNumber == 1 || m_currentFactor <= 2 || m_currentFactor > m_stopFactor) if (m_currentFactNumber == 1 || m_currentFactor <= 2 || m_currentFactor > m_stopFactor)
@ -138,13 +142,17 @@ void FactorizationController::reset() {
return; return;
m_isPaused = false; m_isPaused = false;
m_currentFactNumber = m_originalNumber; m_originalNumber = 0;
m_currentFactor = 2; m_currentFactNumber = 0;
m_currentFactor = 0;
m_stopFactor = 0;
m_factors.clear(); m_factors.clear();
emit isPausedChanged(); emit isPausedChanged();
emit currentFactorChanged(); emit currentFactorChanged();
emit progressChanged(); emit curFactNumberChanged();
emit factorsChanged(); emit factorsChanged();
emit stopFactorChanged();
emit progressChanged();
} }
void FactorizationController::onTimerTick() { void FactorizationController::onTimerTick() {