intermediate checkin
This commit is contained in:
committed by
Aditya Kulkarni
parent
e82ec11520
commit
ed85a4c1e9
@@ -1,5 +1,7 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "turnstile.h"
|
||||||
|
|
||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -16,6 +18,8 @@ int main(int argc, char *argv[])
|
|||||||
qApp->setFont(QFont("Ubuntu", 11, QFont::Normal, false));
|
qApp->setFont(QFont("Ubuntu", 11, QFont::Normal, false));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::srand(std::time(nullptr));
|
||||||
|
|
||||||
QCoreApplication::setOrganizationName("zec-qt-wallet-org");
|
QCoreApplication::setOrganizationName("zec-qt-wallet-org");
|
||||||
QCoreApplication::setApplicationName("zec-qt-wallet");
|
QCoreApplication::setApplicationName("zec-qt-wallet");
|
||||||
|
|
||||||
@@ -25,5 +29,9 @@ int main(int argc, char *argv[])
|
|||||||
w.setWindowTitle("zec-qt-wallet v" + QString(APP_VERSION));
|
w.setWindowTitle("zec-qt-wallet v" + QString(APP_VERSION));
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
|
// Temp
|
||||||
|
Turnstile t;
|
||||||
|
qDebug() << t.splitAmount(1245.2294371, 3);
|
||||||
|
|
||||||
return QApplication::exec();
|
return QApplication::exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
/* Add C++ includes here */
|
/* Add C++ includes here */
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
|||||||
37
src/turnstile.cpp
Normal file
37
src/turnstile.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "precompiled.h"
|
||||||
|
#include "turnstile.h"
|
||||||
|
|
||||||
|
|
||||||
|
Turnstile::Turnstile() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Turnstile::~Turnstile() {
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QString> Turnstile::splitAmount(double amount, int parts) {
|
||||||
|
QList<QString> amounts;
|
||||||
|
fillAmounts(amounts, amount, parts);
|
||||||
|
|
||||||
|
// Ensure they all add up!
|
||||||
|
double sumofparts = 0;
|
||||||
|
for (auto a : amounts) {
|
||||||
|
sumofparts += a.toDouble();
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_ASSERT(sumofparts == amount);
|
||||||
|
return amounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Turnstile::fillAmounts(QList<QString>& amounts, double amount, int count) {
|
||||||
|
if (count == 1 || amount < 1) {
|
||||||
|
amounts.push_back(QString::number(amount, 'g', 8));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a random amount off the amount and call recursively.
|
||||||
|
auto curAmount = std::rand() % (int)std::floor(amount);
|
||||||
|
amounts.push_back(QString::number(curAmount, 'g', 8));
|
||||||
|
|
||||||
|
fillAmounts(amounts, amount - curAmount, count - 1);
|
||||||
|
}
|
||||||
11
src/turnstile.h
Normal file
11
src/turnstile.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
class Turnstile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Turnstile();
|
||||||
|
~Turnstile();
|
||||||
|
|
||||||
|
QList<QString> Turnstile::splitAmount(double amount, int parts);
|
||||||
|
void fillAmounts(QList<QString>& amounts, double amount, int count);
|
||||||
|
};
|
||||||
|
|
||||||
@@ -50,6 +50,7 @@ SOURCES += \
|
|||||||
src/sendtab.cpp \
|
src/sendtab.cpp \
|
||||||
src/senttxstore.cpp \
|
src/senttxstore.cpp \
|
||||||
src/txtablemodel.cpp \
|
src/txtablemodel.cpp \
|
||||||
|
src/turnstile.cpp \
|
||||||
src/utils.cpp
|
src/utils.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
@@ -65,6 +66,7 @@ HEADERS += \
|
|||||||
src/settings.h \
|
src/settings.h \
|
||||||
src/txtablemodel.h \
|
src/txtablemodel.h \
|
||||||
src/senttxstore.h \
|
src/senttxstore.h \
|
||||||
|
src/turnstile.h \
|
||||||
src/utils.h
|
src/utils.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
|||||||
Reference in New Issue
Block a user