work save

This commit is contained in:
royqh1979 2021-11-01 20:44:08 +08:00
parent 9f4e8344a3
commit e82723c6f8
14 changed files with 534 additions and 344 deletions

View File

@ -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 \

File diff suppressed because it is too large Load Diff

View File

@ -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();
}

View File

@ -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;

View File

@ -3,9 +3,7 @@
#include "runner.h"
#include <QVector>
class OJProblemCase;
using POJProblemCase = std::shared_ptr<OJProblemCase>;
#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:

View File

@ -23,7 +23,6 @@ public:
const PIcon &bookmark() const;
const PIcon &folder() const;
signals:
private:
PIcon mSyntaxError;

View File

@ -18,6 +18,7 @@
#include "colorscheme.h"
#include "thememanager.h"
#include "widgets/darkfusionstyle.h"
#include "problems/problemcasevalidator.h"
#include <QCloseEvent>
#include <QComboBox>
@ -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);
}

View File

@ -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;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1036</width>
<width>1114</width>
<height>742</height>
</rect>
</property>
@ -1205,20 +1205,6 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRunCurrentProblemCase">
<property name="toolTip">
<string>Run Current Case</string>
</property>
<property name="text">
<string>Run Current Case</string>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/069-run.png</normaloff>:/icons/images/newlook24/069-run.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnRunAllProblemCases">
<property name="toolTip">
@ -1229,17 +1215,7 @@
</property>
<property name="icon">
<iconset resource="icons.qrc">
<normaloff>:/icons/images/newlook24/021-Debug-Continue.png</normaloff>:/icons/images/newlook24/021-Debug-Continue.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="pbProblemCases">
<property name="value">
<number>24</number>
</property>
<property name="format">
<string>%v/%m</string>
<normaloff>:/icons/images/newlook24/069-run.png</normaloff>:/icons/images/newlook24/069-run.png</iconset>
</property>
</widget>
</item>
@ -1256,6 +1232,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QProgressBar" name="pbProblemCases">
<property name="value">
<number>24</number>
</property>
<property name="format">
<string>%v/%m</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -1331,7 +1317,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1036</width>
<width>1114</width>
<height>25</height>
</rect>
</property>

View File

@ -0,0 +1,14 @@
#include "ojproblemset.h"
#include <QUuid>
OJProblemCase::OJProblemCase()
{
QUuid uid = QUuid::createUuid();
id = uid.toString();
}
const QString &OJProblemCase::getId() const
{
return id;
}

View File

@ -0,0 +1,43 @@
#ifndef OJPROBLEMSET_H
#define OJPROBLEMSET_H
#include <QString>
#include <memory>
#include <QVector>
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<OJProblemCase>;
struct OJProblem {
QString name;
QVector<POJProblemCase> cases;
};
using POJProblem = std::shared_ptr<OJProblem>;
struct OJProblemSet {
QString name;
QVector<POJProblem> problems;
};
#endif // OJPROBLEMSET_H

View File

@ -1,10 +1,12 @@
#include "ojproblemsetmodel.h"
#include <QFile>
#include <QIcon>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#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;i<mProblem->cases.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

View File

@ -3,35 +3,7 @@
#include <QAbstractListModel>
#include <memory>
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<OJProblemCase>;
struct OJProblem {
QString name;
QVector<POJProblemCase> cases;
};
using POJProblem = std::shared_ptr<OJProblem>;
struct OJProblemSet {
QString name;
QVector<POJProblem> 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;

View File

@ -3,3 +3,4 @@ TEMPLATE = subdirs
SUBDIRS += \
# ../QScintilla/src/qscintilla.pro \
RedPandaIDE