From e82723c6f8fa06cbb9c142bc8aa51c05ccdeaf8b Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Mon, 1 Nov 2021 20:44:08 +0800 Subject: [PATCH] work save --- RedPandaIDE/RedPandaIDE.pro | 4 + RedPandaIDE/RedPandaIDE_zh_CN.ts | 580 ++++++++++-------- RedPandaIDE/compiler/compilermanager.cpp | 8 +- RedPandaIDE/compiler/ojproblemcasesrunner.cpp | 6 +- RedPandaIDE/compiler/ojproblemcasesrunner.h | 8 +- RedPandaIDE/iconsmanager.h | 1 - RedPandaIDE/mainwindow.cpp | 74 ++- RedPandaIDE/mainwindow.h | 15 +- RedPandaIDE/mainwindow.ui | 40 +- RedPandaIDE/problems/ojproblemset.cpp | 14 + RedPandaIDE/problems/ojproblemset.h | 43 ++ RedPandaIDE/widgets/ojproblemsetmodel.cpp | 51 ++ RedPandaIDE/widgets/ojproblemsetmodel.h | 33 +- Red_Panda_CPP.pro | 1 + 14 files changed, 534 insertions(+), 344 deletions(-) create mode 100644 RedPandaIDE/problems/ojproblemset.cpp create mode 100644 RedPandaIDE/problems/ojproblemset.h diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index de4748a8..89604661 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -35,6 +35,7 @@ SOURCES += \ parser/cpptokenizer.cpp \ parser/parserutils.cpp \ parser/statementmodel.cpp \ + problems/ojproblemset.cpp \ project.cpp \ projectoptions.cpp \ projecttemplate.cpp \ @@ -81,6 +82,7 @@ SOURCES += \ iconsmanager.cpp \ main.cpp \ mainwindow.cpp \ + problems/problemcasevalidator.cpp \ qsynedit/CodeFolding.cpp \ qsynedit/Constants.cpp \ qsynedit/KeyStrokes.cpp \ @@ -153,6 +155,8 @@ HEADERS += \ parser/parserutils.h \ parser/statementmodel.h \ platform.h \ + problems/ojproblemset.h \ + problems/problemcasevalidator.h \ project.h \ projectoptions.h \ projecttemplate.h \ diff --git a/RedPandaIDE/RedPandaIDE_zh_CN.ts b/RedPandaIDE/RedPandaIDE_zh_CN.ts index 2fdc02bf..256cbc09 100644 --- a/RedPandaIDE/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/RedPandaIDE_zh_CN.ts @@ -550,44 +550,44 @@ CompilerManager - - - - - + + + + + No compiler set 无编译器设置 - - - - - + + + + + No compiler set is configured. 没有配置编译器设置。 - - - - - + + + + + Can't start debugging. 无法启动调试器 - + Encoding not support 不支持字符编码 - + Clang only support utf-8 encoding. Clang只支持UTF-8编码 - + Strings in the program might be wrongly processed. 程序中的文字内容可能无法被正确处理和显示。 @@ -1872,7 +1872,7 @@ Are you really want to continue? ExecutableRunner - + The runner process '%1' failed to start. The runner process failed to start. 无法启动程序运行进程'%1'。 @@ -1882,17 +1882,17 @@ Are you really want to continue? 程序运行进程启动后崩溃。 - + 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. 在从程序运行进程读取内容时出错。 @@ -2806,44 +2806,44 @@ Are you really want to continue? 小熊猫C++ - + - + Issues 编译器 - + Compile Log 编译日志 - + File 文件 - + Tools 工具 - - + + Run 运行 - + Edit 编辑 - + Project 项目 @@ -2867,82 +2867,82 @@ Are you really want to continue? 资源 - - - - + + + + Debug 调试 - + Evaluate: 求值 - + Debug Console 调试主控台 - + Call Stack 调用栈 - + Breakpoints 断点 - + Locals 本地变量 - - + + Search 查找 - + History: 历史: - + Search Again 重新查找 - + Replace with: 替换为: - + Replace 替换 - + Close 关闭 - + Execute 运行 - - + + Code 代码 - + Window 窗口 @@ -2960,59 +2960,59 @@ Are you really want to continue? 新建 - + Ctrl+N Ctrl+N - + Open... 打开... - + Ctrl+O Ctrl+O - + Save 保存 - + Ctrl+S Ctrl+S - + Save As... 另存为... - + Save As 另存为 - + Save All 全部保存 - + Ctrl+Shift+S Ctrl+Shift+S - + Options 选项 - - - + + + @@ -3021,696 +3021,721 @@ Are you really want to continue? 编译 - + F9 F9 - + F10 F10 - + Undo 恢复 - + Ctrl+Z Ctrl+Z - + Redo 重做 - + Ctrl+Y Ctrl+Y - + Cut 剪切 - + Ctrl+X Ctrl+X - + Copy 复制 - + Ctrl+C Ctrl+C - + Paste 粘贴 - + Ctrl+V Ctrl+V - + Select All 选择全部 - + Ctrl+A Ctrl+A - + Indent 缩进 - + UnIndent 取消缩进 - + Toggle Comment 切换注释 - + Ctrl+/ Ctrl+/ - + Collapse All 全部收起 - + Uncollapse All 全部展开 - + Encode in ANSI 使用ANSI编码 - + Encode in UTF-8 使用UTF-8编码 - + Auto Detect 自动检测 - + Convert to ANSI 转换为ANSI编码 - + Convert to UTF-8 转换为UTF-8编码 - - + + Compile & Run 编译运行 - + F11 F11 - - + + Rebuild All 全部重编译 - + F12 F12 - + Stop Execution 停止执行 - + F6 F6 - + F5 F5 - + Step Over 单步跳过 - + F7 F7 - + Step Into 单步进入 - - + + Problem Set 试题集 - + + + New Problem Set 新建试题集 - + + Add Problem 添加试题 - + + Remove Problem 删除试题 - - + + + Save Problem Set 保存试题集 - - + + + Load Problem Set 载入试题集 - + Memory 内存 - + Address Expression: Address: 地址表达式: - + Cancel 取消 - + TODO TODO - + Bookmark 书签 - - + + Problem 试题 - + + Add Probem Case 添加试题案例 - + + Remove Problem Case Remove Problem Set 删除试题集 - + + + Run Current Case + + + + + + Run All Cases + + + + + %v/%m + + + + Output 输出 - + Input 输入 - + Expected 期望输出 - + Help 帮助 - + Refactor 重构 - + Main 主工具栏 - + Compiler Set 编译器配置集 - - + + New Source File 新建源代码文件 - + Tab Tab - + Shift+Tab Shift+Tab - + F8 F8 - + Step Out 单步跳出 - + Ctrl+F8 Ctrl+F8 - + Run To Cursor 执行到光标处 - + Ctrl+F5 Ctrl+F5 - + Continue 继续执行 - + F4 F4 - + Add Watch... 添加监视 - + View CPU Window... 打开CPU信息窗口... - + Exit 退出 - + Find... 查找... - + Ctrl+F Ctrl+F - + Find in Files... 在文件中查找... - + Ctrl+Shift+F Ctrl+Shift+F - + Replace... 替换 - + Ctrl+R Ctrl+R - + Find Next 查找下一个 - + F3 F3 - + Find Previous 查找前一个 - + Shift+F3 Shift+F3 - + Remove Watch 删除监视值 - + Remove All Watches Remove All 删除全部监视值 - + Modify Watch... 修改监视值 - + Reformat Code 对代码重新排版 - + Ctrl+Shift+A Ctrl+Shift+A - + Go back 前一次编辑位置 - + Ctrl+Alt+Left Ctrl+Alt+Left - + Forward 后一次编辑位置 - + Ctrl+Alt+Right Ctrl+Alt+Right - + Ctrl+W Ctrl+W - + Close All 全部关闭 - + Ctrl+Shift+W Ctrl+Shift+W - + Maximize Editor 最大化编辑器 - + Ctrl+F11 Ctrl+F11 - + Next 下一窗口 - + Ctrl+Tab Ctrl+Tab - + Previous 前一窗口 - + Ctrl+Shift+Tab Ctrl+Shift+Tab - + Toggle breakpoint 切换断点 - + Ctrl+F4 Ctrl+F4 - - + + Clear all breakpoints 删除所有断点 - + Breakpoint property... 设置断点条件... - + Goto Declaration 跳转到声明处 - + Goto Definition 跳转到定义处 - + Find references 查找符号的引用 - + Open containing folder 打开所在的文件夹 - + Ctrl+B Ctrl+B - + Open a terminal here 打开命令行窗口 - + File Properties... 文件属性... - + Close Project 关闭项目 - + Project options 项目属性 - + New Project... 新建项目... - + New File 新建项目文件 - + Add to project... 添加到项目... - + Remove from project 从项目删除 - + View Makefile 查看Makefile - + Clean 清理构建文件 - + Open Folder in Explorer 在浏览器中打开 - + Open In Terminal 在终端中打开 - + About 关于 - - + + Rename Symbol 重命名符号 - + Shift+F6 Shift+F6 - + Print... 打印... - + Ctrl+P Ctrl+P - - + + Export As RTF 导出为RTF - - + + Export As HTML 导出为HTML - + Move To Other View 移动到其他视图 - + Ctrl+M Ctrl+M - + C/C++ Reference C/C++参考 - + EGE Manual EGE图形库手册 - + Add Bookmark 添加书签 - + Remove Bookmark 删除书签 - + Modify Bookmark Description 修改书签说明 - + Locate in Files View 在文件视图中定位 - - + + Open Folder 打开文件夹 - + Running Parameters... 运行参数... @@ -3936,7 +3961,7 @@ Are you really want to continue? - + Problem Set %1 试题集%1 @@ -3962,15 +3987,15 @@ Are you really want to continue? - - + + Bookmark Description 书签描述 - - + + Description: 描述: @@ -4113,6 +4138,7 @@ Are you really want to continue? + Do you want to save it? 需要保存吗? @@ -4120,7 +4146,7 @@ Are you really want to continue? - + Save Error 保存失败 @@ -4140,149 +4166,154 @@ Are you really want to continue? 你真的想要做那些吗? - + 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 - + Red panda Dev-C++ project file (*.dev) 小熊猫Dev-C++项目文件 (*.dev) - + New project fail 新建项目失败 - + Can't assign project template 无法使用模板创建项目 - + untitled 无标题 - + New Project File Name 新的项目文件名 - + File Name: 文件名: - + File Already Exists! 文件已存在! - + File '%1' already exists! 文件'%1'已经存在! - + Add to project 添加到项目 - + 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 @@ -4300,8 +4331,8 @@ Are you really want to continue? - - + + Error 错误 @@ -4341,45 +4372,45 @@ Are you really want to continue? 编译失败 - + 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个文件) @@ -4433,6 +4464,29 @@ Are you really want to continue? 缺省 + + OJProblemCasesRunner + + + 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. + 在从程序运行进程读取内容时出错。 + + Project @@ -6195,7 +6249,7 @@ Are you really want to continue? 自动链接 - + @@ -6271,7 +6325,7 @@ Are you really want to continue? 杂项 - + Program Runner 程序运行 diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index b51d6e5b..470cd48d 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -244,9 +244,9 @@ void CompilerManager::runProblem(const QString &filename, const QString &argumen OJProblemCasesRunner * execRunner = new OJProblemCasesRunner(filename,arguments,workDir,problemCase); mRunner = execRunner; connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); - connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished); + connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunProblemFinished); connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured); -// connect(execRunner, &OJProblemCasesRunner::caseStarted, pMainWindow, &MainWindow::onOJProblemCaseStarted); + connect(execRunner, &OJProblemCasesRunner::caseStarted, pMainWindow, &MainWindow::onOJProblemCaseStarted); mRunner->start(); } @@ -259,9 +259,9 @@ void CompilerManager::runProblem(const QString &filename, const QString &argumen OJProblemCasesRunner * execRunner = new OJProblemCasesRunner(filename,arguments,workDir,problemCases); mRunner = execRunner; connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); - connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunFinished); + connect(mRunner, &Runner::finished, pMainWindow ,&MainWindow::onRunProblemFinished); connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured); -// connect(execRunner, &OJProblemCasesRunner::caseStarted, pMainWindow, &MainWindow::onOJProblemCaseStarted); + connect(execRunner, &OJProblemCasesRunner::caseStarted, pMainWindow, &MainWindow::onOJProblemCaseStarted); mRunner->start(); } diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp index 1bedeb9e..e8f6473f 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp @@ -21,9 +21,9 @@ OJProblemCasesRunner::OJProblemCasesRunner(const QString& filename, const QStrin void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) { - emit caseStarted(mProblemCases.count(),index); - auto action = finally([this,&index]{ - emit caseStarted(mProblemCases.count(),index); + emit caseStarted(problemCase->getId(),mProblemCases.count(),index); + auto action = finally([this,&index, &problemCase]{ + emit caseFinished(problemCase->getId(),mProblemCases.count(),index); }); QProcess process; bool errorOccurred = false; diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.h b/RedPandaIDE/compiler/ojproblemcasesrunner.h index 86508570..aeecef07 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.h +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.h @@ -3,9 +3,7 @@ #include "runner.h" #include - -class OJProblemCase; -using POJProblemCase = std::shared_ptr; +#include "../problems/ojproblemset.h" class OJProblemCasesRunner : public Runner { @@ -16,8 +14,8 @@ public: explicit OJProblemCasesRunner(const QString& filename, const QString& arguments, const QString& workDir, POJProblemCase problemCase, QObject *parent = nullptr); signals: - void caseStarted(int total, int current); - void caseFinished(int total, int current); + void caseStarted(const QString& id, int total, int current); + void caseFinished(const QString& id, int total, int current); private: void runCase(int index, POJProblemCase problemCase); private: diff --git a/RedPandaIDE/iconsmanager.h b/RedPandaIDE/iconsmanager.h index b807957c..e59fd4ff 100644 --- a/RedPandaIDE/iconsmanager.h +++ b/RedPandaIDE/iconsmanager.h @@ -23,7 +23,6 @@ public: const PIcon &bookmark() const; const PIcon &folder() const; - signals: private: PIcon mSyntaxError; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index ff5bee8e..ddcc09f4 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -18,6 +18,7 @@ #include "colorscheme.h" #include "thememanager.h" #include "widgets/darkfusionstyle.h" +#include "problems/problemcasevalidator.h" #include #include @@ -205,7 +206,7 @@ MainWindow::MainWindow(QWidget *parent) ui->searchView,&QTreeView::expandAll); ui->replacePanel->setVisible(false); - mOJProblemSetNameCounter++; + mOJProblemSetNameCounter=1; mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter)); ui->lstProblemSet->setModel(&mOJProblemSetModel); ui->lstProblemCases->setModel(&mOJProblemModel); @@ -1086,7 +1087,7 @@ bool MainWindow::compile(bool rebuild) return false; } -void MainWindow::runExecutable(const QString &exeName,const QString &filename) +void MainWindow::runExecutable(const QString &exeName,const QString &filename,RunType runType) { // Check if it exists if (!fileExists(exeName)) { @@ -1136,22 +1137,37 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename) // end; updateCompileActions(); - if (pSettings->executor().minimizeOnRun()) { - showMinimized(); - } - updateAppTitle(); QString params; if (pSettings->executor().useParams()) { params = pSettings->executor().params(); } - mCompilerManager->run(exeName,params,QFileInfo(exeName).absolutePath()); + if (runType==RunType::Normal) { + if (pSettings->executor().minimizeOnRun()) { + showMinimized(); + } + mCompilerManager->run(exeName,params,QFileInfo(exeName).absolutePath()); + } else if (runType == RunType::ProblemCases) { + POJProblem problem = mOJProblemModel.problem(); + if (problem) { + mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), + problem->cases); + } + } else if (runType == RunType::CurrentProblemCase) { + QModelIndex index = ui->lstProblemCases->currentIndex(); + if (index.isValid()) { + POJProblemCase problemCase =mOJProblemModel.getCase(index.row()); + mCompilerManager->runProblem(exeName,params,QFileInfo(exeName).absolutePath(), + problemCase); + } + } + updateAppTitle(); } -void MainWindow::runExecutable() +void MainWindow::runExecutable(RunType runType) { CompileTarget target =getCompileTarget(); if (target == CompileTarget::Project) { - runExecutable(mProject->executable(),mProject->filename()); + runExecutable(mProject->executable(),mProject->filename(),runType); } else { Editor * editor = mEditorList->getEditor(); if (editor != NULL ) { @@ -1160,7 +1176,7 @@ void MainWindow::runExecutable() return; } QString exeName= getCompiledExecutableName(editor->filename()); - runExecutable(exeName,editor->filename()); + runExecutable(exeName,editor->filename(),runType); } } } @@ -3327,6 +3343,39 @@ void MainWindow::onRunFinished() updateAppTitle(); } +void MainWindow::onRunProblemFinished() +{ + updateCompileActions(); + updateAppTitle(); +} + +void MainWindow::onOJProblemCaseStarted(const QString& id,int current, int total) +{ + ui->pbProblemCases->setMaximum(total); + ui->pbProblemCases->setValue(current); + int row = mOJProblemModel.getCaseIndexById(id); + if (row>=0) { + POJProblemCase problemCase = mOJProblemModel.getCase(row); + problemCase->testState = ProblemCaseTestState::Testing; + mOJProblemModel.update(row); + } +} + +void MainWindow::onOJProblemCaseFinished(const QString &id, int current, int total) +{ + int row = mOJProblemModel.getCaseIndexById(id); + if (row>=0) { + POJProblemCase problemCase = mOJProblemModel.getCase(row); + ProblemCaseValidator validator; + problemCase->testState = validator.validate(problemCase)? + ProblemCaseTestState::Passed: + ProblemCaseTestState::Failed; + mOJProblemModel.update(row); + } + ui->pbProblemCases->setMaximum(total); + ui->pbProblemCases->setValue(current); +} + void MainWindow::cleanUpCPUDialog() { CPUDialog* ptr=mCPUDialog; @@ -4985,3 +5034,8 @@ void MainWindow::on_btnAddProblemCase_clicked() ui->lstProblemCases->setCurrentIndex(mOJProblemModel.index(mOJProblemModel.count()-1)); } +void MainWindow::on_btnRunAllProblemCases_clicked() +{ + runExecutable(RunType::ProblemCases); +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index da52071b..941841d3 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -29,6 +29,12 @@ enum class CompileTarget { Invalid, None, File, Project, SyntaxCheck }; +enum class RunType { + Normal, + CurrentProblemCase, + ProblemCases +}; + class EditorList; class QLabel; class QComboBox; @@ -76,8 +82,8 @@ public: void updateDebuggerSettings(); void checkSyntaxInBack(Editor* e); bool compile(bool rebuild=false); - void runExecutable(const QString& exeName, const QString& filename=QString()); - void runExecutable(); + void runExecutable(const QString& exeName, const QString& filename=QString(),RunType runType = RunType::Normal); + void runExecutable(RunType runType = RunType::Normal); void debug(); void showSearchPanel(bool showReplace = false); @@ -154,6 +160,9 @@ public slots: void onCompileErrorOccured(const QString& reason); void onRunErrorOccured(const QString& reason); void onRunFinished(); + void onRunProblemFinished(); + void onOJProblemCaseStarted(const QString& id, int current, int total); + void onOJProblemCaseFinished(const QString& id, int current, int total); void cleanUpCPUDialog(); void onDebugCommandInput(const QString& command); void onDebugEvaluateInput(); @@ -448,6 +457,8 @@ private slots: void on_btnAddProblemCase_clicked(); + void on_btnRunAllProblemCases_clicked(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 647f22e6..76a0d85d 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 1036 + 1114 742 @@ -1205,20 +1205,6 @@ - - - - Run Current Case - - - Run Current Case - - - - :/icons/images/newlook24/069-run.png:/icons/images/newlook24/069-run.png - - - @@ -1229,17 +1215,7 @@ - :/icons/images/newlook24/021-Debug-Continue.png:/icons/images/newlook24/021-Debug-Continue.png - - - - - - - 24 - - - %v/%m + :/icons/images/newlook24/069-run.png:/icons/images/newlook24/069-run.png @@ -1256,6 +1232,16 @@ + + + + 24 + + + %v/%m + + + @@ -1331,7 +1317,7 @@ 0 0 - 1036 + 1114 25 diff --git a/RedPandaIDE/problems/ojproblemset.cpp b/RedPandaIDE/problems/ojproblemset.cpp new file mode 100644 index 00000000..a6c59106 --- /dev/null +++ b/RedPandaIDE/problems/ojproblemset.cpp @@ -0,0 +1,14 @@ +#include "ojproblemset.h" + +#include + +OJProblemCase::OJProblemCase() +{ + QUuid uid = QUuid::createUuid(); + id = uid.toString(); +} + +const QString &OJProblemCase::getId() const +{ + return id; +} diff --git a/RedPandaIDE/problems/ojproblemset.h b/RedPandaIDE/problems/ojproblemset.h new file mode 100644 index 00000000..e3e1e225 --- /dev/null +++ b/RedPandaIDE/problems/ojproblemset.h @@ -0,0 +1,43 @@ +#ifndef OJPROBLEMSET_H +#define OJPROBLEMSET_H +#include +#include +#include + +enum class ProblemCaseTestState { + NoTested, + Testing, + Passed, + Failed +}; + +struct OJProblemCase { + QString name; + QString input; + QString expected; + ProblemCaseTestState testState; // no persistence + QString output; // no persistence + OJProblemCase(); + +public: + const QString &getId() const; + +private: + QString id; +}; + +using POJProblemCase = std::shared_ptr; + +struct OJProblem { + QString name; + QVector cases; +}; + +using POJProblem = std::shared_ptr; + +struct OJProblemSet { + QString name; + QVector problems; +}; + +#endif // OJPROBLEMSET_H diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.cpp b/RedPandaIDE/widgets/ojproblemsetmodel.cpp index 2cd6c251..ea32bb5c 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.cpp +++ b/RedPandaIDE/widgets/ojproblemsetmodel.cpp @@ -1,10 +1,12 @@ #include "ojproblemsetmodel.h" #include +#include #include #include #include #include "../utils.h" +#include "../iconsmanager.h" OJProblemSetModel::OJProblemSetModel(QObject *parent) : QAbstractListModel(parent) { @@ -223,6 +225,29 @@ POJProblemCase OJProblemModel::getCase(int index) return mProblem->cases[index]; } +POJProblemCase OJProblemModel::getCaseById(const QString& id) +{ + if (mProblem==nullptr) + return POJProblemCase(); + foreach (const POJProblemCase& problemCase, mProblem->cases){ + if (problemCase->getId() == id) + return problemCase; + } + return POJProblemCase(); +} + +int OJProblemModel::getCaseIndexById(const QString &id) +{ + if (mProblem==nullptr) + return -1; + for (int i=0;icases.size();i++) { + const POJProblemCase& problemCase = mProblem->cases[i]; + if (problemCase->getId() == id) + return i; + } + return -1; +} + void OJProblemModel::clear() { if (mProblem==nullptr) @@ -239,6 +264,11 @@ int OJProblemModel::count() return mProblem->cases.count(); } +void OJProblemModel::update(int row) +{ + emit dataChanged(index(row,0),index(row,0)); +} + int OJProblemModel::rowCount(const QModelIndex &) const { if (mProblem==nullptr) @@ -254,6 +284,17 @@ QVariant OJProblemModel::data(const QModelIndex &index, int role) const return QVariant(); if (role == Qt::DisplayRole || role == Qt::EditRole) { return mProblem->cases[index.row()]->name; + } else if (role == Qt::DecorationRole) { + switch (mProblem->cases[index.row()]->testState) { + case ProblemCaseTestState::Failed: + return QIcon(":/icons/images/newlook24/008-close.png"); + case ProblemCaseTestState::Passed: + return QIcon(":/icons/images/newlook24/007-bughelp.png"); + case ProblemCaseTestState::Testing: + return QIcon(":/icons/images/newlook24/052-next.png"); + default: + return QVariant(); + } } return QVariant(); } @@ -262,6 +303,16 @@ bool OJProblemModel::setData(const QModelIndex &index, const QVariant &value, in { if (!index.isValid()) return false; + if (mProblem==nullptr) + return false; + if (role == Qt::DisplayRole || role == Qt::EditRole) { + QString s = value.toString(); + if (!s.isEmpty()) { + mProblem->cases[index.row()]->name = s; + return true; + } + } + return false; } Qt::ItemFlags OJProblemModel::flags(const QModelIndex &) const diff --git a/RedPandaIDE/widgets/ojproblemsetmodel.h b/RedPandaIDE/widgets/ojproblemsetmodel.h index 59f83e0d..8d4f04c9 100644 --- a/RedPandaIDE/widgets/ojproblemsetmodel.h +++ b/RedPandaIDE/widgets/ojproblemsetmodel.h @@ -3,35 +3,7 @@ #include #include - -enum class ProblemCaseTestState { - NoTested, - Passed, - Failed -}; - -struct OJProblemCase { - QString name; - QString input; - QString expected; - - QString output; // no persistence - ProblemCaseTestState testState; // no persistence -}; - -using POJProblemCase = std::shared_ptr; - -struct OJProblem { - QString name; - QVector cases; -}; - -using POJProblem = std::shared_ptr; - -struct OJProblemSet { - QString name; - QVector problems; -}; +#include "../problems/ojproblemset.h" class OJProblemModel: public QAbstractListModel { Q_OBJECT @@ -42,8 +14,11 @@ public: void addCase(POJProblemCase problemCase); void removeCase(int index); POJProblemCase getCase(int index); + POJProblemCase getCaseById(const QString& id); + int getCaseIndexById(const QString& id); void clear(); int count(); + void update(int row); private: POJProblem mProblem; diff --git a/Red_Panda_CPP.pro b/Red_Panda_CPP.pro index b737f4d8..148bb77d 100644 --- a/Red_Panda_CPP.pro +++ b/Red_Panda_CPP.pro @@ -3,3 +3,4 @@ TEMPLATE = subdirs SUBDIRS += \ # ../QScintilla/src/qscintilla.pro \ RedPandaIDE +