From 2520ddf8f5a369f5866208493ea222bbfa320978 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 13 Dec 2022 08:49:20 +0800 Subject: [PATCH] - enhancement: Show memory usage for problem cases. --- NEWS.md | 2 + RedPandaIDE/compiler/compilermanager.cpp | 25 +- RedPandaIDE/compiler/compilermanager.h | 15 +- RedPandaIDE/compiler/ojproblemcasesrunner.cpp | 37 +- RedPandaIDE/compiler/ojproblemcasesrunner.h | 9 +- RedPandaIDE/mainwindow.cpp | 65 +- RedPandaIDE/mainwindow.h | 6 + RedPandaIDE/mainwindow.ui | 2 +- RedPandaIDE/problems/freeprojectsetformat.cpp | 20 +- RedPandaIDE/problems/ojproblemset.cpp | 31 + RedPandaIDE/problems/ojproblemset.h | 27 +- RedPandaIDE/settings.cpp | 42 +- RedPandaIDE/settings.h | 17 +- .../executorproblemsetwidget.cpp | 7 +- .../executorproblemsetwidget.ui | 34 +- RedPandaIDE/translations/RedPandaIDE_pt_BR.ts | 70 +- RedPandaIDE/translations/RedPandaIDE_zh_CN.ts | 790 ++++++++++-------- RedPandaIDE/translations/RedPandaIDE_zh_TW.ts | 74 +- .../widgets/ojproblempropertywidget.cpp | 83 +- RedPandaIDE/widgets/ojproblempropertywidget.h | 11 +- .../widgets/ojproblempropertywidget.ui | 91 +- RedPandaIDE/widgets/ojproblemsetmodel.cpp | 32 +- 22 files changed, 1015 insertions(+), 475 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5b13d7c6..6d74921c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,8 @@ Red Panda C++ Version 2.6 - enhancement: When current file is the project's makefile, show project's compiler set in the toolbar. - enhancement: Prevent error of "del" to stop make when rebuild project. - enhancement: Import FPS (free problem set) files. + - enhancement: Show current problem's description in the problem list's mouse tip. + - enhancement: Show memory usage for problem cases. Red Panda C++ Version 2.5 diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 766884ad..976bd271 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -316,27 +316,40 @@ void CompilerManager::run( } -void CompilerManager::runProblem(const QString &filename, const QString &arguments, const QString &workDir, POJProblemCase problemCase) +void CompilerManager::runProblem(const QString &filename, const QString &arguments, const QString &workDir, POJProblemCase problemCase, + const POJProblem& problem + ) { QMutexLocker locker(&mRunnerMutex); - doRunProblem(filename, arguments, workDir, QVector {problemCase}); + doRunProblem(filename, arguments, workDir, QVector {problemCase}, problem); } -void CompilerManager::runProblem(const QString &filename, const QString &arguments, const QString &workDir, const QVector& problemCases) +void CompilerManager::runProblem(const QString &filename, const QString &arguments, const QString &workDir, const QVector& problemCases, + const POJProblem& problem + ) { QMutexLocker locker(&mRunnerMutex); - doRunProblem(filename, arguments, workDir, problemCases); + doRunProblem(filename, arguments, workDir, problemCases, problem); } -void CompilerManager::doRunProblem(const QString &filename, const QString &arguments, const QString &workDir, const QVector& problemCases) +void CompilerManager::doRunProblem(const QString &filename, const QString &arguments, const QString &workDir, const QVector& problemCases, + const POJProblem& problem) { if (mRunner!=nullptr) { return; } OJProblemCasesRunner * execRunner = new OJProblemCasesRunner(filename,arguments,workDir,problemCases); mRunner = execRunner; - if (pSettings->executor().enableCaseTimeout()) + if (pSettings->executor().enableCaseLimit()) { execRunner->setExecTimeout(pSettings->executor().caseTimeout()); + execRunner->setMemoryLimit(pSettings->executor().caseMemoryLimit()*1024); //convert kb to bytes + } + size_t timeLimit = problem->getTimeLimit(); + size_t memoryLimit = problem->getMemoryLimit(); + if (timeLimit>0) + execRunner->setExecTimeout(timeLimit); + if (memoryLimit) + execRunner->setMemoryLimit(memoryLimit); connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); connect(mRunner, &Runner::finished, mRunner ,&Runner::deleteLater); connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunProblemFinished); diff --git a/RedPandaIDE/compiler/compilermanager.h b/RedPandaIDE/compiler/compilermanager.h index 96adca60..73c5bbbb 100644 --- a/RedPandaIDE/compiler/compilermanager.h +++ b/RedPandaIDE/compiler/compilermanager.h @@ -25,6 +25,8 @@ class Runner; class Project; class Compiler; +struct OJProblem; +using POJProblem = std::shared_ptr; struct OJProblemCase; using POJProblemCase = std::shared_ptr; class CompilerManager : public QObject @@ -47,8 +49,13 @@ public: const QString& arguments, const QString& workDir, const QStringList& extraBinDir); - void runProblem(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase); - void runProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector &problemCases); + void runProblem( + const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase, + const POJProblem& problem + ); + void runProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector &problemCases, + const POJProblem& problem + ); void stopRun(); void stopAllRunners(); void stopPausing(); @@ -67,7 +74,9 @@ signals: void signalStopAllRunners(); private slots: - void doRunProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector &problemCases); + void doRunProblem(const QString& filename, const QString& arguments, const QString& workDir, const QVector &problemCases, + const POJProblem& problem + ); void onRunnerTerminated(); void onRunnerPausing(); void onCompileFinished(); diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp index f3ac04d8..a3a8f44b 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp @@ -21,12 +21,16 @@ #include "../widgets/ojproblemsetmodel.h" #include #include +#ifdef Q_OS_WINDOWS +#include +#endif OJProblemCasesRunner::OJProblemCasesRunner(const QString& filename, const QString& arguments, const QString& workDir, const QVector& problemCases, QObject *parent): Runner(filename,arguments,workDir,parent), - mExecTimeout(-1) + mExecTimeout(0), + mMemoryLimit(0) { mProblemCases = problemCases; mBufferSize = 8192; @@ -37,7 +41,8 @@ OJProblemCasesRunner::OJProblemCasesRunner(const QString& filename, const QStrin OJProblemCasesRunner::OJProblemCasesRunner(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase, QObject *parent): Runner(filename,arguments,workDir,parent), - mExecTimeout(-1) + mExecTimeout(0), + mMemoryLimit(0) { mProblemCases.append(problemCase); mBufferSize = 8192; @@ -88,6 +93,12 @@ void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) problemCase->output.clear(); process.start(); process.waitForStarted(5000); +#ifdef Q_OS_WIN + HANDLE hProcess = NULL; + if (process.processId()!=0) { + hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,process.processId()); + } +#endif if (process.state()==QProcess::Running) { if (fileExists(problemCase->inputFileName)) process.write(readFileToByteArray(problemCase->inputFileName)); @@ -133,8 +144,22 @@ void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) } } problemCase->runningTime=elapsedTimer.elapsed(); + problemCase->runningMemory = 0; +#ifdef Q_OS_WIN + if (hProcess!=NULL) { + PROCESS_MEMORY_COUNTERS counter{0}; + counter.cb = sizeof(counter); + if (GetProcessMemoryInfo(hProcess,&counter, + sizeof(counter))){ + problemCase->runningMemory = counter.PeakWorkingSetSize; + } + } +#endif if (execTimeouted) { - problemCase->output = tr("Case Timeout"); + problemCase->output = tr("Time limit exceeded!"); + emit resetOutput(problemCase->getId(), problemCase->output); + } else if (mMemoryLimit>0 && problemCase->runningMemory>mMemoryLimit) { + problemCase->output = tr("Memory limit exceeded!"); emit resetOutput(problemCase->getId(), problemCase->output); } else { if (process.state() == QProcess::ProcessState::NotRunning) @@ -142,6 +167,7 @@ void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) emit newOutputGetted(problemCase->getId(),QString::fromLocal8Bit(buffer)); output.append(buffer); problemCase->output = QString::fromLocal8Bit(output); + if (errorOccurred) { //qDebug()<<"process error:"<& problemCases, QObject *parent = nullptr); + const QVector& problemCases, + QObject *parent = nullptr); explicit OJProblemCasesRunner(const QString& filename, const QString& arguments, const QString& workDir, - POJProblemCase problemCase, QObject *parent = nullptr); + POJProblemCase problemCase, + QObject *parent = nullptr); //max size of output buffer int bufferSize() const; void setBufferSize(int newBufferSize); @@ -43,6 +45,8 @@ public: int execTimeout() const; void setExecTimeout(int newExecTimeout); + void setMemoryLimit(size_t limit); + signals: void caseStarted(const QString &caseId, int current, int total); void caseFinished(const QString &caseId, int current, int total); @@ -60,6 +64,7 @@ private: int mBufferSize; int mOutputRefreshTime; int mExecTimeout; + size_t mMemoryLimit; }; #endif // OJPROBLEMCASESRUNNER_H diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 0ed57dea..337fabc3 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -94,6 +94,7 @@ #ifdef Q_OS_WIN #include #include +#include #include #endif @@ -1933,7 +1934,8 @@ void MainWindow::runExecutable( POJProblem problem = mOJProblemModel.problem(); if (problem) { mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), - problem->cases); + problem->cases, + problem); stretchMessagesPanel(true); ui->tabMessages->setCurrentWidget(ui->tabProblem); } @@ -1941,8 +1943,10 @@ void MainWindow::runExecutable( QModelIndex index = ui->tblProblemCases->currentIndex(); if (index.isValid()) { POJProblemCase problemCase =mOJProblemModel.getCase(index.row()); + POJProblem problem = mOJProblemModel.problem(); mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), - problemCase); + problemCase, + problem); stretchMessagesPanel(true); ui->tabMessages->setCurrentWidget(ui->tabProblem); } @@ -2675,6 +2679,20 @@ void MainWindow::buildContextMenus() connect(mProblem_OpenSource, &QAction::triggered, this, &MainWindow::onProblemOpenSource); + mProblem_Rename=createActionFor( + tr("Rename Problem"), + ui->lstProblemSet + ); + connect(mProblem_Rename, &QAction::triggered, this, + &MainWindow::onProblemRename); + + mProblem_GotoUrl=createActionFor( + tr("Goto Url"), + ui->lstProblemSet + ); + connect(mProblem_GotoUrl, &QAction::triggered, this, + &MainWindow::onProblemGotoUrl); + //context menu signal for the problem list view ui->tblProblemCases->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->tblProblemCases, &QWidget::customContextMenuRequested, @@ -3558,6 +3576,9 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos) QMenu menu(this); QModelIndex idx = ui->lstProblemSet->currentIndex(); mProblem_Properties->setEnabled(idx.isValid()); + mProblem_Rename->setEnabled(idx.isValid()); + menu.addAction(mProblem_Rename); + menu.addAction(mProblem_GotoUrl); if (idx.isValid()) { POJProblem problem = mOJProblemSetModel.problem(idx.row()); QMenu * menuSetAnswer = new QMenu(&menu); @@ -3614,7 +3635,11 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos) }); menuSetAnswer->addAction(action); menu.addMenu(menuSetAnswer); + mProblem_GotoUrl->setEnabled(!problem->url.isEmpty()); mProblem_OpenSource->setEnabled(!problem->answerProgram.isEmpty()); + } else { + mProblem_GotoUrl->setEnabled(false); + mProblem_OpenSource->setEnabled(false); } menu.addAction(mProblem_OpenSource); menu.addAction(mProblem_Properties); @@ -4044,15 +4069,9 @@ void MainWindow::onProblemProperties() if (!problem) return; OJProblemPropertyWidget dialog; - dialog.setName(problem->name); - dialog.setUrl(problem->url); - dialog.setDescription(problem->description); + dialog.loadFromProblem(problem); if (dialog.exec() == QDialog::Accepted) { - problem->url = dialog.url(); - problem->description = dialog.description(); - if (problem == mOJProblemModel.problem()) { - updateProblemTitle(); - } + dialog.saveToProblem(problem); } } @@ -4069,6 +4088,27 @@ void MainWindow::onProblemOpenSource() } } +void MainWindow::onProblemRename() +{ + QModelIndex idx = ui->lstProblemSet->currentIndex(); + if (!idx.isValid()) + return; + ui->lstProblemSet->edit(idx); +} + +void MainWindow::onProblemGotoUrl() +{ + QModelIndex idx = ui->lstProblemSet->currentIndex(); + if (!idx.isValid()) + return; + POJProblem problem=mOJProblemSetModel.problem(idx.row()); + if (!problem) + return; + if (!problem->url.isEmpty()) { + QDesktopServices::openUrl(problem->url); + } +} + void MainWindow::onLableProblemSetContextMenuRequested() { QString newName = QInputDialog::getText( @@ -8920,12 +8960,13 @@ void MainWindow::on_btnImportFPS_clicked() try { QList problems = importFreeProblemSet(fileName); mOJProblemSetModel.addProblems(problems); + ui->lblProblemSet->setText(mOJProblemSetModel.name()); + ui->lstProblemSet->setCurrentIndex(mOJProblemSetModel.index(0,0)); } catch (FileError& error) { QMessageBox::critical(this,tr("Load Error"), error.reason()); } } - ui->lblProblemSet->setText(mOJProblemSetModel.name()); - ui->lstProblemSet->setCurrentIndex(mOJProblemSetModel.index(0,0)); } + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 6127b231..724fba67 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -348,6 +348,9 @@ private slots: void onFilesViewRename(); void onProblemProperties(); void onProblemOpenSource(); + void onProblemRename(); + void onProblemGotoUrl(); + void onLableProblemSetContextMenuRequested(); void onBookmarkRemove(); void onBookmarkRemoveAll(); @@ -881,6 +884,9 @@ private: //action for problem set QAction * mProblem_OpenSource; QAction * mProblem_Properties; + QAction * mProblem_Rename; + QAction * mProblem_GotoUrl; + //action for problem QAction * mProblem_RunCurrentCase; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 42cf3c04..27969bf3 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -912,7 +912,7 @@ QTabWidget::South - 2 + 6 diff --git a/RedPandaIDE/problems/freeprojectsetformat.cpp b/RedPandaIDE/problems/freeprojectsetformat.cpp index 95970215..e8e71012 100644 --- a/RedPandaIDE/problems/freeprojectsetformat.cpp +++ b/RedPandaIDE/problems/freeprojectsetformat.cpp @@ -35,17 +35,27 @@ QList importFreeProblemSet(const QString &filename) currentCase->name = QObject::tr("Problem Case %1").arg(currentProblem->cases.count()+1); } else if (currentProblem && xml.name()=="time_limit") { + currentEleName = xml.name().toString(); foreach (const QXmlStreamAttribute& attr, xml.attributes()) { - if (attr.name() == "unit" && attr.value()=="ms") { - currentEleName = attr.name().toString(); + if (attr.name() == "unit") { + if (attr.value()=="ms") + currentProblem->timeLimitUnit = ProblemTimeLimitUnit::Milliseconds; + else if (attr.value()=="s") + currentProblem->timeLimitUnit = ProblemTimeLimitUnit::Seconds; break; } } } else if (currentProblem && xml.name()=="memory_limit") { + currentEleName = xml.name().toString(); foreach (const QXmlStreamAttribute& attr, xml.attributes()) { - if (attr.name() == "unit" && attr.value()=="mb") { - currentEleName = attr.name().toString(); + if (attr.name() == "unit") { + if (attr.value()=="mb") + currentProblem->memoryLimitUnit = ProblemMemoryLimitUnit::MB; + else if (attr.value()=="kb") + currentProblem->memoryLimitUnit = ProblemMemoryLimitUnit::KB; + else if (attr.value()=="gb") + currentProblem->memoryLimitUnit = ProblemMemoryLimitUnit::GB; break; } } @@ -70,7 +80,7 @@ QList importFreeProblemSet(const QString &filename) } else if (currentProblem && currentEleName=="hint") { currentProblem->hint = xml.text().toString(); } else if (currentProblem && currentEleName=="title") { - currentProblem->name = xml.text().toString().trimmed(); + currentProblem->name = xml.text().toString().trimmed().replace(" "," "); } else if (currentProblem && currentEleName=="url") { currentProblem->url = xml.text().toString().trimmed(); } else if (currentProblem && currentEleName=="time_limit") { diff --git a/RedPandaIDE/problems/ojproblemset.cpp b/RedPandaIDE/problems/ojproblemset.cpp index 8f67bb3c..449f917d 100644 --- a/RedPandaIDE/problems/ojproblemset.cpp +++ b/RedPandaIDE/problems/ojproblemset.cpp @@ -28,3 +28,34 @@ const QString &OJProblemCase::getId() const { return id; } + +size_t OJProblem::getTimeLimit() +{ + switch(timeLimitUnit) { + case ProblemTimeLimitUnit::Seconds: + return timeLimit*1000; + default: + return timeLimit; + } +} + +size_t OJProblem::getMemoryLimit() +{ + switch(memoryLimitUnit) { + case ProblemMemoryLimitUnit::KB: + return memoryLimit*1024; + case ProblemMemoryLimitUnit::MB: + return memoryLimit*1024*1024; + default: + return memoryLimit*1024*1024*1024; + } +} + +OJProblem::OJProblem() : + timeLimit(0), + memoryLimit(0), + timeLimitUnit(ProblemTimeLimitUnit::Milliseconds), + memoryLimitUnit(ProblemMemoryLimitUnit::MB) +{ + +} diff --git a/RedPandaIDE/problems/ojproblemset.h b/RedPandaIDE/problems/ojproblemset.h index deefb709..4de5d7bd 100644 --- a/RedPandaIDE/problems/ojproblemset.h +++ b/RedPandaIDE/problems/ojproblemset.h @@ -27,6 +27,17 @@ enum class ProblemCaseTestState { Failed }; +enum class ProblemTimeLimitUnit { + Seconds, + Milliseconds +}; + +enum class ProblemMemoryLimitUnit { + KB, + MB, + GB +}; + struct OJProblemCase { QString name; QString input; @@ -35,9 +46,10 @@ struct OJProblemCase { QString expectedOutputFileName; ProblemCaseTestState testState; // no persistence QString output; // no persistence - int runningTime; - int firstDiffLine; - int outputLineCounts; + size_t runningTime; // no persistence + size_t runningMemory; // no persistence; + int firstDiffLine; // no persistence + int outputLineCounts; // no persistence int expectedLineCounts; OJProblemCase(); @@ -56,9 +68,14 @@ struct OJProblem { QString description; QString hint; QString answerProgram; - int timeLimit; // ms - int memoryLimit; // mb + size_t timeLimit; + size_t memoryLimit; + ProblemTimeLimitUnit timeLimitUnit; + ProblemMemoryLimitUnit memoryLimitUnit; QVector cases; + size_t getTimeLimit(); + size_t getMemoryLimit(); + OJProblem(); }; using POJProblem = std::shared_ptr; diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 671a9774..bd51e4f9 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -26,8 +26,6 @@ #include #include #include -#include -#include #ifdef Q_OS_LINUX #include #endif @@ -334,6 +332,11 @@ int Settings::_Base::intValue(const QString &key, int defaultValue) return value(key,defaultValue).toInt(); } +unsigned int Settings::_Base::uintValue(const QString &key, unsigned int defaultValue) +{ + return value(key,defaultValue).toUInt(); +} + QStringList Settings::_Base::stringListValue(const QString &key, const QStringList &defaultValue) { return value(key,defaultValue).toStringList(); @@ -3478,24 +3481,34 @@ void Settings::Executor::setCaseEditorFontOnlyMonospaced(bool newCaseEditorFontO mCaseEditorFontOnlyMonospaced = newCaseEditorFontOnlyMonospaced; } -int Settings::Executor::caseTimeout() const +size_t Settings::Executor::caseTimeout() const { return mCaseTimeout; } -void Settings::Executor::setCaseTimeout(int newCaseTimeout) +void Settings::Executor::setCaseTimeout(size_t newCaseTimeout) { mCaseTimeout = newCaseTimeout; } -bool Settings::Executor::enableCaseTimeout() const +size_t Settings::Executor::caseMemoryLimit() const { - return mEnableCaseTimeout; + return mCaseMemoryLimit; } -void Settings::Executor::setEnableCaseTimeout(bool newEnableCaseTimeout) +void Settings::Executor::setCaseMemoryLimit(size_t newCaseMemoryLimit) { - mEnableCaseTimeout = newEnableCaseTimeout; + mCaseMemoryLimit = newCaseMemoryLimit; +} + +bool Settings::Executor::enableCaseLimit() const +{ + return mEnableCaseLimit; +} + +void Settings::Executor::setEnableCaseLimit(bool newValue) +{ + mEnableCaseLimit = newValue; } int Settings::Executor::caseEditorFontSize() const @@ -3555,8 +3568,9 @@ void Settings::Executor::doSave() saveValue("case_editor_font_size",mCaseEditorFontSize); saveValue("case_editor_font_only_monospaced",mCaseEditorFontOnlyMonospaced); saveValue("case_timeout_ms", mCaseTimeout); + saveValue("case_memory_limit",mCaseMemoryLimit); remove("case_timeout"); - saveValue("enable_case_timeout", mEnableCaseTimeout); + saveValue("enable_case_limit", mEnableCaseLimit); } bool Settings::Executor::pauseConsole() const @@ -3595,8 +3609,14 @@ void Settings::Executor::doLoad() if (case_timeout>0) mCaseTimeout = case_timeout*1000; else - mCaseTimeout = intValue("case_timeout_ms", 2000); - mEnableCaseTimeout = boolValue("enable_case_timeout", true); + mCaseTimeout = uintValue("case_timeout_ms", 2000); //2000ms + mCaseMemoryLimit = uintValue("case_memory_limit",0); // kb + + mEnableCaseLimit = boolValue("enable_case_limit", true); + //compatibility + if (boolValue("enable_time_limit", true)) { + mEnableCaseLimit=true; + } } diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index c42bde7c..5cdeec53 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -69,6 +69,7 @@ private: bool boolValue(const QString &key, bool defaultValue); QSize sizeValue(const QString &key); int intValue(const QString &key, int defaultValue); + unsigned int uintValue(const QString &key, unsigned int defaultValue); QStringList stringListValue(const QString &key, const QStringList& defaultValue=QStringList()); QSet stringSetValue(const QString &key); QColor colorValue(const QString &key, const QColor& defaultValue); @@ -874,11 +875,14 @@ public: bool caseEditorFontOnlyMonospaced() const; void setCaseEditorFontOnlyMonospaced(bool newCaseEditorFontOnlyMonospaced); - bool enableCaseTimeout() const; - void setEnableCaseTimeout(bool newEnableCaseTimeout); + bool enableCaseLimit() const; + void setEnableCaseLimit(bool newValue); - int caseTimeout() const; - void setCaseTimeout(int newCaseTimeout); + size_t caseTimeout() const; + void setCaseTimeout(size_t newCaseTimeout); + + size_t caseMemoryLimit() const; + void setCaseMemoryLimit(size_t newCaseMemoryLimit); private: // general @@ -897,8 +901,9 @@ public: QString mCaseEditorFontName; int mCaseEditorFontSize; bool mCaseEditorFontOnlyMonospaced; - bool mEnableCaseTimeout; - int mCaseTimeout; + bool mEnableCaseLimit; + size_t mCaseTimeout; //ms + size_t mCaseMemoryLimit; //kb protected: void doSave() override; diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp b/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp index 1b0f4100..15173944 100644 --- a/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp @@ -41,9 +41,10 @@ void ExecutorProblemSetWidget::doLoad() ui->cbFont->setCurrentFont(QFont(pSettings->executor().caseEditorFontName())); ui->spinFontSize->setValue(pSettings->executor().caseEditorFontSize()); ui->chkOnlyMonospaced->setChecked(pSettings->executor().caseEditorFontOnlyMonospaced()); - ui->grpEnableTimeout->setChecked(pSettings->executor().enableCaseTimeout()); + ui->grpEnableTimeout->setChecked(pSettings->executor().enableCaseLimit()); ui->spinCaseTimeout->setValue(pSettings->executor().caseTimeout()); + ui->spinMemoryLimit->setValue(pSettings->executor().caseMemoryLimit()); } void ExecutorProblemSetWidget::doSave() @@ -55,8 +56,10 @@ void ExecutorProblemSetWidget::doSave() pSettings->executor().setCaseEditorFontName(ui->cbFont->currentFont().family()); pSettings->executor().setCaseEditorFontOnlyMonospaced(ui->chkOnlyMonospaced->isChecked()); pSettings->executor().setCaseEditorFontSize(ui->spinFontSize->value()); - pSettings->executor().setEnableCaseTimeout(ui->grpEnableTimeout->isChecked()); + pSettings->executor().setEnableCaseLimit(ui->grpEnableTimeout->isChecked()); pSettings->executor().setCaseTimeout(ui->spinCaseTimeout->value()); + pSettings->executor().setCaseMemoryLimit(ui->spinMemoryLimit->value()); + pSettings->executor().save(); pMainWindow->applySettings(); } diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui b/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui index 7b69f1d5..58be4c4e 100644 --- a/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui @@ -75,13 +75,20 @@ - Timeout for Case Valdation + Case Valdation Limit true - - + + + + + Time Limit + + + + @@ -90,7 +97,7 @@ ms - 100 + 0 1000000 @@ -100,7 +107,7 @@ - + Qt::Horizontal @@ -113,6 +120,23 @@ + + + + Memory Limit + + + + + + + kb + + + 999999 + + + diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index d242e743..b8aaa0cd 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -1867,7 +1867,7 @@ Timeout for Case Valdation - Tempo limite para validação de caso + Tempo limite para validação de caso Case Editor Font @@ -1889,6 +1889,22 @@ ms ms + + Case Valdation Limit + + + + Time Limit + + + + Memory Limit + + + + kb + + FileAssociationModel @@ -4737,7 +4753,15 @@ - FPS Problem Set Files (*.fps) + Rename Problem + + + + Goto Url + + + + FPS Problem Set Files (*.fps;*.xml) @@ -4932,7 +4956,7 @@ OJProblemCasesRunner Case Timeout - Tempo esgotado para o caso + Tempo esgotado para o caso The runner process '%1' failed to start. @@ -4950,6 +4974,14 @@ An error occurred when attempting to read from the runner process. Falhar ao tentar ler a execução do processo. + + Time limit exceeded! + + + + Memory limit exceeded! + + OJProblemModel @@ -4961,6 +4993,10 @@ Time(ms) Tempo(ms) + + Memory(kb) + + OJProblemPropertyWidget @@ -4988,6 +5024,34 @@ Cancel Cancelar + + Time Limit + + + + Memory Limit + + + + sec + + + + ms + ms + + + KB + KB + + + MB + MB + + + GB + GB + Project diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index 3a887d4c..0325edf1 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -2525,11 +2525,30 @@ Are you really want to continue? - Timeout for Case Valdation - 试题案例超时时间 + Case Valdation Limit + 测试案例验证的资源限制 - + + Time Limit + 时间限制 + + + + Memory Limit + 内存限制 + + + + kb + kb + + + Timeout for Case Valdation + 试题案例超时时间 + + + ms 毫秒 @@ -2538,22 +2557,22 @@ Are you really want to continue? - + Case Editor Font 试题案例数据编辑字体 - + Font Size: 大小: - + Font: 字体: - + Only Monospaced 仅使用等宽字体 @@ -3918,18 +3937,18 @@ Are you really want to continue? MainWindow - + Red Panda C++ 小熊猫C++ - - - - - + + + + + Issues 编译器 @@ -4003,7 +4022,7 @@ Are you really want to continue? - + Debug Console 调试主控台 @@ -4079,7 +4098,7 @@ Are you really want to continue? 工具栏2 - + New 新建 @@ -4137,8 +4156,8 @@ Are you really want to continue? - - + + Compile 编译 @@ -4216,9 +4235,9 @@ Are you really want to continue? - - - + + + Copy 复制 @@ -4229,7 +4248,7 @@ Are you really want to continue? - + Paste 粘贴 @@ -4240,8 +4259,8 @@ Are you really want to continue? - - + + Select All 选择全部 @@ -4367,7 +4386,7 @@ Are you really want to continue? - + New Problem Set 新建试题集 @@ -4386,14 +4405,14 @@ Are you really want to continue? - + Save Problem Set 保存试题集 - + Load Problem Set 载入试题集 @@ -4454,7 +4473,7 @@ Are you really want to continue? - + Run All Cases Run Current Case 运行所有案例 @@ -4520,7 +4539,7 @@ Are you really want to continue? - + Import FPS Problem Set 导入FPS试题集 @@ -4752,7 +4771,7 @@ Are you really want to continue? - + Clear all breakpoints 删除所有断点 @@ -4953,7 +4972,7 @@ Are you really want to continue? - + New File 新建文件 @@ -4994,7 +5013,7 @@ Are you really want to continue? - + Rename Symbol 重命名符号 @@ -5015,13 +5034,13 @@ Are you really want to continue? - + Export As RTF 导出为RTF - + Export As HTML 导出为HTML @@ -5290,42 +5309,42 @@ Are you really want to continue? 运行参数... - + File Encoding 文件编码 - + Recent Files 文件历史 - - - - - - + + + + + + Debugging 正在调试 - - - - - - + + + + + + Running 正在运行 - - - - - - + + + + + + Compiling 正在编译 @@ -5334,23 +5353,23 @@ Are you really want to continue? 行:%1 列:%2 已选择:%3 总行数:%4 总长度:%5 - + Line:%1 Col:%2 Selected:%3 Lines:%4 Length:%5 Line: %1 Col: %2 Selected: %3 Lines: %4 Length: %5 行: %1 列: %2 已选择 :%3 总行数: %4 总长度: %5 - + Read Only 只读 - + Insert 插入 - + Overwrite 覆写 @@ -5363,133 +5382,133 @@ Are you really want to continue? 你确定要关闭'%1'吗? - - + + Confirm 确认 - - - + + + Source file is not compiled. 源文件尚未编译。 - - + + Compile now? 现在编译? - - + + Source file is more recent than executable. 源文件比可执行程序新。 - + Recompile now? 重新编译? - - - - + + + + Wrong Compiler Settings 错误的编译器设置 - - - - + + + + Compiler is set not to generate executable. 编译器被设置为不生成可执行文件。 - - + + We need the executabe to run problem case. 我们需要可执行文件来运行试题案例。 - + No compiler set 无编译器设置 - + No compiler set is configured. 没有配置编译器设置。 - + Can't start debugging. 无法启动调试器 - - + + Enable debugging 启用调试参数 - - + + You have not enabled debugging info (-g3) and/or stripped it from the executable (-s) in Compiler Options.<BR /><BR />Do you want to correct this now? 当前编译设置中未启用调试选项(-g3),或启用了信息剥除选项(-s)<br /><br/>是否纠正这一问题? - + Project not built 项目尚未构建 - + Project hasn't been built. Build it now? 项目尚未构建。是否构建? - + Host applcation missing 宿主程序不存在 - + DLL project needs a host application to run. 动态链接库(DLL)需要一个宿主程序来运行。 - + But it's missing. 但它不存在。 - + Host application not exists 宿主程序不存在 - + Host application file '%1' doesn't exist. 宿主程序'%1'不存在。 - - + + Please correct this before start debugging 请在调试前改正设置。 - + Recompile? 重新编译? - - + + Save last open info error 保存上次打开信息失败 @@ -5498,60 +5517,60 @@ Are you really want to continue? 无法删除旧上次打开信息文件'%1' - + Can't save last open info file '%1' 无法保存上次打开信息文件'%1' - - + + Load last open info error 载入上次打开信息失败 - - + + Can't load last open info file '%1' 无法载入上次打开信息文件'%1' - + Open Source File 打开源代码文件 - - + + Batch Set Cases 批量设置案例 - + Show detail debug logs 显示详细调试器日志 - + Copy all 全部复制 - + Go to Line 跳转到行 - + Line - + Template Exists 模板已存在 - + Template %1 already exists. Do you want to overwrite? 模板%1已存在。是否覆盖? @@ -5559,25 +5578,25 @@ Are you really want to continue? - - - + + + Clear 清除 - + Export 导出 - + Insert Snippet 插入代码段 - - + + Problem Set %1 试题集%1 @@ -5598,68 +5617,68 @@ Are you really want to continue? 或者选择使用其他的网络端口。 - - + + Rebuild Project 重新构建项目 - - + + Project has been modified, do you want to rebuild it? 项目已经被修改过,是否需要重新构建? - + Auto Save Error 自动保存出错 - + Auto save "%1" to "%2" failed:%3 自动保存"%1"到"%2"失败:%3 - + Properties... 试题属性... - + Set Problem Set Name 设置试题集名称 - + Problem Set Name: 试题集名称: - + Remove 删除 - + Remove All Bookmarks 删除全部书签 - + Modify Description 修改描述 - - - + + + Bookmark Description 书签描述 - - - + + + Description: 描述: @@ -5668,201 +5687,215 @@ Are you really want to continue? 在调试主控台中显示调试器输出 - + Remove this search 清除这次搜索 - + Clear all searches 删除所有搜索 - + Breakpoint condition... 断点条件... - + Break point condition 断点条件 - + Enter the condition of the breakpoint: 输入当前断点的生效条件: - + Remove All Breakpoints Remove all breakpoints 删除所有断点 - + Remove Breakpoint 删除当前断点 - + Rename File 重命名文件 - - + + Add Folder 添加文件夹 - - + + New folder 新文件夹 - + Folder name: 文件夹: - + Rename Folder 重命名 - + Can't open last open information file '%1' for write! 无法写入配置文件'%1'。 - + + Rename Problem + 修改试题名称 + + + + Goto Url + 跳转到试题网址 + + + Run Current Case 运行当前案例 - + Remove Folder 删除文件夹 - + Switch to normal view 切换为普通视图 - + Switch to custom view 切换为自定义视图 - + Sort By Type 按类型排序 - + Sort alphabetically 按名称排序 - + Show inherited members 显示继承的成员 - + Goto declaration 跳转到声明处 - + Goto definition 跳转到定义处 - + In current file 仅当前文件 - + In current project 整个项目 - - + + New Folder 新建文件夹 - + Rename 重命名 - - - - + + + + Delete 删除 - + Open in Editor 在编辑器中打开 - + Open in External Program 使用外部程序打开 - + Open in Terminal 在终端中打开 - + Open in Windows Explorer 在Windows浏览器中打开 - + Character sets 字符集 - + Convert to %1 转换为%1编码 - + %1 files autosaved 已自动保存%1个文件 - + Set answer to... 设置答案源代码... - + select other file... 选择其他文件... - + Select Answer Source File 选择答案源代码文件 - + + FPS Problem Set Files (*.fps;*.xml) + FPS试题集文件(*.fps;*.xml) + + FPS Problem Set Files (*.fps) - FPS试题集文件(*.fps) + FPS试题集文件(*.fps) C/C++Source Files (*.c *.cpp *.cc *.cxx) @@ -5870,7 +5903,7 @@ Are you really want to continue? C/C++源代码文件 (*.c *.cpp *.cc *.cxx) - + New Folder %1 新建文件夹%1 @@ -5883,68 +5916,68 @@ Are you really want to continue? 无标题%1 - + Do you really want to delete %1? 你真的要删除%1吗? - + Do you really want to delete %1 files? 你真的要删除%1个文件吗? - + Save project 保存项目 - + The project '%1' has modifications. 项目'%1'有改动。 - - + + Do you want to save it? 需要保存吗? - - + + File Changed 文件已发生变化 - + New Project File? 新建项目文件? - + Do you want to add the new file to the project? 您是否要将新建的文件加入项目? - - - - + + + + Save Error 保存失败 - + Change Project Compiler Set 改变项目编译器配置集 - + Change the project's compiler set will lose all custom compiler set options. 改变项目的编译器配置集会导致所有的自定义编译器选项被重置。 - - + + Do you really want to do that? 你真的想要那么做吗? @@ -5953,12 +5986,12 @@ Are you really want to continue? 批量设置案例 - + Choose input files 选择输入数据文件 - + Input data files (*.in) 输入数据文件 (*.in) @@ -5967,104 +6000,104 @@ Are you really want to continue? 无标题%1 - + Modify Watch 修改监视表达式 - + Watch Expression 监视表达式 - + Do you really want to clear all breakpoints in this file? 您真的要清除该文件的所有断点吗? - + New project 新建项目 - + Close %1 and start new project? 关闭'%1'以打开新项目? - + Folder not exist 文件夹不存在 - + Folder '%1' doesn't exist. Create it now? 文件夹'%1'不存在。是否创建? - + Can't create folder 无法创建文件夹 - + Failed to create folder '%1'. 创建文件夹'%1'失败。 - + Save new project as - + Folder %1 is not empty. 文件夹%1不是空的。 - + Do you really want to delete it? 你真的要删除它吗? - + Change working folder 改变工作文件夹 - + File '%1' is not in the current working folder. File '%1' is not in the current working folder 文件'%1'不在当前工作文件夹中。 - + Do you want to change working folder to '%1'? 是否将工作文件夹改设为'%1'? - + Can't Commit 无法提交 - + Git needs user info to commit. Git需要用信息进行提交。 - + Choose Input Data File 选择输入数据文件 - - + + All files (*.*) 所有文件 (*.*) - + Choose Expected Output Data File Choose Expected Input Data File 选择期望输出文件 @@ -6076,59 +6109,59 @@ Are you really want to continue? - + Choose Working Folder 选择工作文件夹 - - + + Header Exists 头文件已存在 - - + + Header file "%1" already exists! 头文件"%1"已存在! - + Source Exists 源文件已存在! - + Source file "%1" already exists! 源文件"%1"已存在! - + Can't commit! 无法提交! - + The following files are in conflicting: 下列文件处于冲突状态,请解决后重新添加和提交: - + Commit Message 提交信息 - + Commit Message: 提交信息: - + Commit Failed 提交失败 - + Commit message shouldn't be empty! 提交信息不能为空! @@ -6137,22 +6170,22 @@ Are you really want to continue? 小熊猫Dev-C++项目文件 (*.dev) - + New project fail 新建项目失败 - + Can't assign project template 无法使用模板创建项目 - + Remove file 删除文件 - + Remove the file from disk? 同时从硬盘上删除文件? @@ -6161,230 +6194,230 @@ Are you really want to continue? 无标题 - + New Project File Name 新的项目文件名 - + File Name: 文件名: - + File Already Exists! 文件已存在! - + File '%1' already exists! 文件'%1'已经存在! - + Add to project 添加到项目 - + C/C++ Source Files (*.c *.cpp *.cc *.cxx) C/C++源代码文件 (*.c *.cpp *.cc *.cxx) - + This operation will remove all cases for the current problem. 本操作会删除此试题的所有案例。 - + Red Panda C++ project file (*.dev) 小熊猫C++项目文件(*.dev) - + Rename Error 重命名出错 - + Symbol '%1' is defined in system header. 符号'%1'在系统头文件中定义,无法修改。 - + New Name 新名称 - - + + Replace Error 替换出错 - + Can't open file '%1' for replace! 无法打开文件'%1'进行替换! - + Contents has changed since last search! 内容和上次查找时不一致。 - + Rich Text Format Files (*.rtf) RTF格式文件 (*.rtf) - + HTML Files (*.html) HTML文件 (*.html) - + The current problem set is not empty. 当前的试题集不是空的。 - + Problem %1 试题%1 - - + + Problem Set Files (*.pbs) 试题集文件 (*.pbs) - - + + Load Error 载入失败 - - + + Problem Case %1 试题案例%1 - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + Error 错误 - + Recent Projects 项目历史 - + Load Theme Error 载入主题失败 - - + + Clear History 清除历史 - - + + Version Control 版本控制 - + File '%1' was changed. 磁盘文件'%1'已被修改。 - + Reload its content from disk? 是否重新读取它的内容? - + File '%1' was removed. 磁盘文件'%1'已被删除。 - + Keep it open? 是否保持它在小熊猫C++中打开的编辑窗口? - + Open 打开 - + Compile Failed 编译失败 - + Run Failed 运行失败 - - - - + + + + Confirm Convertion 确认转换 - - - - + + + + The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue? 当前编辑器中的文件将会使用%1编码保存。<br />这项操作无法被撤回。<br />你确定要继续吗? - + New Watch Expression 新监视表达式 - + Enter Watch Expression (it is recommended to use 'this->' for class members): 输入监视表达式 - + Parsing file %1 of %2: "%3" (%1/%2)正在解析文件"%3" - - + + Done parsing %1 files in %2 seconds 完成%1个文件的解析,用时%2秒 - + (%1 files per second) (每秒%1个文件) @@ -6638,27 +6671,36 @@ Are you really want to continue? OJProblemCasesRunner - Case Timeout - 案例运行超时 + 案例运行超时 - + + Time limit exceeded! + 运行时间超限! + + + + Memory limit exceeded! + 运行内存超限! + + + The runner process '%1' failed to start. 无法启动程序运行进程'%1'。 - + The last waitFor...() function timed out. waitFor()函数等待超时。 - + An error occurred when attempting to write to the runner process. 在向程序运行进程写入内容时出错。 - + An error occurred when attempting to read from the runner process. 在从程序运行进程读取内容时出错。 @@ -6666,16 +6708,21 @@ Are you really want to continue? OJProblemModel - + Name 名称 - + Time(ms) Time(sec) 时间(毫秒) + + + Memory(kb) + 内存(kb) + OJProblemPropertyWidget @@ -6690,7 +6737,7 @@ Are you really want to continue? URL - + TextLabel @@ -6699,16 +6746,51 @@ Are you really want to continue? Description 描述 + + + Time Limit + 时间限制 + + Memory Limit + 内存限制 + + + OK 确定 - + Cancel 取消 + + + sec + + + + + ms + 毫秒 + + + + KB + KB + + + + MB + MB + + + + GB + GB + Project @@ -7645,60 +7727,60 @@ Are you really want to continue? 无法载入自动链接设置 - - - - + + + + The following %1 directories don't exist: 下列%1文件夹不存在: - - + + binary 二进制 - + No %1 directories have been specified. 未指定%1文件夹 - + C include C包含 - - + + C++ include C++包含 - - - - + + + + Cannot find the %1 "%2" 无法找到%1程序"%2" - + C Compiler C编译器 - + C++ Compiler C++编译器 - + Maker 构建程序(Make) - + Debugger 调试器 @@ -7764,7 +7846,7 @@ Are you really want to continue? 生成调试信息(-g3) - + Would you like Red Panda C++ to search for compilers in PATH? 您同意小熊猫C++在PATH路径中寻找gcc编译器吗? @@ -7877,23 +7959,23 @@ Are you really want to continue? 只生成汇编代码(-S) - - + + Confirm 确认 - + The following problems were found during validation of compiler set "%1": 在验证编译器设置"%1"时遇到了下列问题: - + Leaving those directories will lead to problems during compilation. 在配置中保留这些文件夹可能会导致编译出错。 - + Would you like Red Panda C++ to remove them for you and add the default paths to the valid paths? 是否让小熊猫C++删除这些配置,并尝试重新建立配置? @@ -7902,13 +7984,13 @@ Are you really want to continue? 如果仍然保留这些设置,可能会导致编译错误。<br /><br />请选择“是”,除非您清楚的知道选择“否”的后果, - - + + Compiler set not configuared. 未配置编译器设置。 - + Would you like Red Panda C++ to search for compilers in the following locations: <BR />'%1'<BR />'%2'? 您需要小熊猫C++在下列位置搜索编译器吗:<br />%1<br />%2 @@ -8269,8 +8351,8 @@ Are you really want to continue? - - + + Can't open file '%1' for read. 无法读取文件'%1'. @@ -8283,7 +8365,7 @@ Are you really want to continue? 无法写入文件'%1'. - + Can't parse problem set file '%1':%2 无法解析试题集文件"%1":%2 @@ -8294,7 +8376,7 @@ Are you really want to continue? <由Git自动生成> - + Problem Case %1 试题案例%1 @@ -8971,14 +9053,14 @@ Are you really want to continue? 性能 - + Compiler Set 编译器配置集 - + Compiler @@ -8990,7 +9072,7 @@ Are you really want to continue? 自动链接 - + @@ -9067,15 +9149,15 @@ Are you really want to continue? 杂项 - - + + Program Runner 程序运行 - + Problem Set 试题集 diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index f0ae912e..63fc4c76 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -1754,10 +1754,6 @@ Ignore spaces when validating problem cases - - Timeout for Case Valdation - - Case Editor Font @@ -1778,6 +1774,22 @@ ms + + Case Valdation Limit + + + + Time Limit + + + + Memory Limit + + + + kb + + FileAssociationModel @@ -4578,7 +4590,15 @@ - FPS Problem Set Files (*.fps) + Rename Problem + + + + Goto Url + + + + FPS Problem Set Files (*.fps;*.xml) @@ -4759,10 +4779,6 @@ OJProblemCasesRunner - - Case Timeout - - The runner process '%1' failed to start. @@ -4779,6 +4795,14 @@ An error occurred when attempting to read from the runner process. + + Time limit exceeded! + + + + Memory limit exceeded! + + OJProblemModel @@ -4790,6 +4814,10 @@ Time(ms) + + Memory(kb) + + OJProblemPropertyWidget @@ -4817,6 +4845,34 @@ Cancel + + Time Limit + + + + Memory Limit + + + + sec + + + + ms + + + + KB + + + + MB + + + + GB + + Project diff --git a/RedPandaIDE/widgets/ojproblempropertywidget.cpp b/RedPandaIDE/widgets/ojproblempropertywidget.cpp index aa6789c3..2f46371e 100644 --- a/RedPandaIDE/widgets/ojproblempropertywidget.cpp +++ b/RedPandaIDE/widgets/ojproblempropertywidget.cpp @@ -16,12 +16,22 @@ */ #include "ojproblempropertywidget.h" #include "ui_ojproblempropertywidget.h" +#include "../problems/ojproblemset.h" OJProblemPropertyWidget::OJProblemPropertyWidget(QWidget *parent) : QDialog(parent), ui(new Ui::OJProblemPropertyWidget) { ui->setupUi(this); + QFont f = ui->lbName->font(); + f.setPixelSize(f.pixelSize()+2); + f.setBold(true); + ui->lbName->setFont(f); + ui->cbTimeLimitUnit->addItem(tr("sec")); + ui->cbTimeLimitUnit->addItem(tr("ms")); + ui->cbMemoryLimitUnit->addItem(tr("KB")); + ui->cbMemoryLimitUnit->addItem(tr("MB")); + ui->cbMemoryLimitUnit->addItem(tr("GB")); } OJProblemPropertyWidget::~OJProblemPropertyWidget() @@ -29,38 +39,55 @@ OJProblemPropertyWidget::~OJProblemPropertyWidget() delete ui; } -void OJProblemPropertyWidget::setName(const QString &name) +void OJProblemPropertyWidget::loadFromProblem(POJProblem problem) { - QFont f = ui->lbName->font(); - f.setPixelSize(f.pixelSize()+2); - f.setBold(true); - ui->lbName->setFont(f); - ui->lbName->setText(name); + if (!problem) + return; + ui->lbName->setText(problem->name); + ui->txtURL->setText(problem->url); + ui->txtDescription->setHtml(problem->description); + ui->spinMemoryLimit->setValue(problem->memoryLimit); + ui->spinTimeLimit->setValue(problem->timeLimit); + switch(problem->timeLimitUnit) { + case ProblemTimeLimitUnit::Seconds: + ui->cbTimeLimitUnit->setCurrentText(tr("sec")); + break; + case ProblemTimeLimitUnit::Milliseconds: + ui->cbTimeLimitUnit->setCurrentText(tr("ms")); + break; + } + switch(problem->memoryLimitUnit) { + case ProblemMemoryLimitUnit::KB: + ui->cbTimeLimitUnit->setCurrentText(tr("KB")); + break; + case ProblemMemoryLimitUnit::MB: + ui->cbTimeLimitUnit->setCurrentText(tr("MB")); + break; + case ProblemMemoryLimitUnit::GB: + ui->cbTimeLimitUnit->setCurrentText(tr("GB")); + break; + } } -void OJProblemPropertyWidget::setUrl(const QString &url) +void OJProblemPropertyWidget::saveToProblem(POJProblem problem) { - ui->txtURL->setText(url); -} - -void OJProblemPropertyWidget::setDescription(const QString &description) -{ - ui->txtDescription->setHtml(description); -} - -QString OJProblemPropertyWidget::name() -{ - return ui->lbName->text(); -} - -QString OJProblemPropertyWidget::url() -{ - return ui->txtURL->text(); -} - -QString OJProblemPropertyWidget::description() -{ - return ui->txtDescription->toHtml(); + if (!problem) + return; + problem->name = ui->lbName->text(); + problem->url = ui->txtURL->text(); + problem->description = ui->txtDescription->toHtml(); + problem->memoryLimit = ui->spinMemoryLimit->value(); + problem->timeLimit = ui->spinTimeLimit->value(); + if (ui->cbTimeLimitUnit->currentText()=="sec") + problem->timeLimitUnit = ProblemTimeLimitUnit::Seconds; + else + problem->timeLimitUnit = ProblemTimeLimitUnit::Milliseconds; + if (ui->cbTimeLimitUnit->currentText()=="KB") + problem->memoryLimitUnit = ProblemMemoryLimitUnit::KB; + else if (ui->cbTimeLimitUnit->currentText()=="MB") + problem->memoryLimitUnit = ProblemMemoryLimitUnit::MB; + else + problem->memoryLimitUnit = ProblemMemoryLimitUnit::GB; } void OJProblemPropertyWidget::on_btnOk_clicked() diff --git a/RedPandaIDE/widgets/ojproblempropertywidget.h b/RedPandaIDE/widgets/ojproblempropertywidget.h index e8de222b..3cb7dde7 100644 --- a/RedPandaIDE/widgets/ojproblempropertywidget.h +++ b/RedPandaIDE/widgets/ojproblempropertywidget.h @@ -18,11 +18,14 @@ #define OJPROBLEMPROPERTYWIDGET_H #include +#include namespace Ui { class OJProblemPropertyWidget; } +class OJProblem; +using POJProblem = std::shared_ptr; class OJProblemPropertyWidget : public QDialog { Q_OBJECT @@ -30,12 +33,8 @@ class OJProblemPropertyWidget : public QDialog public: explicit OJProblemPropertyWidget(QWidget *parent = nullptr); ~OJProblemPropertyWidget(); - void setName(const QString& name); - void setUrl(const QString& url); - void setDescription(const QString& description); - QString name(); - QString url(); - QString description(); + void loadFromProblem(POJProblem problem); + void saveToProblem(POJProblem problem); private slots: void on_btnOk_clicked(); diff --git a/RedPandaIDE/widgets/ojproblempropertywidget.ui b/RedPandaIDE/widgets/ojproblempropertywidget.ui index 2514028a..eedf6214 100644 --- a/RedPandaIDE/widgets/ojproblempropertywidget.ui +++ b/RedPandaIDE/widgets/ojproblempropertywidget.ui @@ -6,39 +6,107 @@ 0 0 - 400 - 300 + 460 + 364 Form - - + + URL - + + + + TextLabel - - - - + Description - + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Time Limit + + + + + + + Memory Limit + + + + + + + 9999999 + + + + + + + 9999999 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + @@ -83,9 +151,6 @@ - - - diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.cpp b/RedPandaIDE/widgets/ojproblemsetmodel.cpp index f300fab0..f524eb6a 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.cpp +++ b/RedPandaIDE/widgets/ojproblemsetmodel.cpp @@ -125,6 +125,10 @@ void OJProblemSetModel::saveToFile(const QString &fileName, int currentIndex) problemObj["name"]=problem->name; problemObj["url"]=problem->url; problemObj["description"]=problem->description; + problemObj["time_limit"]=(int)problem->timeLimit; + problemObj["memory_limit"]=(int)problem->memoryLimit; + problemObj["time_limit_unit"]=(int)problem->timeLimitUnit; + problemObj["memory_limit_unit"]=(int)problem->memoryLimitUnit; if (fileExists(problem->answerProgram)) problemObj["answer_program"] = problem->answerProgram; QJsonArray cases; @@ -184,6 +188,11 @@ void OJProblemSetModel::loadFromFile(const QString &fileName, int& currentIndex) POJProblem problem = std::make_shared(); problem->name = problemObj["name"].toString(); problem->url = problemObj["url"].toString(); + problem->timeLimit = problemObj["time_limit"].toInt(); + problem->memoryLimit = problemObj["memory_limit"].toInt(); + problem->timeLimitUnit = (ProblemTimeLimitUnit)problemObj["time_limit_unit"].toInt(); + problem->memoryLimitUnit = (ProblemMemoryLimitUnit)problemObj["memory_limit_unit"].toInt(); + problem->description = problemObj["description"].toString(); problem->answerProgram = problemObj["answer_program"].toString(); QJsonArray casesArray = problemObj["cases"].toArray(); @@ -252,6 +261,15 @@ QVariant OJProblemSetModel::data(const QModelIndex &index, int role) const return QVariant(); if (role == Qt::DisplayRole || role == Qt::EditRole) { return mProblemSet.problems[index.row()]->name; + } else if (role == Qt::ToolTipRole) { + POJProblem problem = mProblemSet.problems[index.row()]; + + QString s; + s=QString("

%1

").arg(problem->name); + if (!problem->description.isEmpty()) + s+=problem->description; + + return s; } return QVariant(); } @@ -479,6 +497,16 @@ QVariant OJProblemModel::data(const QModelIndex &index, int role) const return ""; } break; + case 2: + if (role == Qt::DisplayRole) { + POJProblemCase problemCase = mProblem->cases[index.row()]; + if (problemCase->testState == ProblemCaseTestState::Passed + || problemCase->testState == ProblemCaseTestState::Failed) + return problemCase->runningMemory/1024; + else + return ""; + } + break; } return QVariant(); @@ -515,7 +543,7 @@ Qt::ItemFlags OJProblemModel::flags(const QModelIndex &idx) const int OJProblemModel::columnCount(const QModelIndex &/*parent*/) const { - return 2; + return 3; } QVariant OJProblemModel::headerData(int section, Qt::Orientation orientation, int role) const @@ -526,6 +554,8 @@ QVariant OJProblemModel::headerData(int section, Qt::Orientation orientation, in return tr("Name"); case 1: return tr("Time(ms)"); + case 2: + return tr("Memory(kb)"); } } return QVariant();