Skip to content

Commit b780f2a

Browse files
5ab-juruooitl-5abalphagocc
authored
feat: compress export HTML code (#139)
* feat: compressed export HTML code * chore: styled Co-authored-by: oitl-5ab <mail-5ab@qq.com> Co-authored-by: Alphagocc <alphagocc@163.com>
1 parent ac518dc commit b780f2a

2 files changed

Lines changed: 49 additions & 81 deletions

File tree

makespec/BUILDVERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
197
2+

src/component/exportutil/exportutil.cpp

Lines changed: 48 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -107,30 +107,12 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
107107
}
108108

109109
htmlCode += "<table style=\"border: solid;\"><tr>";
110-
htmlCode +=
111-
QString(
112-
R"(<th scope="col" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">%1</th>)")
113-
.arg(tr("Test Case"));
114-
htmlCode +=
115-
QString(
116-
R"(<th scope="col" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">%1</th>)")
117-
.arg(tr("Input File"));
118-
htmlCode +=
119-
QString(
120-
R"(<th scope="col" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">%1</th>)")
121-
.arg(tr("Result"));
122-
htmlCode +=
123-
QString(
124-
R"(<th scope="col" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">%1</th>)")
125-
.arg(tr("Time Used"));
126-
htmlCode +=
127-
QString(
128-
R"(<th scope="col" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">%1</th>)")
129-
.arg(tr("Memory Used"));
130-
htmlCode +=
131-
QString(
132-
R"(<th scope="col" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">%1</th></tr>)")
133-
.arg(tr("Score"));
110+
htmlCode += QString(R"(<th scope="col" class="a">%1</th>)").arg(tr("Test Case"));
111+
htmlCode += QString(R"(<th scope="col" class="a">%1</th>)").arg(tr("Input File"));
112+
htmlCode += QString(R"(<th scope="col" class="a">%1</th>)").arg(tr("Result"));
113+
htmlCode += QString(R"(<th scope="col" class="a">%1</th>)").arg(tr("Time Used"));
114+
htmlCode += QString(R"(<th scope="col" class="a">%1</th>)").arg(tr("Memory Used"));
115+
htmlCode += QString(R"(<th scope="col" class="a">%1</th></tr>)").arg(tr("Score"));
134116
QList<TestCase *> testCases = taskList[i]->getTestCaseList();
135117
QList<QStringList> inputFiles = contestant->getInputFiles(i);
136118
QList<QList<ResultState>> result = contestant->getResult(i);
@@ -145,30 +127,23 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
145127

146128
if (k == 0) {
147129
if (score[j].size() == inputFiles[j].size())
148-
htmlCode +=
149-
QString(
150-
R"(<td rowspan="%1" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">#%2</td>)")
151-
.arg(inputFiles[j].size())
152-
.arg(j + 1);
130+
htmlCode += QString(R"(<td rowspan="%1" class="a">#%2</td>)")
131+
.arg(inputFiles[j].size())
132+
.arg(j + 1);
153133
else
154-
htmlCode +=
155-
QString(
156-
R"(<td rowspan="%1" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;">#%2<br>%3:%4</td>)")
157-
.arg(inputFiles[j].size())
158-
.arg(j + 1)
159-
.arg(tr("Subtask Dependence Status"))
160-
.arg(statusRankingText(score[j].back()));
134+
htmlCode += QString(R"(<td rowspan="%1" class="a">#%2<br>%3:%4</td>)")
135+
.arg(inputFiles[j].size())
136+
.arg(j + 1)
137+
.arg(tr("Subtask Dependence Status"))
138+
.arg(statusRankingText(score[j].back()));
161139
}
162140

163-
htmlCode += QString("<td style=\"border-style: none solid solid none; border-width: 1px 3px; "
164-
"border-color: #ccc;\">%1</td>")
165-
.arg(inputFiles[j][k]);
141+
htmlCode += QString("<td class=\"a\">%1</td>").arg(inputFiles[j][k]);
166142
QString text;
167143
QString bgColor = "rgb(255, 255, 255)";
168144
QString frColor = "rgb(0, 0, 0)";
169145
Settings::setTextAndColor(result[j][k], text, frColor, bgColor);
170-
htmlCode += QString("<td style=\"border-style: none solid solid none; border-width: 1px 3px; "
171-
"border-color: #ccc; background-color: %2; color: %3;\">%1")
146+
htmlCode += QString("<td class=\"a\" style=\"background-color: %2; color: %3;\">%1")
172147
.arg(text)
173148
.arg(bgColor)
174149
.arg(frColor);
@@ -181,8 +156,7 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
181156
}
182157

183158
htmlCode += "</td>";
184-
htmlCode += "<td style=\"border-style: none solid solid none; border-width: 1px 3px; "
185-
"border-color: #ccc;\">";
159+
htmlCode += "<td class=\"a\">";
186160

187161
if (timeUsed[j][k] != -1) {
188162
htmlCode += QString("").asprintf("%.3lf s", double(timeUsed[j][k]) / 1000);
@@ -191,8 +165,7 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
191165
}
192166

193167
htmlCode += "</td>";
194-
htmlCode += "<td style=\"border-style: none solid solid none; border-width: 1px 3px; "
195-
"border-color: #ccc;\">";
168+
htmlCode += "<td class=\"a\">";
196169

197170
if (memoryUsed[j][k] != -1) {
198171
htmlCode += QString("").asprintf("%.3lf MB", double(memoryUsed[j][k]) / 1024 / 1024);
@@ -219,7 +192,7 @@ auto ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contestant,
219192

220193
htmlCode +=
221194
QString(
222-
R"(<td rowspan="%1" style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc; background-color: %2;"><a style="font-weight: bold; font-size: large;">%3</a> / %4</td>)")
195+
R"(<td rowspan="%1" class="a" style=" background-color: %2;"><a class="c">%3</a> / %4</td>)")
223196
.arg(inputFiles[j].size())
224197
.arg(bgColor)
225198
.arg(minv)
@@ -261,7 +234,11 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
261234
out << "<html><head>";
262235
out << R"(<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />)";
263236
out << "<style type=\"text/css\">th, td {padding-left: 1em; padding-right: 1em; white-space: nowrap; "
264-
"text-align: center; verticle-align: middle;}</style>";
237+
"text-align: center; verticle-align: middle;} .a {border-style: none solid solid none; "
238+
"border-width: 1px 3px; border-color: #ccc;} .b {border-style: none solid solid none; "
239+
"border-width: 3px 3px; border-color: #000;} .c {font-weight: bold; font-size: large;} "
240+
".d {font-size:x-large; font-weight:bold;} .e {font-size: small;} .f {font-weight: bold;}"
241+
".g {border-style: none solid solid none; border-width: 3px 2px; border-color: #000;}</style>";
265242
out << "<title>" << contest->getContestTitle() << " : " << tr("Contest Result") << "</title>";
266243
out << "</head><body>";
267244
QList<std::pair<int, QString>> sortList;
@@ -293,25 +270,17 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
293270
loc.insert(contestantList[i], i);
294271
}
295272

296-
out << "<p><span style=\"font-size:x-large; font-weight:bold;\">";
273+
out << "<p><span class=\"d\">";
297274
out << "<a name=\"top\"></a>" << contest->getContestTitle() << " : " << tr("Rank List") << "</span></p>";
298-
out << "<p style=\"font-size: small;\">"
299-
<< tr("Click names or task scores to jump to details. Judged By LemonLime") << "</p>";
275+
out << "<p class=\"e\">" << tr("Click names or task scores to jump to details. Judged By LemonLime")
276+
<< "</p>";
300277
out << R"(<p><table cellpadding="1" style="border-style: solid;"><tr>)";
301-
out << QString(
302-
R"(<th style="border-style: none solid solid none; border-width: 3px 3px; border-color: #000;" scope="col">%1</th>)")
303-
.arg(tr("Rank"));
304-
out << QString(
305-
R"(<th style="border-style: none solid solid none; border-width: 3px 3px; border-color: #000;" scope="col">%1</th>)")
306-
.arg(tr("Name"));
307-
out << QString(
308-
R"(<th style="border-style: none solid solid none; border-width: 3px 2px; border-color: #000;" scope="col">%1</th>)")
309-
.arg(tr("Total Score"));
278+
out << QString(R"(<th class="b" scope="col">%1</th>)").arg(tr("Rank"));
279+
out << QString(R"(<th class="b" scope="col">%1</th>)").arg(tr("Name"));
280+
out << QString(R"(<th class="g" scope="col">%1</th>)").arg(tr("Total Score"));
310281

311282
for (auto &i : taskList)
312-
out << QString(
313-
R"(<th style="border-style: none solid solid none; border-width: 3px 2px; border-color: #000;" scope="col">%1</th>)")
314-
.arg(i->getProblemTitle());
283+
out << QString(R"(<th class="g" scope="col">%1</th>)").arg(i->getProblemTitle());
315284

316285
out << "</tr>";
317286
QList<int> fullScore;
@@ -323,11 +292,9 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
323292

324293
for (auto &i : sortList) {
325294
Contestant *contestant = contest->getContestant(i.second);
326-
out << QString("<tr><td style=\"border-style: none solid solid none; border-width: 1px 3px; "
327-
"border-color: #ccc;\">%1</td>")
328-
.arg(rankList[contestant->getContestantName()] + 1);
295+
out << QString("<tr><td class=\"a\">%1</td>").arg(rankList[contestant->getContestantName()] + 1);
329296
out << QString(
330-
R"(<td style="border-style: none solid solid none; border-width: 1px 3px; border-color: #ccc;"><a href="#c%1" style="color: black; text-decoration: none;">%2</a></td>)")
297+
R"(<td class="a"><a href="#c%1" style="color: black; text-decoration: none;">%2</a></td>)")
331298
.arg(loc[contestant])
332299
.arg(i.second);
333300
int allScore = contestant->getTotalScore();
@@ -402,8 +369,7 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
402369
out << "</table></p>";
403370

404371
for (int i = 0; i < contestantList.size(); i++) {
405-
out << QString("<a name=\"c%1\"><hr><a>").arg(i)
406-
<< "<span style=\"font-size:x-large; font-weight:bold;\">";
372+
out << QString("<a name=\"c%1\"><hr><a>").arg(i) << "<span class=\"d\">";
407373
out << tr("Contestant: %1").arg(contestantList[i]->getContestantName()) << "</span>";
408374
out << getContestantHtmlCode(contest, contestantList[i], i);
409375
}
@@ -560,12 +526,10 @@ auto ExportUtil::getSmallerContestantHtmlCode(Contest *contest, Contestant *cont
560526
if (score[j][t] < minv)
561527
minv = score[j][t];
562528

563-
htmlCode +=
564-
QString(
565-
R"(<td rowspan="%1"><a style="font-weight: bold; font-size: large;">%2</a> / %3</td>)")
566-
.arg(inputFiles[j].size())
567-
.arg(minv)
568-
.arg(maxv);
529+
htmlCode += QString(R"(<td rowspan="%1"><a class="c">%2</a> / %3</td>)")
530+
.arg(inputFiles[j].size())
531+
.arg(minv)
532+
.arg(maxv);
569533
}
570534

571535
htmlCode += "</tr>";
@@ -598,7 +562,11 @@ void ExportUtil::exportSmallerHtml(QWidget *widget, Contest *contest, const QStr
598562
out << "<html><head>";
599563
out << R"(<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />)";
600564
out << "<style type=\"text/css\">th, td {padding-left: 1em; padding-right: 1em; white-space: nowrap; "
601-
"text-align: center; verticle-align: middle;}</style>";
565+
"text-align: center; verticle-align: middle;} .a {border-style: none solid solid none; "
566+
"border-width: 1px 3px; border-color: #ccc;} .b {border-style: none solid solid none; "
567+
"border-width: 3px 3px; border-color: #000;} .c {font-weight: bold; font-size: large;} "
568+
".d {font-size:x-large; font-weight:bold;} .e {font-size: small;} .f {font-weight: bold;}"
569+
".g {border-style: none solid solid none; border-width: 3px 2px; border-color: #000;}</style>";
602570
out << "<title>" << contest->getContestTitle() << " : " << tr("Contest Result") << "</title>";
603571
out << "</head><body>";
604572
QList<std::pair<int, QString>> sortList;
@@ -630,9 +598,9 @@ void ExportUtil::exportSmallerHtml(QWidget *widget, Contest *contest, const QStr
630598
loc.insert(contestantList[i], i);
631599
}
632600

633-
out << "<p><span style=\"font-size:x-large; font-weight:bold;\">";
601+
out << "<p><span class=\"d\">";
634602
out << "<a name=\"top\"></a>" << contest->getContestTitle() << " : " << tr("Rank List") << "</span></p>";
635-
out << "<p style=\"font-size: small;\">" << tr("Judged By LemonLime") << "</p>";
603+
out << "<p class=\"e\">" << tr("Judged By LemonLime") << "</p>";
636604
out << R"(<p><table border="1" cellpadding="1"><tr>)";
637605
out << QString("<th scope=\"col\">%1</th>").arg(tr("Rank"));
638606
out << QString("<th scope=\"col\">%1</th>").arg(tr("Name"));
@@ -656,9 +624,9 @@ void ExportUtil::exportSmallerHtml(QWidget *widget, Contest *contest, const QStr
656624
int allScore = contestant->getTotalScore();
657625

658626
if (allScore != -1) {
659-
out << QString("<td style=\"font-weight: bold;\">%1</td>").arg(allScore);
627+
out << QString("<td class=\"f\">%1</td>").arg(allScore);
660628
} else {
661-
out << QString("<td style=\"font-weight: bold;\">%1</td>").arg(tr("Invalid"));
629+
out << QString("<td class=\"f\">%1</td>").arg(tr("Invalid"));
662630
}
663631

664632
for (int j = 0; j < taskList.size(); j++) {
@@ -675,8 +643,7 @@ void ExportUtil::exportSmallerHtml(QWidget *widget, Contest *contest, const QStr
675643
out << "</table></p>";
676644

677645
for (int i = 0; i < contestantList.size(); i++) {
678-
out << QString("<a name=\"c%1\"><hr><a>").arg(i)
679-
<< "<span style=\"font-size:x-large; font-weight:bold;\">";
646+
out << QString("<a name=\"c%1\"><hr><a>").arg(i) << "<span class=\"d\">";
680647
out << tr("Contestant: %1").arg(contestantList[i]->getContestantName()) << "</span>";
681648
out << getSmallerContestantHtmlCode(contest, contestantList[i]);
682649
}

0 commit comments

Comments
 (0)