-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
361 lines (287 loc) · 10.3 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include <QtGui>
#include "mainwindow.h"
MF::MF(QSplashScreen *psplash, QWidget *parent) : QMainWindow(parent),settings("NNCSM","Journal")
{
//load settings
setupUi(this);
plf = new LF;
pdst = new dSt(this);
settings.beginGroup("/Settings");
Path = settings.value("/Path","./").toString();
splash = settings.value("/Splash",true).toBool();
font.fromString(settings.value("/Font",font.toString()).toString());
settings.endGroup();
main_tblv->setFont(font);
change_tblv->setFont(font);
pdst->set_Pash(&Path);
pdst->set_splash(&splash);
if(splash) psplash->show();
ldb = QSqlDatabase::database();
ldb.setDatabaseName(Path + "/db.sqlite");
if(!ldb.open())
{
this->close();
}
QTime time;
time.start();
for(int i = 0; i < 100;)
{
if (time.elapsed() > 40)
{
time.start();
++i;
}
psplash->showMessage(tr("Loading modules:") + QString::number(i) + "%",
Qt::AlignCenter | Qt::AlignBottom , Qt::white);
}
//Login
psplash->finish(plf);
plf->show();
//Login End
this->move(QApplication::desktop()->availableGeometry().center() - this->rect().center());
sqtmodel.setTable("main");
sqtmodel.select();
sqtmodel.setHeaderData(1,Qt::Horizontal,QObject::tr("id"));
sqtmodel.setHeaderData(2,Qt::Horizontal,QObject::tr("Date"));
sqtmodel.setHeaderData(3,Qt::Horizontal,QObject::tr("Reg_Num"));
sqtmodel.setHeaderData(4,Qt::Horizontal,QObject::tr("Obozn_Tu"));
sqtmodel.setHeaderData(5,Qt::Horizontal,QObject::tr("Naim_Tu"));
sqtmodel.setHeaderData(6,Qt::Horizontal,QObject::tr("Razrab_Tu"));
sqtmodel.setHeaderData(8,Qt::Horizontal,QObject::tr("Prim"));
main_tblv->setModel(&sqtmodel); // model for main
sqqmodel.setTable("change");
sqqmodel.setHeaderData(1,Qt::Horizontal,QObject::tr("date"));
sqqmodel.setHeaderData(2,Qt::Horizontal,QObject::tr("number"));
change_tblv->setModel(&sqqmodel); // model for changes
//proxy model for search
prxmod.setSourceModel(&sqtmodel); //model fo search
prxmod.setFilterKeyColumn(-1); //search for all 0 for 1
//delete unuse row
main_tblv->hideColumn(0);
main_tblv->hideColumn(7);
main_tblv->hideColumn(9);
change_tblv->hideColumn(0);
change_tblv->hideColumn(3);
change_tblv->hideColumn(4);
change_tblv->hideColumn(5);
//end.
main_tblv->setModel(&prxmod); //install proxy model
main_tblv->resizeRowsToContents();
main_tblv->resizeColumnsToContents();
// form
padduser = new admf();
pmAdd = new mAdd();
pchf = new addChForm();
//conections
////////////////////////////////////adm form
QObject::connect(padduser,SIGNAL(signal_close()),this,SLOT(close())); // call destructor
//end adm form
//////////////////////////////////login form
QObject::connect(plf,SIGNAL(signal_admin()),padduser,SLOT(show())); // if admin login show user add form
QObject::connect(plf,SIGNAL(signal_user()),this,SLOT(show())); // if user login show main form
QObject::connect(plf,SIGNAL(signal_close()),this,SLOT(close())); //call destruktor
//end login form
////////////////////////////////add main form
QObject::connect(pmAdd,SIGNAL(signal_hidForm()),this,SLOT(slot_en_main())); // enable form refresh main_tblv
//end add main form
//////////////////////////////add ch form
QObject::connect(pchf,SIGNAL(signal_hidForm()),this,SLOT(slot_en_main())); // enable main form
//end add ch form
//////////////////////////////main form
QObject::connect(main_tblv,SIGNAL(clicked(const QModelIndex&)),this,SLOT(slot_change_case(const QModelIndex&))); // case change
//search
QObject::connect(bSearch,SIGNAL(clicked()),this,SLOT(slot_search())); // search
//add main
QObject::connect(b_add,SIGNAL(clicked()),this,SLOT(slot_add())); // Call slot that transmits a signal form to be added.
QObject::connect(this,SIGNAL(signal_clicked_add()),pmAdd,SLOT(slot_add())); //method call form to add
//edit main
QObject::connect(b_edit,SIGNAL(clicked()),this,SLOT(slot_edit_main())); // edit button
QObject::connect(this,SIGNAL(signal_clicked_edit(const QModelIndex&)),pmAdd,SLOT(slot_changes(const QModelIndex&))); // method call from to change
// del main
QObject::connect(b_delete,SIGNAL(clicked()),this,SLOT(slot_delete())); //delete button call slot for emit signals
QObject::connect(this,SIGNAL(signal_clicked_delete(const QModelIndex&)),this,SLOT(slot_delete_main(const QModelIndex&))); // remove row from main_tblv
//add ch
QObject::connect(b_addChange,SIGNAL(clicked()),this,SLOT(slot_ch_add()));// generate signal for add ch
QObject::connect(this,SIGNAL(signal_clicked_ch_add(const QModelIndex&)),pchf,SLOT(slot_add(const QModelIndex&))); //add change
// edit ch
QObject::connect(b_editChanges,SIGNAL(clicked()),this,SLOT(slot_ch_changes())); //generate signal for ed ch
QObject::connect(this,SIGNAL(signal_clicked_ch_chenges(const QModelIndex&)),pchf,SLOT(slot_edit(const QModelIndex&))); // call edit changes
//del ch
QObject::connect(b_deleteChanges,SIGNAL(clicked()),this,SLOT(slot_ch_delete())); //generate signal for delete ch
QObject::connect(this,SIGNAL(signal_clicked_ch_delete(const QModelIndex&)),this,SLOT(slot_delete_change(const QModelIndex&))); //delete ch
//end main form
//connect menu
QObject::connect(actionQuit,SIGNAL(triggered()),this,SLOT(close())); // quit
QObject::connect(action_Font,SIGNAL(triggered()),this,SLOT(slot_set_font())); // Set Font
QObject::connect(action_Main_Settings,SIGNAL(triggered()),this,SLOT(slot_settings())); //settings
QObject::connect(action_About_Developer,SIGNAL(triggered()),this,SLOT(slot_about())); //about
QObject::connect(action_About_QT,SIGNAL(triggered()),this,SLOT(slot_aboutQt())); //aboutQt
QObject::connect(action_Help,SIGNAL(triggered()),this,SLOT(slot_help())); // about programm
//end connect menu
/////////////////////////connection for save settings
}
void MF::slot_change_case(const QModelIndex & id)
{
QModelIndex ind = sqtmodel.index(id.row(),0,QModelIndex());
QVariant value = sqtmodel.data(ind);
QString str_query = "id = %1";
str_query = str_query.arg(value.toInt());
sqqmodel.setFilter(str_query);
sqqmodel.select();
if (sqqmodel.lastError().isValid())
{
qDebug() << sqqmodel.lastError();
}
change_tblv->resizeRowsToContents();
}
void MF::slot_search()
{
QString strSearch = shlv->text();
this->prxmod.setFilterWildcard(strSearch);
}
void MF::slot_ch_add()
{
const QModelIndex mind = main_tblv->currentIndex();
if(mind.isValid())
{
this->setEnabled(false);
emit signal_clicked_ch_add(mind);
}
}
void MF::slot_ch_changes()
{
const QModelIndex chind = change_tblv->currentIndex();
if(chind.isValid())
{
this->setEnabled(false);
emit signal_clicked_ch_chenges(chind);
}
else
{
QMessageBox::information(this,tr("Info"),tr("Choose the something!"));
}
}
void MF::slot_ch_delete()
{
QModelIndex chind = change_tblv->currentIndex();
if(chind.isValid())
{
int n = QMessageBox::warning(this,tr("Warning"),tr("Information will be lost \n Are you sure? "),QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (n==QMessageBox::Yes) emit signal_clicked_ch_delete(chind);
}
else
{
QMessageBox::information(this,tr("Info"),tr("Choose the something!"));
}
}
void MF::slot_delete_change( const QModelIndex &chind)
{
if (!sqqmodel.removeRow(chind.row()))
{
qDebug() << sqqmodel.lastError();
}
sqqmodel.select();
}
void MF::slot_set_font()
{
bool bOk;
font = QFontDialog::getFont(&bOk,this);
if (bOk)
{
main_tblv->setFont(font);
change_tblv->setFont(font);
emit signal_font_ch();
}
}
void MF::slot_settings()
{
pdst->show();
if(pdst->exec())
{
emit signal_setings_ch();
}
}
void MF::slot_about()
{
QMessageBox::about(this,tr("About developer"),tr("This Proggramm develop for NNCSM.\n"
"Developer Klimets Sergey Vadimovich. \n"
" 2015 year."));
}
void MF::slot_aboutQt()
{
QMessageBox::aboutQt(this,tr("About Qt"));
}
void MF::slot_help()
{
QMessageBox::about(this,tr("About Programm"),tr("Programm Catalog V 1.1 \n"
" 2015 year"));
}
void MF::slot_edit_main()
{
const QModelIndex ind = main_tblv->currentIndex();
if(ind.isValid())
{
this->setEnabled(false);
emit signal_clicked_edit(ind);
}
else
{
QMessageBox::information(this,tr("Info"),tr("Choose the something!"));
}
}
void MF::slot_en_main()
{
this->setEnabled(true);
this->sqtmodel.select();
this->sqqmodel.select();
}
void MF::slot_add()
{
this->setEnabled(false);
emit signal_clicked_add();
}
void MF::slot_delete_main(const QModelIndex &ind)
{
if (!sqqmodel.removeRows(0,sqqmodel.rowCount()))
{
qDebug() << sqqmodel.lastError();
}
sqqmodel.select();
if (!sqtmodel.removeRow(ind.row()))
{
// QMessageBox::critical(this,tr("Atantion"),tr("critical SQL Error \n" + sqtmodel.lastError() ));
qDebug() << sqtmodel.lastError();
}
sqtmodel.select();
}
void MF::slot_delete()
{
const QModelIndex ind = main_tblv->currentIndex();
if (ind.isValid())
{
int n = QMessageBox::warning(this,tr("Warning"),tr("Information will be lost \n Are you sure? "),QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (n==QMessageBox::Yes) emit signal_clicked_delete(ind);
}
else
{
QMessageBox::information(this,tr("Info"),tr("Choose the something!"));
}
}
void MF::closeEvent(QCloseEvent *event)
{
this->~MF();
event->accept();
}
/*virtual*/ MF::~MF()
{
settings.beginGroup("/Settings");
settings.setValue("/Path", pdst->get_Path());
settings.setValue("/Splash",pdst->get_splash());
settings.setValue("/Font", font.toString());
settings.endGroup();
ldb.close();
delete padduser;
delete pmAdd;
delete pchf;
delete plf;
}