- enhancement: batch set cases ( in problem case table's context menu )

This commit is contained in:
Roy Qu 2022-04-16 20:39:09 +08:00
parent 076a92fb77
commit f6ac7ad1dc
7 changed files with 378 additions and 289 deletions

View File

@ -9,6 +9,7 @@ Red Panda C++ Version 1.0.4
- fix: parenthesis skip doesn't work when editing non-c/c++ files - fix: parenthesis skip doesn't work when editing non-c/c++ files
- enhancement: prefer local headers over system headers when complete #include header path - enhancement: prefer local headers over system headers when complete #include header path
- fix: tab/shift+tab not correctly handled in options dialog's code template page - fix: tab/shift+tab not correctly handled in options dialog's code template page
- enhancement: batch set cases ( in problem case table's context menu )
Red Panda C++ Version 1.0.3 Red Panda C++ Version 1.0.3
- fix: when oj problem grabbed by competitive companion received, - fix: when oj problem grabbed by competitive companion received,

View File

@ -4424,6 +4424,22 @@
<source>Line %1</source> <source>Line %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Batch Set Cases</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Choose input files</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Input data files (*.in)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This operation will remove all cases for the current problem.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>NewClassDialog</name> <name>NewClassDialog</name>

File diff suppressed because it is too large Load Diff

View File

@ -2273,6 +2273,11 @@ void MainWindow::buildContextMenus()
); );
connect(mProblem_RunCurrentCase, &QAction::triggered, this, connect(mProblem_RunCurrentCase, &QAction::triggered, this,
&MainWindow::onProblemRunCurrentCase); &MainWindow::onProblemRunCurrentCase);
mProblem_batchSetCases = createActionFor(
tr("Batch Set Cases"),
ui->tblProblemCases);
connect(mProblem_batchSetCases, &QAction::triggered, this,
&MainWindow::onProblemBatchSetCases);
//context menu signal for the Problem Set lable //context menu signal for the Problem Set lable
ui->lblProblemSet->setContextMenuPolicy(Qt::CustomContextMenu); ui->lblProblemSet->setContextMenuPolicy(Qt::CustomContextMenu);
@ -3142,6 +3147,8 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos)
void MainWindow::onTableProblemCasesContextMenu(const QPoint &pos) void MainWindow::onTableProblemCasesContextMenu(const QPoint &pos)
{ {
QMenu menu(this); QMenu menu(this);
menu.addAction(mProblem_batchSetCases);
menu.addSeparator();
QModelIndex idx = ui->tblProblemCases->currentIndex(); QModelIndex idx = ui->tblProblemCases->currentIndex();
menu.addAction(mProblem_RunAllCases); menu.addAction(mProblem_RunAllCases);
menu.addAction(mProblem_RunCurrentCase); menu.addAction(mProblem_RunCurrentCase);
@ -3255,6 +3262,35 @@ void MainWindow::onProblemRunCurrentCase()
runExecutable(RunType::CurrentProblemCase); runExecutable(RunType::CurrentProblemCase);
} }
void MainWindow::onProblemBatchSetCases()
{
if (QMessageBox::question(this,tr("Batch Set Cases"),
tr("This operation will remove all cases for the current problem.")
+"<br />"
+tr("Do you really want to do that?"),
QMessageBox::Yes| QMessageBox::No,
QMessageBox::No)!=QMessageBox::Yes)
return;
QStringList files = QFileDialog::getOpenFileNames(
this,
tr("Choose input files"),
QDir::currentPath(),
tr("Input data files (*.in)"));
if (files.isEmpty())
return;
mOJProblemModel.removeCases();
foreach (const QString& filename, files) {
POJProblemCase problemCase = std::make_shared<OJProblemCase>();
problemCase->name = QFileInfo(filename).baseName();
problemCase->testState = ProblemCaseTestState::NotTested;
problemCase->inputFileName = filename;
QString expectedFileName = filename.mid(0,filename.length()-2)+"out";
if (fileExists(expectedFileName))
problemCase->expectedOutputFileName = expectedFileName;
mOJProblemModel.addCase(problemCase);
}
}
void MainWindow::onNewProblemConnection() void MainWindow::onNewProblemConnection()
{ {
QTcpSocket* clientConnection = mTcpServer.nextPendingConnection(); QTcpSocket* clientConnection = mTcpServer.nextPendingConnection();
@ -4694,7 +4730,7 @@ void MainWindow::onOJProblemCaseNewOutputGetted(const QString &/* id */, const Q
ui->txtProblemCaseOutput->appendPlainText(line); ui->txtProblemCaseOutput->appendPlainText(line);
} }
void MainWindow::onOJProblemCaseResetOutput(const QString &id, const QString &line) void MainWindow::onOJProblemCaseResetOutput(const QString &/* id */, const QString &line)
{ {
ui->txtProblemCaseOutput->setPlainText(line); ui->txtProblemCaseOutput->setPlainText(line);
} }

View File

@ -283,6 +283,7 @@ private slots:
void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous); void onProblemCaseIndexChanged(const QModelIndex &current, const QModelIndex &previous);
void onProblemNameChanged(int index); void onProblemNameChanged(int index);
void onProblemRunCurrentCase(); void onProblemRunCurrentCase();
void onProblemBatchSetCases();
void onNewProblemConnection(); void onNewProblemConnection();
void updateProblemTitle(); void updateProblemTitle();
void onEditorClosed(); void onEditorClosed();
@ -793,6 +794,7 @@ private:
//action for problem //action for problem
QAction * mProblem_RunCurrentCase; QAction * mProblem_RunCurrentCase;
QAction * mProblem_RunAllCases; QAction * mProblem_RunAllCases;
QAction * mProblem_batchSetCases;
//action for tools output //action for tools output
QAction * mToolsOutput_Clear; QAction * mToolsOutput_Clear;

View File

@ -284,6 +284,13 @@ void OJProblemModel::removeCase(int index)
endRemoveRows(); endRemoveRows();
} }
void OJProblemModel::removeCases()
{
beginRemoveRows(QModelIndex(),0,mProblem->cases.count());
mProblem->cases.clear();
endRemoveRows();
}
POJProblemCase OJProblemModel::getCase(int index) POJProblemCase OJProblemModel::getCase(int index)
{ {
if (mProblem==nullptr) if (mProblem==nullptr)

View File

@ -29,6 +29,7 @@ public:
void setProblem(const POJProblem &newProblem); void setProblem(const POJProblem &newProblem);
void addCase(POJProblemCase problemCase); void addCase(POJProblemCase problemCase);
void removeCase(int index); void removeCase(int index);
void removeCases();
POJProblemCase getCase(int index); POJProblemCase getCase(int index);
POJProblemCase getCaseById(const QString& id); POJProblemCase getCaseById(const QString& id);
int getCaseIndexById(const QString& id); int getCaseIndexById(const QString& id);