-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
128 lines (103 loc) · 4.42 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDir>
#include <QFileInfoList>
#include <QFileInfo>
#include <QDebug>
#include <QVector>
#include <QString>
#include <QFileDialog>
#include "tableworker.h"
#include "utils.h"
MainWindow::MainWindow(ConfigWorker * cfg, QWidget * parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, cfgWorker(cfg)
{
ui->setupUi(this);
connect(ui->countryList, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCountryList(int)));
connect(ui->leaguesList, SIGNAL(currentIndexChanged(int)), this, SLOT(changeLeaguesList(int)));
connect(ui->cmdList, SIGNAL(clicked(QModelIndex)), this, SLOT(changeStateCBoxCmd(QModelIndex)));
connect(ui->AnalizeBtn, SIGNAL(clicked()), this, SLOT(clickedAnalize()));
connect(ui->genTableBtn, SIGNAL(clicked()), this, SIGNAL(showGenTableWindow()));
connect(ui->menuSettings, SIGNAL(aboutToShow()), this, SIGNAL(showSettingsWindow()));
connect(ui->chooseAllCBox, SIGNAL(stateChanged(int)), this, SLOT(chooseAllCBoxCmd()));
connect(ui->LoadOldResultBtn, SIGNAL(clicked()), this, SLOT(clickLoadOldResults()));
connect(ui->UncheckAllBtn, SIGNAL(clicked()), this, SLOT(uncheckAll()));
ui->goalsAnalizeCBox->setCheckState(Qt::Checked);
ui->leaguesList->setEnabled(false);
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::init() {
ui->countryList->addItem(" ");
ui->countryList->addItems(cfgWorker->getContries());
}
void MainWindow::clickedAnalize() {
QVector<Criterions> vcrt;
if (ui->goalsAnalizeCBox->checkState() == Qt::Checked) {
vcrt.push_back(Criterions::GOAL_FIRTS_TIME);
vcrt.push_back(Criterions::GOAL_SECOND_TIME);
vcrt.push_back(Criterions::GOAL_IN_3_TIMES);
}
//ui->percentEdit->setEnabled(false);
emit startAnalize(vcrt);
}
void MainWindow::changeCountryList(int index) {
if (ui->countryList->currentText() == " ") {
//ui->AnalizeBtn->setEnabled(false);
return;
}
ui->leaguesList->setEnabled(true);
ui->leaguesList->clear();
ui->leaguesList->addItem(" ");
ui->leaguesList->addItems(cfgWorker->getLeagues(ui->countryList->currentText()));
}
void MainWindow::changeLeaguesList(int index) {
if ( ui->leaguesList->currentText() == " ") {
//ui->AnalizeBtn->setEnabled(false);
return;
}
ui->cmdList->clear();
ui->AnalizeBtn->setEnabled(true);
QListWidgetItem * lwi = nullptr;
QVector<CMDState> cmds = cfgWorker->getCmds(ui->countryList->currentText(), ui->leaguesList->currentText());
int flag = 0;
foreach (CMDState cmd, cmds) {
lwi = new QListWidgetItem(cmd.cmd.name, ui->cmdList);
lwi->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
lwi->setCheckState(cmd.checked ? Qt::Checked : Qt::Unchecked);
if (cmd.checked)
flag++;
}
if (flag == cmds.size())
ui->chooseAllCBox->setCheckState(Qt::Checked);
else
ui->chooseAllCBox->setCheckState(Qt::Unchecked);
}
void MainWindow::changeStateCBoxCmd(QModelIndex index) {
QListWidgetItem * lwi = ui->cmdList->item(index.row());
lwi->setCheckState(lwi->checkState() ? Qt::Unchecked : Qt::Checked);
cfgWorker->changeCmdState(ui->countryList->currentText(), ui->leaguesList->currentText(), lwi->text(), lwi->checkState());
}
void MainWindow::chooseAllCBoxCmd() {
for (int i = 0; i < ui->cmdList->count(); ++i) {
QListWidgetItem * lwi = ui->cmdList->item(i);
lwi->setCheckState(ui->chooseAllCBox->checkState() ? Qt::Checked : Qt::Unchecked);
}
cfgWorker->changeLigaState(ui->countryList->currentText(), ui->leaguesList->currentText(), ui->chooseAllCBox->checkState() ? 1 : 0);
}
void MainWindow::clickLoadOldResults() {
QString path = QFileDialog::getOpenFileName(0,QObject::tr("Укажите файл базы данных"),ANALIZE_RESULT_DIR, QObject::tr("Файл SQLite (*." ANALIZE_RESULT_FILE_FORMAT ")"));
QList<ResAnalize> res = cfgWorker->loadAnalizeResults(path);
emit showSavedResults(res);
}
void MainWindow::uncheckAll() {
for (int i = 0; i < ui->cmdList->count(); ++i) {
QListWidgetItem * lwi = ui->cmdList->item(i);
lwi->setCheckState(Qt::Unchecked);
}
ui->chooseAllCBox->setCheckState(Qt::Unchecked);
cfgWorker->changeAllCmdsState(0);
}