Commit 0230fb8bbe22ffae72a2c144d36449ad559a6539
1 parent
dce20eb2
Exists in
master
Adicionado método de converter double para QString sem notação científica.
Showing
4 changed files
with
21 additions
and
1 deletions
Show diff stats
cacic-teste/testcacic.cpp
| @@ -243,6 +243,15 @@ void CTestCacic::testColetaSoftware() | @@ -243,6 +243,15 @@ void CTestCacic::testColetaSoftware() | ||
| 243 | QVERIFY(!OCacicSoftware.toJsonObject().empty()); | 243 | QVERIFY(!OCacicSoftware.toJsonObject().empty()); |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | +void CTestCacic::testConvertDouble() | ||
| 247 | +{ | ||
| 248 | + double number = 4.0905; | ||
| 249 | + | ||
| 250 | + QString converted = OCacic.convertDouble(number); | ||
| 251 | + | ||
| 252 | + QVERIFY(converted.toDouble() == number); | ||
| 253 | +} | ||
| 254 | + | ||
| 246 | void CTestCacic::cleanupTestCase() | 255 | void CTestCacic::cleanupTestCase() |
| 247 | { | 256 | { |
| 248 | OCacic.deleteFile("configRequest.json"); | 257 | OCacic.deleteFile("configRequest.json"); |
cacic-teste/testcacic.h
| @@ -70,6 +70,7 @@ private slots: | @@ -70,6 +70,7 @@ private slots: | ||
| 70 | void testRemoveRegistry(); | 70 | void testRemoveRegistry(); |
| 71 | void testIniciarDaemon(); | 71 | void testIniciarDaemon(); |
| 72 | void testColetaSoftware(); | 72 | void testColetaSoftware(); |
| 73 | + void testConvertDouble(); | ||
| 73 | void cleanupTestCase(); | 74 | void cleanupTestCase(); |
| 74 | }; | 75 | }; |
| 75 | 76 |
src/ccacic.cpp
| @@ -286,6 +286,14 @@ void CCacic::setChaveCrypt(const QString &value) | @@ -286,6 +286,14 @@ void CCacic::setChaveCrypt(const QString &value) | ||
| 286 | chaveCrypt = value; | 286 | chaveCrypt = value; |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | +QString CCacic::convertDouble(const double &number, const int &precision) | ||
| 290 | +{ | ||
| 291 | + std::ostringstream ss; | ||
| 292 | + ss.precision(precision); | ||
| 293 | + ss << std::fixed << number; | ||
| 294 | + | ||
| 295 | + return QString::fromStdString(ss.str()); | ||
| 296 | +} | ||
| 289 | 297 | ||
| 290 | /*Getters/Setters | 298 | /*Getters/Setters |
| 291 | * End. | 299 | * End. |
src/ccacic.h
| @@ -11,6 +11,8 @@ | @@ -11,6 +11,8 @@ | ||
| 11 | #include <QJsonDocument> | 11 | #include <QJsonDocument> |
| 12 | #include <QJsonObject> | 12 | #include <QJsonObject> |
| 13 | #include <QJsonValue> | 13 | #include <QJsonValue> |
| 14 | +#include <sstream> | ||
| 15 | +#include <iostream> | ||
| 14 | #include "../src/crypto++/include/aes.h" | 16 | #include "../src/crypto++/include/aes.h" |
| 15 | #include "../src/crypto++/include/base64.h" | 17 | #include "../src/crypto++/include/base64.h" |
| 16 | #include "../src/crypto++/include/modes.h" | 18 | #include "../src/crypto++/include/modes.h" |
| @@ -38,7 +40,7 @@ public: | @@ -38,7 +40,7 @@ public: | ||
| 38 | void setValueToRegistry(QString organization, QString application, QVariantMap values); | 40 | void setValueToRegistry(QString organization, QString application, QVariantMap values); |
| 39 | QVariant getValueFromRegistry(QString organization, QString application, QString key); | 41 | QVariant getValueFromRegistry(QString organization, QString application, QString key); |
| 40 | void removeRegistry(QString organization, QString application); | 42 | void removeRegistry(QString organization, QString application); |
| 41 | - | 43 | + QString convertDouble(const double &number, const int &precision = 10); |
| 42 | 44 | ||
| 43 | //Geters/seters: | 45 | //Geters/seters: |
| 44 | 46 |