Commit 0230fb8bbe22ffae72a2c144d36449ad559a6539

Authored by Thiago Rocha
1 parent dce20eb2
Exists in master

Adicionado método de converter double para QString sem notação científica.

cacic-teste/testcacic.cpp
... ... @@ -243,6 +243,15 @@ void CTestCacic::testColetaSoftware()
243 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 255 void CTestCacic::cleanupTestCase()
247 256 {
248 257 OCacic.deleteFile("configRequest.json");
... ...
cacic-teste/testcacic.h
... ... @@ -70,6 +70,7 @@ private slots:
70 70 void testRemoveRegistry();
71 71 void testIniciarDaemon();
72 72 void testColetaSoftware();
  73 + void testConvertDouble();
73 74 void cleanupTestCase();
74 75 };
75 76  
... ...
src/ccacic.cpp
... ... @@ -286,6 +286,14 @@ void CCacic::setChaveCrypt(const QString &value)
286 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 298 /*Getters/Setters
291 299 * End.
... ...
src/ccacic.h
... ... @@ -11,6 +11,8 @@
11 11 #include <QJsonDocument>
12 12 #include <QJsonObject>
13 13 #include <QJsonValue>
  14 +#include <sstream>
  15 +#include <iostream>
14 16 #include "../src/crypto++/include/aes.h"
15 17 #include "../src/crypto++/include/base64.h"
16 18 #include "../src/crypto++/include/modes.h"
... ... @@ -38,7 +40,7 @@ public:
38 40 void setValueToRegistry(QString organization, QString application, QVariantMap values);
39 41 QVariant getValueFromRegistry(QString organization, QString application, QString key);
40 42 void removeRegistry(QString organization, QString application);
41   -
  43 + QString convertDouble(const double &number, const int &precision = 10);
42 44  
43 45 //Geters/seters:
44 46  
... ...