-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
87 lines (69 loc) · 2.07 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
db = new DataBase();
if(db->checkingForRecord("admin")){
QVariantList data;
data.append("admin");
data.append("admin");
db->insertIntoMainTable(data);
data.clear();
}
this->setupMainModel(QStringList() << "ID" << "Логин" << "Пароль");
this->createUI();
loginWindow = new loginning();
connect(loginWindow, &loginning::showWindow, this, &MainWindow::show);
loginWindow->show();
userEdit = new UsersEdiditing();
connect(userEdit, &UsersEdiditing::showWindow, this, &MainWindow::show);
deleteUser = new deleteUserFromDB();
connect(deleteUser, &deleteUserFromDB::showWindow, this, &MainWindow::show);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setupMainModel(const QStringList &headers)
{
modelMain = new QSqlQueryModel(this);
modelMain->setQuery("SELECT * FROM " TABLE);
for(int i = 0, j = 0; i < modelMain->columnCount(); i++, j++){
modelMain->setHeaderData(i, Qt::Horizontal, headers[j]);
}
}
void MainWindow::createUI()
{
ui->tableView->setModel(modelMain);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableView->resizeColumnsToContents();
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->horizontalHeader()->setStretchLastSection(true);
}
void MainWindow::on_exitPushButton_clicked()
{
this->close();
}
void MainWindow::on_addNewUserPushButton_clicked()
{
userEdit->show();
}
void MainWindow::refreshWindow(){
this->close();
this->setupMainModel(QStringList() << "ID" << "Логин" << "Пароль");
this->createUI();
this->show();
}
void MainWindow::on_refreshPushButton_clicked()
{
this->refreshWindow();
}
void MainWindow::on_deletePushButton_clicked()
{
deleteUser->show();
}