From d54c6743e7c2c0fe4313586d138a4682b672fb01 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Wed, 26 Feb 2025 16:21:33 +0100 Subject: [PATCH] Return progress as double, not int --- qml/Main.qml | 2 +- src/FactorizationController.cpp | 6 +++--- src/FactorizationController.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/qml/Main.qml b/qml/Main.qml index c8dc9a6..389f9fe 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -151,7 +151,7 @@ ApplicationWindow { } Text { - text: factorizationController.progress.toFixed(0) + "%" + text: factorizationController.progress.toFixed(1) + "%" anchors.centerIn: parent font.pixelSize: 16 color: "black" diff --git a/src/FactorizationController.cpp b/src/FactorizationController.cpp index 96e9cfb..1300f19 100644 --- a/src/FactorizationController.cpp +++ b/src/FactorizationController.cpp @@ -16,7 +16,7 @@ unsigned long long FactorizationController::curFactNumber() const { return m_currentFactNumber; } -int FactorizationController::progress() const { +double FactorizationController::progress() const { // If the original number is set to 0, the computation wasn't yet initialized / was reset. // If the current factor is at 2, the computation has just started, return early to avoid // zero division issues. @@ -32,8 +32,8 @@ int FactorizationController::progress() const { // since factor being <= 2 means 100%, we sub 2 here. double progress = static_cast(m_currentFactor - 2) / static_cast(m_stopFactor - 2); - // Return the value as int percentage - return static_cast(std::clamp(progress * 100, 0.0, 100.0)); + // Return the value as percentage + return std::clamp(progress * 100, 0.0, 100.0); } bool FactorizationController::isFinished() const { diff --git a/src/FactorizationController.h b/src/FactorizationController.h index f9d5171..a2f3835 100644 --- a/src/FactorizationController.h +++ b/src/FactorizationController.h @@ -31,7 +31,7 @@ class FactorizationController : public QObject { Q_PROPERTY(unsigned long long curFactNumber READ curFactNumber NOTIFY curFactNumberChanged) Q_PROPERTY(unsigned long long currentFactor READ currentFactor NOTIFY currentFactorChanged) Q_PROPERTY(unsigned long long stopFactor READ stopFactor NOTIFY stopFactorChanged) - Q_PROPERTY(int progress READ progress NOTIFY progressChanged) + Q_PROPERTY(double progress READ progress NOTIFY progressChanged) Q_PROPERTY(QList factors READ factors NOTIFY factorsChanged) public: @@ -43,7 +43,7 @@ class FactorizationController : public QObject { * @brief Gets the current progress of factorization. * @return The progress percentage (0-100). */ - int progress() const; + double progress() const; /** * @brief Checks if the factorization process is running.