Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
147 lines (128 loc) · 4.72 KB
/
Copy pathmainwindow.cpp
File metadata and controls
147 lines (128 loc) · 4.72 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFontDatabase>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
mod = new TableViewModel();
ui->tableView->setModel(mod);
connect(ui->resetDisplayButton, SIGNAL(clicked(bool)), this, SLOT(resetButtonHandler()));
connect(ui->shelfCaseWidget, &BookCase::addButtonClicked,this, &MainWindow::shelfCaseAddBtnWidget);
connect(ui->shelfBookWidget, &Book::addButtonClicked,this ,&MainWindow::shelfBookAddBtnWidget);
connect(ui->shelfCaseWidget, &BookCase::delButtonClicked,this ,&MainWindow::shelfCaseDelBtnWidget);
connect(ui->shelfBookWidget, &Book::delButtonClicked,this ,&MainWindow::shelfBookDelBtnWidget);
connect(mod,&TableViewModel::dataIsChanged,this,&MainWindow::delTableValue);
connect(ui->shelfBookWidget, &Book::addButtonClicked,this ,&MainWindow::InsertValue);
connect(ui->shelfCaseWidget, &BookCase::delButtonClicked,this ,&MainWindow::InsertValue);
connect(ui->shelfBookWidget, &Book::delButtonClicked,this ,&MainWindow::InsertValue);
setWindowStyle();
QFontDatabase::addApplicationFont(":/Fonts/ofont.ru_Raydis.ttf");
QFontDatabase::addApplicationFont(":/Fonts/ofont.ru_Plovdiv.ttf");
/*
* int id =
QString family = QFontDatabase::applicationFontFamilies(id).at(0); //имя шрифта
qDebug() << family;
*/
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::shelfCaseAddBtnWidget(int _num, QString _gen, uint _cap)
{
foreach(const auto &bookcase, lib.getArrCase())
{
if(bookcase->getCaseBookNumber()==_num)
{
QMessageBox::critical(this,"Ошибка","Шкаф с данным номером существует");
return 0;
}
}
lib.addCaseBook(new BookCase(_gen, _num, _cap));
return 0;
}
bool MainWindow::shelfCaseDelBtnWidget(int num)
{
uint counter = 0;
QString result;
foreach (const auto& bookcase, lib.getArrCase())
{
if(bookcase->getCaseBookNumber() == num)
{
result = lib.deleteCasebook(counter);
QMessageBox::warning(this,"Сообщение", result);
return 0;
}
counter++;
}
QMessageBox::critical(this,"Сообщение", "Данного шкафа не существует");
return 0;
}
bool MainWindow::shelfBookAddBtnWidget(QString name, QString auth, int quan, int number)
{
uint counter = 0;
foreach (const auto& bookcase, lib.getArrCase())
{
if(bookcase->getCaseBookNumber() == number)
{
if(lib.addBook(counter,new Book(name, auth , quan)))
{
QMessageBox::about(this,"Сообщение", "Книга добавлена в шкаф");
return 0;
}
else if (!(lib.addBook(counter,new Book(name, auth , quan))))
{
QMessageBox::critical(this,"Сообщение", "В данном шкафу недостаточно места");
return 0;
}
}
counter++;
}
QMessageBox::critical(this,"Сообщение", "Данного шкафа не существует");
return 0;
}
bool MainWindow::shelfBookDelBtnWidget(int number, QString name)
{
uint counter = 0;
QString res;
foreach (const auto& bookcase, lib.getArrCase())
{
if(bookcase->getCaseBookNumber() == number)
{
res = lib.deleteBook(name, counter);
QMessageBox::warning(this,"Сообщение", res);
return 0;
}
counter++;
}
QMessageBox::critical(this,"Сообщение", "Данного шкафа не существует");
return 0;
}
void MainWindow::resetButtonHandler()
{
int readCaseNumber = ui->numberCaseBox->value();
ui->displayLabel->setText(lib.displayBooksOfCase(readCaseNumber));
}
void MainWindow::delTableValue(QString &name, int &num)
{
lib.delBookFromTable(name,num);
InsertValue();
}
//________________________________________________
void MainWindow::InsertValue()
{
mod->setLibrary(lib.getArrCase());
}
//----------------------------
void MainWindow::setWindowStyle()
{
//ui->shelfBookWidget->setStyleSheet(StyleAssist::getCaseBookStyle());
ui->tabWidget->setStyleSheet(StyleAssist::getButtonStyle());
this->setStyleSheet(StyleAssist::getLineEditStyle());
ui->tabWidget->setStyleSheet("font-family: 'RAYDIS'; font-size:8px;");
//ui->tabWidget->setStyleSheet(StyleAssist::getMainWindowStyle());
}