-
Notifications
You must be signed in to change notification settings - Fork 0
/
BudgetWidget.cpp
77 lines (60 loc) · 2.3 KB
/
BudgetWidget.cpp
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
#include "BudgetWidget.h"
#include "ui_BudgetWidget.h"
#include "BudgetDataModel.h"
#include "UserExpensesModel.h"
BudgetWidget::BudgetWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::BudgetWidget)
{
ui->setupUi(this);
// No selecting
ui->tableView_annual->setSelectionBehavior(QAbstractItemView::SelectionBehavior());
ui->tableView_annual->setDragDropMode(QAbstractItemView::NoDragDrop);
ui->tableView_annual->resizeColumnsToContents();
ui->tableView_annual->horizontalHeader()->hide();
ui->tableView_needs->setCornerButtonEnabled(false);
ui->tableView_needs->verticalHeader()->hide();
ui->tableView_wants->setCornerButtonEnabled(false);
ui->tableView_wants->verticalHeader()->hide();
// Setup percent Needs combobox
for(int i = 100; i >= 0; i = i - 5)
{
ui->comboBox_percentForNeeds->addItem(QString::number(i) + '%');
}
connect(ui->comboBox_percentForNeeds, &QComboBox::currentIndexChanged,
this, &BudgetWidget::slot_onBudgetModelUpdated);
ui->comboBox_percentForNeeds->setCurrentIndex(ui->comboBox_percentForNeeds->count() * 0.25f);
}
BudgetWidget::~BudgetWidget()
{
delete ui;
}
void BudgetWidget::setBudgetModel(BudgetDataModel *model)
{
ui->tableView_annual->setModel(model);
connect(model, &BudgetDataModel::dataChanged,
this, &BudgetWidget::slot_onBudgetModelUpdated);
m_pBudgetModel = model;
}
void BudgetWidget::setNeedsModel(UserExpensesModel *model)
{
ui->tableView_needs->setModel(model);
}
void BudgetWidget::setWantsModel(UserExpensesModel *model)
{
ui->tableView_wants->setModel(model);
}
void BudgetWidget::slot_onBudgetModelUpdated()
{
slot_updateMonthlyWantsNeeds();
}
void BudgetWidget::slot_updateMonthlyWantsNeeds()
{
if(m_pBudgetModel != nullptr)
{
float percentForWants = (100.0f - (ui->comboBox_percentForNeeds->currentText()).remove('%').toFloat()) / 100.0f;
ui->lineEdit_percentForWants->setText(QString::number(percentForWants * 100.0f) + '%');
ui->lineEdit_needsPerMonth->setText(QString::number(ui->comboBox_percentForNeeds->currentText().remove('%').toFloat() / 100.0f * m_pBudgetModel->getMonthlyTakeHome()));
ui->lineEdit_wantsPerMonth->setText(QString::number(percentForWants * m_pBudgetModel->getMonthlyTakeHome()));
}
}