forked from CodElecCz/CameraUIv1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindowReport.cpp
169 lines (143 loc) · 4.74 KB
/
MainWindowReport.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
#include <QDockWidget>
#include <QTextBrowser>
#include <QSqlError>
#include <QDir>
#include <QDateTime>
#include "MainWindow.h"
#include "ui_MainWindow.h"
void MainWindow::createReportWindow(bool showWindow, bool errorQueryToFile)
{
QDockWidget *dock = new QDockWidget(tr("Report"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
report = new ReportView(errorQueryToFile, dock);
dock->setWidget(report);
// dock->resize(250,400);
addDockWidget(Qt::RightDockWidgetArea, dock);
ui->menuTools->addAction(dock->toggleViewAction());
//resize Qt buck
dock->setFloating(true);
dock->hide();
dock->setFloating(false);
if(showWindow)
dock->show();
connect(report, SIGNAL(addTrace(QString,QColor)), this, SLOT(addTrace(QString,QColor)));
connect(report, SIGNAL(readImageFile(QString,QString,QString)), this, SLOT(readImageFile(QString,QString,QString)));
}
bool MainWindow::initializeDatabase(QString dbsHostName, QString dbsDatabase, QString dbsUser, QString dbsPassword)
{
bool status = false;
db = QSqlDatabase::addDatabase("QODBC");
db.setHostName(dbsHostName);
db.setDatabaseName(dbsDatabase);
db.setUserName(dbsUser);
db.setPassword(dbsPassword);
status = db.open();
if(!status)
{
QString msg = "Database initialization failed! Error: " + db.lastError().text() +
"; " + dbsHostName +
"/" + dbsDatabase +
"/" + dbsUser;
emit addTrace(msg);
//QMessageBox::warning(this, "Warning", msg);
//qDebug() << msg;
}
report->setDbs(&db);
return status;
}
void MainWindow::closeDatabase()
{
bool status = db.isOpen();
if(status)
{
db.close();
qDebug() << "Database Close()";
}
}
void MainWindow::readImageFile(QString camera, QString imageName, QString error)
{
if(imageName.length()>0)
{
QString sdate = imageName.split("T").at(0);
QStringList list = sdate.split("-");
// C:\Catalog\2018\12\08\2018-12-08T15.20.37_323456789_1.jpg
QString filePath = catalogPath + "/" + list.at(0) + "/" + list.at(1) + "/" + list.at(2) + "/" + imageName;
QFile imageFile(filePath);
if(!imageFile.exists())
{
emit addTrace("Image file not exist: " + filePath);
}
else
{
QImage image(filePath);
view->updateImage(camera, image);
//emit addTrace("Image file : " + filePath);
view->setPath(camera, filePath);
}
}
else
{
view->setError(camera, error);
}
}
void MainWindow::recordImageFiles(QString label)
{
QStringList camList = view->getViewNames();
QDateTime dt = QDateTime::currentDateTime();
QString sdtPath = dt.toString("yyyy/MM/dd/");
QString sdtFile = dt.toString("yyyy-MM-ddThh.mm.ss");
bool res;
QString fileDir = catalogPath + "/" + sdtPath;
QDir dir(fileDir);
if(!dir.exists())
{
dir.mkpath(fileDir);
addTrace("Directory created, " + fileDir);
}
int i = 1;
foreach(QString cam, camList)
{
QString imageExt = QString::number(i) + "." + imageFormat.toLower();
QString filePath = fileDir + sdtFile + "_" + label + "_" + imageExt;
if(!view->isError(cam))
{
bool res = view->saveImage(cam, filePath, imageFormat, imageQuality);
if(!res)
{
addTrace("Image not saved, " + filePath);
}
else
{
//QFile file(filePath);
//int fileSize = file.size() / 1024;
//addTrace("Image saved, " + filePath + ", Size: " + QString::number(fileSize) + " [kB]");
res = report->storeResult(sdtFile, cam, label, imageExt);
}
}
else
{
res = report->storeResult(sdtFile, cam, label, QString(""), view->getError(cam));
}
i++;
}
}
void MainWindow::saveImageFiles(QString targetDir)
{
QStringList camList = view->getViewNames();
QDir dir(targetDir);
foreach(QString cam, camList)
{
if(!view->isError(cam))
{
QString sourcePath = view->getPath(cam);
QFile file(sourcePath);
if(file.exists())
{
QFileInfo fileInfo(file.fileName());
QString filename(fileInfo.fileName());
QString targetFile = targetDir + "/" + filename;
bool res = file.copy(targetFile);
}
}
}
}