-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
156 lines (121 loc) · 5.91 KB
/
mainwindow.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
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->countryComboBox->addItem("Czech Republic");
ui->countryComboBox->addItem("Slovakia");
ui->countryComboBox->addItem("Germany");
ui->countryComboBox->addItem("Poland");
ui->currencyComboBox->addItem("USD");
ui->currencyComboBox->addItem("CZK");
ui->currencyComboBox->addItem("EUR");
ui->currencyComboBox->addItem("PLN");
ui->filterOptions->addItem("From the cheapest to the most expensive");
ui->filterOptions->addItem("From the most expensive to the cheapest");
ui->filterOptions->addItem("A->Z");
ui->filterOptions->addItem("Z->A");
ui->platformOptions->addItem("All");
ui->platformOptions->addItem("PC Steam");
ui->platformOptions->addItem("PC Origin");
ui->platformOptions->addItem("Xbox Series X");
ui->platformOptions->addItem("Xbox One");
ui->platformOptions->addItem("Playstation 5");
ui->platformOptions->addItem("Playstation 4");
ui->categoryOptions->addItem("All");
ui->categoryOptions->addItem("RPG");
ui->categoryOptions->addItem("Strategy");
ui->categoryOptions->addItem("Racing");
ui->categoryOptions->addItem("Shooter");
ui->categoryOptions->addItem("Open World");
this->paymentMethodsModel = new QStandardItemModel(0, 3);
this->paymentMethodsModel->setHorizontalHeaderItem(0, new QStandardItem("Card name"));
this->paymentMethodsModel->setHorizontalHeaderItem(1, new QStandardItem("Card number"));
this->paymentMethodsModel->setHorizontalHeaderItem(2, new QStandardItem("Expiration date"));
this->ui->paymentMethodsTableView->setModel(this->paymentMethodsModel);
this->gameItemModel = new QStandardItemModel(0, 6);
this->gameItemModel->setHorizontalHeaderItem(0, new QStandardItem(""));
this->gameItemModel->setHorizontalHeaderItem(1, new QStandardItem("Name"));
this->gameItemModel->setHorizontalHeaderItem(2, new QStandardItem("Description"));
this->gameItemModel->setHorizontalHeaderItem(3, new QStandardItem("Platform"));
this->gameItemModel->setHorizontalHeaderItem(4, new QStandardItem("Category"));
this->gameItemModel->setHorizontalHeaderItem(5, new QStandardItem("Price"));
QList <QStandardItem*> gta5(6);
QList <QStandardItem*> hoi4(6);
QImage image(":/images/game_icon.png");
QStandardItem* gta5ImageItem = new QStandardItem();
QStandardItem* hoi4ImageItem = new QStandardItem();
gta5ImageItem->setData(QVariant(QPixmap::fromImage(image).scaled(100, 50)), Qt::DecorationRole);
hoi4ImageItem->setData(QVariant(QPixmap::fromImage(image).scaled(100, 50)), Qt::DecorationRole);
gta5 = {gta5ImageItem, new QStandardItem("Grand Theft Auto V"),
new QStandardItem("Grand Theft Auto V -- open world game in a huge and detalized world"),
new QStandardItem("PC Steam"), new QStandardItem("Open World"), new QStandardItem("59")};
hoi4 = {hoi4ImageItem, new QStandardItem("Hearts of Iron IV"),
new QStandardItem("Hearts of Iron IV -- strategy about WW2"),
new QStandardItem("PC Steam"), new QStandardItem("Strategy"), new QStandardItem("19")};
this->games.push_back(gta5);
this->games.push_back(hoi4);
this->ui->gameTableView->setModel(this->gameItemModel);
this->ui->gameTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
this->ui->paymentMethodsTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
connect(this->ui->addPaymentButton, SIGNAL(clicked(bool)), this, SLOT(showCardWindow()));
connect(this->ui->logo, SIGNAL(clicked(bool)), this, SLOT(showStorePage()));
connect(this->ui->myProfileButton, SIGNAL(clicked(bool)), this, SLOT(showProfilePage()));
connect(this->ui->searchButton, SIGNAL(clicked(bool)), this, SLOT(searchResult()));
this->showStorePage();
}
MainWindow::~MainWindow()
{
delete ui;
delete paymentMethodsModel;
delete gameItemModel;
}
void MainWindow::showCardWindow()
{
CardDialog* cardDialog = new CardDialog();
cardDialog->setWindowModality(Qt::ApplicationModal);
connect(cardDialog, SIGNAL(cardCreated(Card)), this, SLOT(addCardToTable(Card)));
cardDialog->show();
}
void MainWindow::addCardToTable(Card card)
{
QList<QStandardItem*> item(3);
item = {new QStandardItem(card.name.c_str()), new QStandardItem(std::to_string(card.number).c_str()), new QStandardItem((std::to_string(card.month) + "/" + std::to_string(card.year)).c_str())};
this->paymentMethodsModel->appendRow(item);
}
void MainWindow::showProfilePage()
{
this->ui->stackedWidget->setCurrentIndex(0);
}
void MainWindow::showStorePage()
{
qInfo("Row counts before delete: %d", this->gameItemModel->rowCount());
int rowCount = this->gameItemModel->rowCount();
for(int i = 0; i < rowCount; i++){
this->gameItemModel->takeRow(0);
}
qInfo("Row counts after delete: %d", this->gameItemModel->rowCount());
for(unsigned int i = 0; i < this->games.size(); i++){
this->gameItemModel->appendRow(this->games[i]);
}
qInfo("Row counts after append: %d", this->gameItemModel->rowCount());
this->ui->stackedWidget->setCurrentIndex(1);
}
void MainWindow::searchResult()
{
qInfo("Row counts before delete: %d", this->gameItemModel->rowCount());
int rowCount = this->gameItemModel->rowCount();
for(int i = 0; i < rowCount; i++){
this->gameItemModel->takeRow(0);
}
qInfo("Row counts after delete: %d", this->gameItemModel->rowCount());
for(unsigned int i = 0; i < this->games.size(); i++){
if(games[i][1]->text().toStdString().find(this->ui->searchLineEdit->text().toStdString()) != std::string::npos){
this->gameItemModel->appendRow(this->games[i]);
}
}
qInfo("Row counts after append: %d", this->gameItemModel->rowCount());
this->ui->stackedWidget->setCurrentIndex(1);
}