Skip to content

Commit

Permalink
我写代码像 CXK
Browse files Browse the repository at this point in the history
  • Loading branch information
iotang committed Jan 1, 2020
1 parent 4e429a3 commit 16b5ac4
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 38 deletions.
9 changes: 5 additions & 4 deletions addtestcaseswizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "addtestcaseswizard.h"
#include "ui_addtestcaseswizard.h"
#include "settings.h"
#include <algorithm>
#include <QMessageBox>

AddTestCasesWizard::AddTestCasesWizard(QWidget *parent) :
Expand Down Expand Up @@ -290,8 +291,8 @@ void AddTestCasesWizard::searchMatchedFiles()
}
}

qSort(inputFiles.begin(), inputFiles.end(), compareFileName);
qSort(outputFiles.begin(), outputFiles.end(), compareFileName);
std::sort(inputFiles.begin(), inputFiles.end(), compareFileName);
std::sort(outputFiles.begin(), outputFiles.end(), compareFileName);

QList<QStringList> inputFilesMatchedPart;
QList<QStringList> outputFilesMatchedPart;
Expand Down Expand Up @@ -355,12 +356,12 @@ void AddTestCasesWizard::searchMatchedFiles()
ui->testCasesViewer->clear();

QList<QString> keys = loc.uniqueKeys();
qSort(keys.begin(), keys.end(), compareFileName);
std::sort(keys.begin(), keys.end(), compareFileName);

for (int i = 0; i < keys.size(); i ++)
{
QList<int> values = loc.values(keys[i]);
qSort(values.begin(), values.end());
std::sort(values.begin(), values.end());
QStringList inputFiles, outputFiles;
QTreeWidgetItem *item = new QTreeWidgetItem(ui->testCasesViewer);
item->setText(0, tr("Test Case #%1").arg(i + 1));
Expand Down
27 changes: 18 additions & 9 deletions assignmentthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const QList<QStringList> &AssignmentThread::getInputFiles() const

bool AssignmentThread::traditionalTaskPrepare()
{
makeDialogAlert(tr("Preparing..."));
compileState = NoValidSourceFile;
QDir contestantDir;
contestantDir = ! task->getSubFolderCheck() ? QDir(Settings::sourcePath() + contestantName) : QDir(Settings::sourcePath() + contestantName + QDir::separator() + task->getSourceFileName());
Expand All @@ -120,7 +121,7 @@ bool AssignmentThread::traditionalTaskPrepare()

if (task->getTaskType() == Task::Communication)
{
filters = task->getSourceFilesName();
filters = task->getSourceFilesPath();
}
else
{
Expand Down Expand Up @@ -157,11 +158,13 @@ bool AssignmentThread::traditionalTaskPrepare()
QDir(Settings::temporaryPath()).mkdir(contestantName);
if (task->getTaskType() == Task::Communication)
{
QStringList sourcePaths = task->getSourceFilesPath(), sourceFiles = task->getSourceFilesName();
for (int i = 0; i < sourceFiles.length(); i++)
sourceFile = "";
QStringList sourcePaths = task->getSourceFilesPath(), sourceNames = task->getSourceFilesName();
for (int i = 0; i < sourcePaths.length(); i++)
{
QFile::copy(Settings::sourcePath() + contestantName + (task->getSubFolderCheck() ? QDir::separator() + task->getSourceFileName() : QString("")) + QDir::separator() + sourcePaths[i],
Settings::temporaryPath() + contestantName + QDir::separator() + sourceFiles[i]);
Settings::temporaryPath() + contestantName + QDir::separator() + sourceNames[i]);
sourceFile = sourceFile + " " + sourceNames[i] + " ";
}
}
else
Expand All @@ -180,11 +183,11 @@ bool AssignmentThread::traditionalTaskPrepare()

if (task->getTaskType() == Task::Communication)
{
QStringList graderPath = task->getGraderFilesPath(), graderName = task->getGraderFilesName();
for (int i = 0; i < graderPath.length(); i++)
QStringList graderPaths = task->getGraderFilesPath(), graderNames = task->getGraderFilesName();
for (int i = 0; i < graderPaths.length(); i++)
{
QFile::copy(Settings::dataPath() + graderPath[i], Settings::temporaryPath() + contestantName + QDir::separator() + graderName[i]);
extraFiles = extraFiles + " " + graderName[i] + " ";
QFile::copy(Settings::dataPath() + graderPaths[i], Settings::temporaryPath() + contestantName + QDir::separator() + graderNames[i]);
extraFiles = extraFiles + " " + graderNames[i] + " ";
}
}

Expand Down Expand Up @@ -239,6 +242,8 @@ bool AssignmentThread::traditionalTaskPrepare()

if (compilerList[i]->getCompilerType() != Compiler::InterpretiveWithoutByteCode)
{
makeDialogAlert(tr("Compiling..."));

QString arguments = compilerArguments[j];

if (task->getTaskType() == Task::Interaction)
Expand Down Expand Up @@ -342,7 +347,6 @@ bool AssignmentThread::traditionalTaskPrepare()
break;
}
}

break;
}
}
Expand Down Expand Up @@ -525,6 +529,11 @@ void AssignmentThread::assign()
thread->start();
}

void AssignmentThread::makeDialogAlert(QString msg)
{
emit dialogAlert(msg);
}

void AssignmentThread::taskSkipped(const QPair<int, int> &cur)
{
++countFinished;
Expand Down
2 changes: 2 additions & 0 deletions assignmentthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class AssignmentThread : public QThread
bool traditionalTaskPrepare();
void assign();
void taskSkipped(const QPair<int, int> &);
void makeDialogAlert(QString);

private slots:
void threadFinished();
Expand All @@ -99,6 +100,7 @@ public slots:
void stopJudgingSlot();

signals:
void dialogAlert(QString);
void singleCaseFinished(int, int, int, int, int, int, int);
void singleSubtaskDependenceFinished(int, int, int);
void compileError(int, int);
Expand Down
8 changes: 7 additions & 1 deletion contest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void Contest::swapTask(int a, int b)
{
if (0 <= b && b < taskList.size())
{
taskList.swap(a, b);
taskList.swapItemsAt(a, b);
}
}

Expand Down Expand Up @@ -233,6 +233,8 @@ void Contest::judge(Contestant *contestant)
emit taskJudgingStarted(taskList[i]->getProblemTile());

AssignmentThread *thread = new AssignmentThread();
connect(thread, SIGNAL(dialogAlert(QString)),
this, SIGNAL(dialogAlert(QString)));
connect(thread, SIGNAL(singleCaseFinished(int, int, int, int, int, int, int)),
this, SIGNAL(singleCaseFinished(int, int, int, int, int, int, int)));
connect(thread, SIGNAL(singleSubtaskDependenceFinished(int, int, int)),
Expand Down Expand Up @@ -295,6 +297,8 @@ void Contest::judge(Contestant *contestant, QSet<int> index)
emit taskJudgingStarted(taskList[i]->getProblemTile());

AssignmentThread *thread = new AssignmentThread();
connect(thread, SIGNAL(dialogAlert(QString)),
this, SIGNAL(dialogAlert(QString)));
connect(thread, SIGNAL(singleCaseFinished(int, int, int, int, int, int, int)),
this, SIGNAL(singleCaseFinished(int, int, int, int, int, int, int)));
connect(thread, SIGNAL(singleSubtaskDependenceFinished(int, int, int)),
Expand Down Expand Up @@ -353,6 +357,8 @@ void Contest::judge(Contestant *contestant, int index)
emit taskJudgingStarted(taskList[index]->getProblemTile());

AssignmentThread *thread = new AssignmentThread();
connect(thread, SIGNAL(dialogAlert(QString)),
this, SIGNAL(dialogAlert(QString)));
connect(thread, SIGNAL(singleCaseFinished(int, int, int, int, int, int, int)),
this, SIGNAL(singleCaseFinished(int, int, int, int, int, int, int)));
connect(thread, SIGNAL(singleSubtaskDependenceFinished(int, int, int)),
Expand Down
1 change: 1 addition & 0 deletions contest.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public slots:
void taskAddedForViewer();
void taskDeletedForViewer(int);
void problemTitleChanged();
void dialogAlert(QString);
void singleCaseFinished(int, int, int, int, int, int, int);
void singleSubtaskDependenceFinished(int, int, int);
void taskJudgingStarted(QString);
Expand Down
20 changes: 10 additions & 10 deletions contestant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ void Contestant::swapTask(int a, int b)
if (a < 0 || a >= checkJudged.size())return;
if (b < 0 || b >= checkJudged.size())return;

checkJudged.swap(a, b);
compileState.swap(a, b);
sourceFile.swap(a, b);
compileMesaage.swap(a, b);
inputFiles.swap(a, b);
result.swap(a, b);
message.swap(a, b);
score.swap(a, b);
timeUsed.swap(a, b);
memoryUsed.swap(a, b);
checkJudged.swapItemsAt(a, b);
compileState.swapItemsAt(a, b);
sourceFile.swapItemsAt(a, b);
compileMesaage.swapItemsAt(a, b);
inputFiles.swapItemsAt(a, b);
result.swapItemsAt(a, b);
message.swapItemsAt(a, b);
score.swapItemsAt(a, b);
timeUsed.swapItemsAt(a, b);
memoryUsed.swapItemsAt(a, b);
}

int Contestant::getTaskScore(int index) const
Expand Down
4 changes: 2 additions & 2 deletions detaildialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void DetailDialog::refreshViewer(Contest *_contest, Contestant *_contestant)

if (timeUsed[j][k] != -1)
{
htmlCode += QString("").sprintf("%.3lf s", double (timeUsed[j][k]) / 1000);
htmlCode += QString("").asprintf("%.3lf s", double (timeUsed[j][k]) / 1000);
}
else
{
Expand All @@ -261,7 +261,7 @@ void DetailDialog::refreshViewer(Contest *_contest, Contestant *_contestant)

if (memoryUsed[j][k] != -1)
{
htmlCode += QString("").sprintf("%.3lf MB", double (memoryUsed[j][k]) / 1024 / 1024);
htmlCode += QString("").asprintf("%.3lf MB", double (memoryUsed[j][k]) / 1024 / 1024);
}
else
{
Expand Down
15 changes: 8 additions & 7 deletions exportutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "testcase.h"
#include "contestant.h"
#include "globaltype.h"
#include <algorithm>
#include <QMessageBox>
#include <QFileDialog>
#include <QApplication>
Expand Down Expand Up @@ -238,7 +239,7 @@ QString ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contesta

if (timeUsed[j][k] != -1)
{
htmlCode += QString("").sprintf("%.3lf s", double (timeUsed[j][k]) / 1000);
htmlCode += QString("").asprintf("%.3lf s", double (timeUsed[j][k]) / 1000);
}
else
{
Expand All @@ -251,7 +252,7 @@ QString ExportUtil::getContestantHtmlCode(Contest *contest, Contestant *contesta

if (memoryUsed[j][k] != -1)
{
htmlCode += QString("").sprintf("%.3lf MB", double (memoryUsed[j][k]) / 1024 / 1024);
htmlCode += QString("").asprintf("%.3lf MB", double (memoryUsed[j][k]) / 1024 / 1024);
}
else
{
Expand Down Expand Up @@ -326,7 +327,7 @@ void ExportUtil::exportHtml(QWidget *widget, Contest *contest, const QString &fi
}
}

qSort(sortList);
std::sort(sortList.begin(), sortList.end());
QMap<QString, int> rankList;

for (int i = 0; i < sortList.size(); i ++)
Expand Down Expand Up @@ -622,7 +623,7 @@ QString ExportUtil::getSmallerContestantHtmlCode(Contest *contest, Contestant *c

if (timeUsed[j][k] != -1)
{
htmlCode += QString("").sprintf("%.3lf s", double (timeUsed[j][k]) / 1000);
htmlCode += QString("").asprintf("%.3lf s", double (timeUsed[j][k]) / 1000);
}
else
{
Expand All @@ -635,7 +636,7 @@ QString ExportUtil::getSmallerContestantHtmlCode(Contest *contest, Contestant *c

if (memoryUsed[j][k] != -1)
{
htmlCode += QString("").sprintf("%.3lf MB", double (memoryUsed[j][k]) / 1024 / 1024);
htmlCode += QString("").asprintf("%.3lf MB", double (memoryUsed[j][k]) / 1024 / 1024);
}
else
{
Expand Down Expand Up @@ -705,7 +706,7 @@ void ExportUtil::exportSmallerHtml(QWidget *widget, Contest *contest, const QStr
}
}

qSort(sortList);
std::sort(sortList.begin(), sortList.end());
QMap<QString, int> rankList;

for (int i = 0; i < sortList.size(); i ++)
Expand Down Expand Up @@ -830,7 +831,7 @@ void ExportUtil::exportCsv(QWidget *widget, Contest *contest, const QString &fil
}
}

qSort(sortList);
std::sort(sortList.begin(), sortList.end());
QMap<QString, int> rankList;

for (int i = 0; i < sortList.size(); i ++)
Expand Down
16 changes: 16 additions & 0 deletions judgingdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ JudgingDialog::~JudgingDialog()
void JudgingDialog::setContest(Contest *contest)
{
curContest = contest;
connect(curContest, SIGNAL(dialogAlert(QString)),
this, SLOT(dialogAlert(QString)));
connect(curContest, SIGNAL(singleCaseFinished(int, int, int, int, int, int, int)),
this, SLOT(singleCaseFinished(int, int, int, int, int, int, int)));
connect(curContest, SIGNAL(singleSubtaskDependenceFinished(int, int, int)),
Expand Down Expand Up @@ -267,6 +269,20 @@ void JudgingDialog::singleCaseFinished(int progress, int x, int y, int result, i
bar->setValue(bar->maximum());
}

void JudgingDialog::dialogAlert(QString msg)
{
QTextBlockFormat blockFormat;
blockFormat.setLeftMargin(30);
cursor->insertBlock(blockFormat);
QTextCharFormat format;
format.setFontPointSize(9);
format.setForeground(QBrush(Qt::gray));
cursor->insertText(msg, format);

QScrollBar *bar = ui->logViewer->verticalScrollBar();
bar->setValue(bar->maximum());
}

void JudgingDialog::singleSubtaskDependenceFinished(int x, int y, int status)
{
QTextBlockFormat blockFormat;
Expand Down
1 change: 1 addition & 0 deletions judgingdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private slots:
bool stopJudging;

public slots:
void dialogAlert(QString);
void singleCaseFinished(int, int, int, int, int, int, int);
void singleSubtaskDependenceFinished(int, int, int);
void taskJudgingStarted(const QString &);
Expand Down
3 changes: 2 additions & 1 deletion lemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "detaildialog.h"
#include "statisticsbrowser.h"
#include "exportutil.h"
#include <algorithm>
#include <QMessageBox>
#include <QDesktopServices>
#include <QUrl>
Expand Down Expand Up @@ -1147,7 +1148,7 @@ void Lemon::addTasksAction()
}
}

qSort(cases.begin(), cases.end(), compareFileName);
std::sort(cases.begin(), cases.end(), compareFileName);

if (! cases.isEmpty())
{
Expand Down
7 changes: 4 additions & 3 deletions resultviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "contest.h"
#include "task.h"
#include "detaildialog.h"
#include <algorithm>
#include <QMessageBox>
#include <QCheckBox>
#include <QGridLayout>
Expand Down Expand Up @@ -187,7 +188,7 @@ void ResultViewer::refreshViewer()
}
else bg = QColor::fromHslF(oriBaseColorHF, oriBaseColorSF, oriBaseColorLF(score, fullScore[j], 0.3));

item(i, j + 3)->setBackgroundColor(bg);
item(i, j + 3)->setBackground(bg);
}
else
{
Expand All @@ -204,7 +205,7 @@ void ResultViewer::refreshViewer()
if (totalScore != -1)
{
item(i, 2)->setData(Qt::DisplayRole, totalScore);
item(i, 2)->setBackgroundColor(QColor::fromHslF(oriBaseColorHF, oriBaseColorSF, oriBaseColorLF(totalScore, sfullScore, 0.4)));
item(i, 2)->setBackground(QColor::fromHslF(oriBaseColorHF, oriBaseColorSF, oriBaseColorLF(totalScore, sfullScore, 0.4)));

QFont font;
font.setBold(true);
Expand All @@ -222,7 +223,7 @@ void ResultViewer::refreshViewer()
}
}

qSort(sortList);
std::sort(sortList.begin(), sortList.end());
QMap<QString, int> rankList;

for (int i = 0; i < sortList.size(); i ++)
Expand Down
2 changes: 1 addition & 1 deletion settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void Settings::swapCompiler(int a, int b)
{
if (0 <= b && b < compilerList.size())
{
compilerList.swap(a, b);
compilerList.swapItemsAt(a, b);
}
}
}
Expand Down

0 comments on commit 16b5ac4

Please sign in to comment.