-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsynchresultitem.cpp
136 lines (121 loc) · 4.67 KB
/
synchresultitem.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
/** @file synchresultitem.cpp
* Soubor s tridou SynchResultItem dedici ze trid QObject a QTreeWidgetItem,
* radky s vysledky v dialogu s vysledky synchronizace
*/
#include "synchresultitem.h"
SynchResultItem::SynchResultItem(ImageInfo* image, QString cOk, QString cFailed, QString cOkUnchecked, QString cFailedChecked, QTreeWidget* parent)
: QTreeWidgetItem(parent)
{
colorFailed = cFailed;
colorOk = cOk;
colorOkUnchecked = cOkUnchecked;
colorFailedChecked = cFailedChecked;
colCount = parent->columnCount();
checkBox = new QCheckBox();
checkBox->setChecked(0);
checkBox->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
checkBox->setMaximumWidth(20);
QObject::connect(checkBox, SIGNAL(clicked()), this, SLOT(setItemColor()));
QLabel* l = new QLabel(QFileInfo(image->imageData->pictureName).fileName());
QWidget* w = new QWidget;
w->setLayout(new QHBoxLayout);
w->layout()->setSpacing(0);
w->layout()->setContentsMargins(1, 1, 1, 1);
w->layout()->setAlignment(Qt::AlignLeft);
w->layout()->addWidget(checkBox);
w->layout()->addWidget(l);
parent->setItemWidget(this, 0, w);
if (image->imageData->dateTime->isNull()
|| image->imageData->dateTime->toSecsSinceEpoch() == QDateTime::fromString(QString("0000:00:00 00:00:00"), "yyyy:MM:dd hh:mm:ss").toSecsSinceEpoch()) {
// neni datum ve fotce
this->setText(1, "-");
this->setText(2, "-");
this->setText(3, "-");
this->setText(4, "-");
this->setText(5, "-");
for (int j = 0; j < parent->columnCount(); j++) {
this->setBackground(j, QBrush(colorFailed, Qt::SolidPattern));
}
synchOk = 0;
timeDiff = 9999999;
checkBox->setEnabled(false);
} else {
this->setText(1, image->imageData->dateTime->toString("dd.M.yyyy hh:mm:ss"));
if (image->approxMethod == 0) { // nejblizsi bod
this->setText(3, tr("nearest point (") + image->candidatePointTime->toString("dd.MM.yyyy hh:mm:ss") + ")");
timeDiff = image->imageData->dateTime->toSecsSinceEpoch() - image->candidatePointTime->toSecsSinceEpoch();
char sign = '+';
if (timeDiff < 0) {
timeDiff *= -1;
sign = '-';
}
int days = timeDiff / (24 * 3600);
QString dayName;
if (days == 1) {
dayName = tr("day");
} else if (days == 2 || days == 3 || days == 4) {
dayName = tr("days", "low");
} else {
dayName = tr("days", "high");
}
int h = (timeDiff % 24) / 3600;
int m = (timeDiff % 3600) / 60;
int s = (timeDiff % 60);
QString str;
str = sign
+ (days > 0 ? QString::number(days) + dayName + " " : "")
+ (h ? QString("%1h").arg(h) : "")
+ ((m || h) ? QString("%1m").arg(m) : "")
+ QString("%1s").arg(s);
this->setText(4, str);
} else if (image->approxMethod == 1) {
this->setText(3, tr("from 2 points"));
timeDiff = 0;
} else if (image->approxMethod == 2) { // z vice bodu
this->setText(3, tr("from more points"));
timeDiff = 0;
}
if (image->candidateIsCorrect) {
checkBox->setChecked(1);
for (int j = 0; j < parent->columnCount(); j++) {
this->setBackground(j, QBrush(colorOk, Qt::SolidPattern));
}
synchOk = 1;
} else { // prirazeni selhalo
for (int j = 0; j < parent->columnCount(); j++) {
this->setBackground(j, QBrush(colorFailed, Qt::SolidPattern));
}
synchOk = 0;
}
this->setText(2, image->gpsCandidadesString());
this->setText(5, image->routeName);
}
if (image->imageData->isGps) {
QFont font = this->font(2);
font.setBold(true);
this->setFont(2, font);
}
}
void SynchResultItem::setChecked(bool n)
{
if (checkBox->isEnabled()) {
checkBox->setChecked(n);
setItemColor();
}
}
void SynchResultItem::setItemColor()
{
QString currentColor;
if (synchOk && checkBox->isChecked()) {
currentColor = colorOk;
} else if (!synchOk && !checkBox->isChecked()) {
currentColor = colorFailed;
} else if (synchOk && !checkBox->isChecked()) {
currentColor = colorOkUnchecked;
} else if (!synchOk && checkBox->isChecked()) {
currentColor = colorFailedChecked;
}
for (int j = 0; j < colCount; j++) {
this->setBackground(j, QBrush(currentColor, Qt::SolidPattern));
}
}