support "url" in fps file

This commit is contained in:
Roy Qu 2022-12-11 21:46:51 +08:00
parent b1ca0bb600
commit 67f0e4dee2
2 changed files with 10 additions and 15 deletions

View File

@ -8915,7 +8915,7 @@ void MainWindow::on_btnImportFPS_clicked()
this, this,
tr("Import FPS Problem Set"), tr("Import FPS Problem Set"),
QString(), QString(),
tr("FPS Problem Set Files (*.fps)")); tr("FPS Problem Set Files (*.fps;*.xml)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
try { try {
QList<POJProblem> problems = importFreeProblemSet(fileName); QList<POJProblem> problems = importFreeProblemSet(fileName);

View File

@ -24,12 +24,11 @@ QList<POJProblem> importFreeProblemSet(const QString &filename)
if (xml.name()=="item") { if (xml.name()=="item") {
currentProblem=std::make_shared<OJProblem>(); currentProblem=std::make_shared<OJProblem>();
} else if (currentProblem && } else if (currentProblem &&
( xml.name()=="sample_input" (xml.name()=="test_input")) {
|| xml.name()=="test_input")) {
currentCase = std::make_shared<OJProblemCase>(); currentCase = std::make_shared<OJProblemCase>();
foreach (const QXmlStreamAttribute& attr, xml.attributes()) { foreach (const QXmlStreamAttribute& attr, xml.attributes()) {
if (attr.name() == "name") { if (attr.name() == "name") {
currentCase->name = attr.value().toString(); currentCase->name = attr.value().toString().trimmed();
break; break;
} }
} }
@ -38,7 +37,7 @@ QList<POJProblem> importFreeProblemSet(const QString &filename)
xml.name()=="time_limit") { xml.name()=="time_limit") {
foreach (const QXmlStreamAttribute& attr, xml.attributes()) { foreach (const QXmlStreamAttribute& attr, xml.attributes()) {
if (attr.name() == "unit" && attr.value()=="ms") { if (attr.name() == "unit" && attr.value()=="ms") {
currentEleName = xml.name().toString(); currentEleName = attr.name().toString();
break; break;
} }
} }
@ -46,7 +45,7 @@ QList<POJProblem> importFreeProblemSet(const QString &filename)
xml.name()=="memory_limit") { xml.name()=="memory_limit") {
foreach (const QXmlStreamAttribute& attr, xml.attributes()) { foreach (const QXmlStreamAttribute& attr, xml.attributes()) {
if (attr.name() == "unit" && attr.value()=="mb") { if (attr.name() == "unit" && attr.value()=="mb") {
currentEleName = xml.name().toString(); currentEleName = attr.name().toString();
break; break;
} }
} }
@ -60,15 +59,9 @@ QList<POJProblem> importFreeProblemSet(const QString &filename)
} }
break; break;
case QXmlStreamReader::TokenType::Characters: case QXmlStreamReader::TokenType::Characters:
if (currentCase && if (currentCase && currentProblem && currentEleName=="test_input") {
(
currentEleName=="test_input" ||
currentEleName=="sample_input")) {
currentCase->input = xml.text().toString(); currentCase->input = xml.text().toString();
} else if (currentCase && currentProblem && } else if (currentCase && currentProblem && currentEleName=="test_output" ) {
(
currentEleName=="test_output" ||
currentEleName=="sample_output")) {
currentCase->expected = xml.text().toString(); currentCase->expected = xml.text().toString();
currentProblem->cases.append(currentCase); currentProblem->cases.append(currentCase);
currentCase.reset(); currentCase.reset();
@ -77,7 +70,9 @@ QList<POJProblem> importFreeProblemSet(const QString &filename)
} else if (currentProblem && currentEleName=="hint") { } else if (currentProblem && currentEleName=="hint") {
currentProblem->hint = xml.text().toString(); currentProblem->hint = xml.text().toString();
} else if (currentProblem && currentEleName=="title") { } else if (currentProblem && currentEleName=="title") {
currentProblem->name = xml.text().toString(); currentProblem->name = xml.text().toString().trimmed();
} else if (currentProblem && currentEleName=="url") {
currentProblem->url = xml.text().toString().trimmed();
} else if (currentProblem && currentEleName=="time_limit") { } else if (currentProblem && currentEleName=="time_limit") {
currentProblem->timeLimit = xml.text().toInt(); currentProblem->timeLimit = xml.text().toInt();
} else if (currentProblem && currentEleName=="memory_limit") { } else if (currentProblem && currentEleName=="memory_limit") {