- 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
- 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
- enhancement: batch set cases ( in problem case table's context menu )
Red Panda C++ Version 1.0.3
- fix: when oj problem grabbed by competitive companion received,

View File

@ -4424,6 +4424,22 @@
<source>Line %1</source>
<translation type="unfinished"></translation>
</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>
<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,
&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
ui->lblProblemSet->setContextMenuPolicy(Qt::CustomContextMenu);
@ -3142,6 +3147,8 @@ void MainWindow::onLstProblemSetContextMenu(const QPoint &pos)
void MainWindow::onTableProblemCasesContextMenu(const QPoint &pos)
{
QMenu menu(this);
menu.addAction(mProblem_batchSetCases);
menu.addSeparator();
QModelIndex idx = ui->tblProblemCases->currentIndex();
menu.addAction(mProblem_RunAllCases);
menu.addAction(mProblem_RunCurrentCase);
@ -3255,6 +3262,35 @@ void MainWindow::onProblemRunCurrentCase()
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()
{
QTcpSocket* clientConnection = mTcpServer.nextPendingConnection();
@ -4694,7 +4730,7 @@ void MainWindow::onOJProblemCaseNewOutputGetted(const QString &/* id */, const Q
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);
}

View File

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

View File

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

View File

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