-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
168 lines (146 loc) · 5.88 KB
/
mainwindow.cpp
File metadata and controls
168 lines (146 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "QDebug"
#include "QMessageBox"
#include "classes/account.h" //
#include "financegraph.h"
#include "graphviewer.h"
#include "setbudget.h"
#include <iostream>
Account transportation;
Account food;
Account other;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QDoubleValidator *doubleValidator = new QDoubleValidator(-999999.0, 999999.0, 2, this);
ui->enterTransactionLineEdit->setValidator(doubleValidator);
ui->enterTransactionLabel->setVisible(false);
ui->enterTransactionLineEdit->setVisible(false);
ui->dateTimeLabel->setVisible(false);
ui->dateTimeEdit->setVisible(false);
ui->accountLabel->setVisible(false);
ui->accountComboBox->setVisible(false);
ui->addButton->setVisible(false);
connect(ui->addButton, &QPushButton::clicked, this, &MainWindow::submitData);
connect(ui->openDialogBtn, &QPushButton::clicked, this, &MainWindow::openDialog);
connect(ui->visualizeBtn, &QPushButton::clicked, this, &MainWindow::openGraphViewer);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::openGraphViewer()
{
GraphViewer graphs(this);
graphs.sendAccounts(food, transportation, other);
graphs.exec();
}
void MainWindow::openDialog()
{
SetBudget dialog(this); // Create the dialog instance
if (dialog.exec() == QDialog::Accepted) { // Wait for user interaction and check result
float text = dialog.getLineEditText().toFloat(); // Retrieve the text from the LineEdit
QString budgetAmt = QString::asprintf("%.2f", text);
ui->budgetAmountTotal->setText("$" + budgetAmt);
int radioMode = dialog.getRadioMode();
cout << "AHHHH" << radioMode << endl;
food.SetStartingBalance((dialog.getPercentages(radioMode)[0].toDouble() / 100) * text);
transportation.SetStartingBalance((dialog.getPercentages(radioMode)[1].toDouble() / 100)
* text);
other.SetStartingBalance((dialog.getPercentages(radioMode)[2].toDouble() / 100) * text);
}
}
void MainWindow::on_pushButton_clicked()
{
ui->enterTransactionLabel->setVisible(true);
ui->enterTransactionLineEdit->setVisible(true);
ui->dateTimeLabel->setVisible(true);
ui->dateTimeEdit->setVisible(true);
ui->accountLabel->setVisible(true);
ui->accountComboBox->setVisible(true);
ui->addButton->setVisible(true);
ui->pushButton->setVisible(false);
}
void MainWindow::submitData()
{
float floatTrans = ui->enterTransactionLineEdit->text().toFloat();
QString transaction = QString::asprintf("%.2f", floatTrans);
QString date_and_time = ui->dateTimeEdit->text();
QString account = ui->accountComboBox->currentText();
if (account == "Food") {
food.SetTransaction(transaction.toDouble());
ui->foodList->addItem("$" + transaction + ", " + date_and_time);
food.SetAvgTrans();
Box(transaction.toDouble(), food);
} else if (account == "Transportation") {
transportation.SetTransaction(transaction.toDouble());
ui->transList->addItem("$" + transaction + ", " + date_and_time);
transportation.SetAvgTrans();
Box(transaction.toDouble(), transportation);
} else {
other.SetTransaction(transaction.toDouble());
ui->otherList->addItem("$" + transaction + ", " + date_and_time);
other.SetAvgTrans();
Box(transaction.toDouble(), other);
}
QString text = ui->budgetAmountTotal->text();
if (text.startsWith('$')) {
text.remove(0, 1);
}
double bdgtAmt = text.toDouble();
float sum = 0.0;
for (float value : food.GetTransactions()) {
sum += value;
}
for (float value : transportation.GetTransactions()) {
sum += value;
}
for (float value : other.GetTransactions()) {
sum += value;
}
bdgtAmt -= sum;
QString str = QString::number(bdgtAmt, 'f', 2);
ui->totalAmtLabel->setText("Total Left:" + str);
ui->enterTransactionLabel->setVisible(false);
ui->enterTransactionLineEdit->setVisible(false);
ui->dateTimeLabel->setVisible(false);
ui->dateTimeEdit->setVisible(false);
ui->accountLabel->setVisible(false);
ui->accountComboBox->setVisible(false);
ui->addButton->setVisible(false);
ui->pushButton->setVisible(true);
}
void MainWindow::Box(double transaction, Account acc)
{
cout << acc.GetTransactionSum() << endl << acc.GetStartingBalance() << endl;
if (acc.GetTransactionSum() >= acc.GetStartingBalance()) {
QMessageBox::information(this,
"Maybe its time to stop..",
"You have exceeded the limit for this account!",
QMessageBox::Warning);
} else if (transaction > 2 * acc.GetAvgTrans()) {
QMessageBox::information(this,
"Watch your spending!",
"You're Spending more than double your average!",
QMessageBox::Warning);
} else if (transaction > 1.5 * acc.GetAvgTrans()) {
QMessageBox::information(this,
"Watch your spending!",
"You're Spending slightly over your average, be careful!",
QMessageBox::Warning);
} else if (transaction < acc.GetAvgTrans() / 2) {
QMessageBox::information(
this,
"Nice one!",
"You have spent less than half of your average, we will hold you to this!",
QMessageBox::Ok);
} else if (transaction < acc.GetAvgTrans()) {
QMessageBox::information(this,
"Nice one!",
"You spent less than your average, Keep it up!",
QMessageBox::Ok);
}
}