diff --git a/NEWS.md b/NEWS.md index 3feed134..c5117230 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ Version 0.11.2 For Dev-C++ 7 Beta - fix: button "run all problem cases" not disabled when compiling or debugging + - enhancement: set font for problem case input/output textedits + - enhancement: when run problem cases, updates output immediately Version 0.11.1 For Dev-C++ 7 Beta - enhancement: Problem's test case shouldn't accept rich text inputs diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 65ab3023..3eaffe99 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -245,6 +245,7 @@ void CompilerManager::runProblem(const QString &filename, const QString &argumen if (mRunner!=nullptr) { return; } + OJProblemCasesRunner * execRunner = new OJProblemCasesRunner(filename,arguments,workDir,problemCase); mRunner = execRunner; connect(mRunner, &Runner::finished, this ,&CompilerManager::onRunnerTerminated); @@ -268,6 +269,7 @@ void CompilerManager::runProblem(const QString &filename, const QString &argumen connect(mRunner, &Runner::runErrorOccurred, pMainWindow ,&MainWindow::onRunErrorOccured); connect(execRunner, &OJProblemCasesRunner::caseStarted, pMainWindow, &MainWindow::onOJProblemCaseStarted); connect(execRunner, &OJProblemCasesRunner::caseFinished, pMainWindow, &MainWindow::onOJProblemCaseFinished); + connect(execRunner, &OJProblemCasesRunner::newOutputLineGetted, pMainWindow, &MainWindow::onOJProblemCaseNewOutputLineGetted); mRunner->start(); } diff --git a/RedPandaIDE/compiler/executablerunner.cpp b/RedPandaIDE/compiler/executablerunner.cpp index e8c3ade6..cd91faef 100644 --- a/RedPandaIDE/compiler/executablerunner.cpp +++ b/RedPandaIDE/compiler/executablerunner.cpp @@ -106,8 +106,25 @@ void ExecutableRunner::run() process.closeReadChannel(QProcess::StandardOutput); process.closeReadChannel(QProcess::StandardError); process.closeWriteChannel(); +#ifdef Q_OS_WIN + if (!mStartConsole) { + process.terminate(); + if (process.waitForFinished(1000)) { + break; + } + } +#else process.terminate(); - process.kill(); + if (process.waitForFinished(1000)) { + break; + } +#endif + for (int i=0;i<10;i++) { + process.kill(); + if (process.waitForFinished(100)) { + break; + } + } break; } if (errorOccurred) diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp index 1b8bf943..a2731b8b 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp @@ -47,22 +47,30 @@ void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) } env.insert("PATH",path); process.setProcessEnvironment(env); + process.setCreateProcessArgumentsModifier([this](QProcess::CreateProcessArguments * args){ + args->flags |= CREATE_NEW_CONSOLE; + args->startupInfo -> dwFlags |= STARTF_USESHOWWINDOW; + args->startupInfo->wShowWindow = SW_HIDE; + }); process.setProcessChannelMode(QProcess::MergedChannels); process.connect(&process, &QProcess::errorOccurred, [&](){ errorOccurred= true; }); problemCase->output.clear(); - process.start(); + process.start(QProcess::ReadWrite|QProcess::Unbuffered); process.waitForStarted(5000); if (process.state()==QProcess::Running) { process.write(problemCase->input.toUtf8()); process.closeWriteChannel(); } QByteArray readed; + QByteArray buffer; + QStringList outputLines; while (true) { - process.waitForFinished(1000); - readed += process.readAll(); + process.waitForFinished(100); + readed = process.readAll(); + buffer += readed; if (process.state()!=QProcess::Running) { break; } @@ -76,8 +84,30 @@ void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) } if (errorOccurred) break; + QList lines = splitByteArrayToLines(buffer); + qDebug()<<"----do buffer----"; + qDebug()<=2) { + for (int i=0;igetId(),line); + outputLines.append(line); + } + buffer = lines.last(); + while (buffer.endsWith('\0')) { + buffer.remove(buffer.length()-1,1); + } + } + } + buffer += process.readAll(); + QList lines = splitByteArrayToLines(buffer); + for (int i=0;igetId(),line); + outputLines.append(line); } - readed += process.readAll(); if (errorOccurred) { //qDebug()<<"process error:"<output = QString::fromUtf8(readed); + problemCase->output = linesToText(outputLines); } void OJProblemCasesRunner::run() diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.h b/RedPandaIDE/compiler/ojproblemcasesrunner.h index 3a727659..114e93c5 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.h +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.h @@ -16,6 +16,7 @@ public: signals: void caseStarted(const QString& id, int current, int total); void caseFinished(const QString& id, int current, int total); + void newOutputLineGetted(const QString&id, const QString& newOutputLine); private: void runCase(int index, POJProblemCase problemCase); private: diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 999a8cbd..7c8093b8 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -545,6 +545,13 @@ void MainWindow::applySettings() qApp->setFont(font); this->setFont(font); + QFont caseEditorFont(pSettings->executor().caseEditorFontName(), + pSettings->executor().caseEditorFontSize()); + font.setStyleStrategy(QFont::PreferAntialias); + ui->txtProblemCaseInput->setFont(caseEditorFont); + ui->txtProblemCaseOutput->setFont(caseEditorFont); + ui->txtProblemCaseExpected->setFont(caseEditorFont); + mTcpServer.close(); int idxProblem = ui->tabMessages->indexOf(ui->tabProblem); ui->tabMessages->setTabEnabled(idxProblem,pSettings->executor().enableProblemSet()); @@ -1193,7 +1200,6 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename,Ru } } - updateCompileActions(); QString params; if (pSettings->executor().useParams()) { params = pSettings->executor().params(); @@ -1221,6 +1227,7 @@ void MainWindow::runExecutable(const QString &exeName,const QString &filename,Ru ui->tabMessages->setCurrentWidget(ui->tabProblem); } } + updateCompileActions(); updateAppTitle(); } @@ -3719,6 +3726,7 @@ void MainWindow::onOJProblemCaseStarted(const QString& id,int current, int total POJProblemCase problemCase = mOJProblemModel.getCase(row); problemCase->testState = ProblemCaseTestState::Testing; mOJProblemModel.update(row); + ui->txtProblemCaseOutput->clear(); } } @@ -3741,7 +3749,12 @@ void MainWindow::onOJProblemCaseFinished(const QString& id, int current, int tot } ui->pbProblemCases->setMaximum(total); ui->pbProblemCases->setValue(current); -// ui->lblProblem->setText(mOJProblemModel.getProblemTitle()); + // ui->lblProblem->setText(mOJProblemModel.getProblemTitle()); +} + +void MainWindow::onOJProblemCaseNewOutputLineGetted(const QString &id, const QString &line) +{ + ui->txtProblemCaseOutput->append(line); } void MainWindow::cleanUpCPUDialog() diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 9997d355..949ba708 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -174,6 +174,7 @@ public slots: void onRunProblemFinished(); void onOJProblemCaseStarted(const QString& id, int current, int total); void onOJProblemCaseFinished(const QString& id, int current, int total); + void onOJProblemCaseNewOutputLineGetted(const QString& id, const QString& line); void cleanUpCPUDialog(); void onDebugCommandInput(const QString& command); void onDebugEvaluateInput(); diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index ec709366..a6499ae7 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -2878,6 +2878,36 @@ void Settings::Executor::setIgnoreSpacesWhenValidatingCases(bool newIgnoreSpaces mIgnoreSpacesWhenValidatingCases = newIgnoreSpacesWhenValidatingCases; } +bool Settings::Executor::caseEditorFontOnlyMonospaced() const +{ + return mCaseEditorFontOnlyMonospaced; +} + +void Settings::Executor::setCaseEditorFontOnlyMonospaced(bool newCaseEditorFontOnlyMonospaced) +{ + mCaseEditorFontOnlyMonospaced = newCaseEditorFontOnlyMonospaced; +} + +int Settings::Executor::caseEditorFontSize() const +{ + return mCaseEditorFontSize; +} + +void Settings::Executor::setCaseEditorFontSize(int newCaseEditorFontSize) +{ + mCaseEditorFontSize = newCaseEditorFontSize; +} + +const QString &Settings::Executor::caseEditorFontName() const +{ + return mCaseEditorFontName; +} + +void Settings::Executor::setCaseEditorFontName(const QString &newCaseEditorFontName) +{ + mCaseEditorFontName = newCaseEditorFontName; +} + bool Settings::Executor::enableCompetitiveCompanion() const { return mEnableCompetitiveCompanion; @@ -2911,6 +2941,9 @@ void Settings::Executor::doSave() saveValue("enable_competivie_companion", mEnableCompetitiveCompanion); saveValue("competitive_companion_port", mCompetivieCompanionPort); saveValue("ignore_spaces_when_validating_cases", mIgnoreSpacesWhenValidatingCases); + saveValue("case_editor_font_name",mCaseEditorFontName); + saveValue("case_editor_font_size",mCaseEditorFontSize); + saveValue("case_editor_font_only_monospaced",mCaseEditorFontOnlyMonospaced); } bool Settings::Executor::pauseConsole() const @@ -2936,6 +2969,9 @@ void Settings::Executor::doLoad() mEnableCompetitiveCompanion = boolValue("enable_competivie_companion",true); mCompetivieCompanionPort = intValue("competitive_companion_port",10045); mIgnoreSpacesWhenValidatingCases = boolValue("ignore_spaces_when_validating_cases",false); + mCaseEditorFontName = stringValue("case_editor_font_name","consolas"); + mCaseEditorFontSize = intValue("case_editor_font_size",14); + mCaseEditorFontOnlyMonospaced = boolValue("case_editor_font_only_monospaced",true); } diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index a29b37ca..6046e595 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -797,6 +797,15 @@ public: bool ignoreSpacesWhenValidatingCases() const; void setIgnoreSpacesWhenValidatingCases(bool newIgnoreSpacesWhenValidatingCases); + const QString &caseEditorFontName() const; + void setCaseEditorFontName(const QString &newCaseEditorFontName); + + int caseEditorFontSize() const; + void setCaseEditorFontSize(int newCaseEditorFontSize); + + bool caseEditorFontOnlyMonospaced() const; + void setCaseEditorFontOnlyMonospaced(bool newCaseEditorFontOnlyMonospaced); + private: // general bool mPauseConsole; @@ -811,6 +820,9 @@ public: bool mEnableCompetitiveCompanion; int mCompetivieCompanionPort; bool mIgnoreSpacesWhenValidatingCases; + QString mCaseEditorFontName; + int mCaseEditorFontSize; + bool mCaseEditorFontOnlyMonospaced; protected: void doSave() override; diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp b/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp index 3b80f14b..677500f3 100644 --- a/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.cpp @@ -21,6 +21,10 @@ void ExecutorProblemSetWidget::doLoad() ui->grpCompetitiveCompanion->setChecked(pSettings->executor().enableCompetitiveCompanion()); ui->spinPortNumber->setValue(pSettings->executor().competivieCompanionPort()); ui->chkIgnoreSpacesWhenValidatingCases->setChecked(pSettings->executor().ignoreSpacesWhenValidatingCases()); + + ui->cbFont->setCurrentFont(QFont(pSettings->executor().caseEditorFontName())); + ui->spinFontSize->setValue(pSettings->executor().caseEditorFontSize()); + ui->chkOnlyMonospaced->setChecked(pSettings->executor().caseEditorFontOnlyMonospaced()); } void ExecutorProblemSetWidget::doSave() @@ -29,6 +33,19 @@ void ExecutorProblemSetWidget::doSave() pSettings->executor().setEnableCompetitiveCompanion(ui->grpCompetitiveCompanion->isChecked()); pSettings->executor().setCompetivieCompanionPort(ui->spinPortNumber->value()); pSettings->executor().setIgnoreSpacesWhenValidatingCases(ui->chkIgnoreSpacesWhenValidatingCases->isChecked()); + pSettings->executor().setCaseEditorFontName(ui->cbFont->currentFont().family()); + pSettings->executor().setCaseEditorFontOnlyMonospaced(ui->chkOnlyMonospaced->isChecked()); + pSettings->executor().setCaseEditorFontSize(ui->spinFontSize->value()); pSettings->executor().save(); pMainWindow->applySettings(); } + +void ExecutorProblemSetWidget::on_chkOnlyMonospaced_stateChanged(int ) +{ + if (ui->chkOnlyMonospaced->isChecked()) { + ui->cbFont->setFontFilters(QFontComboBox::FontFilter::MonospacedFonts); + } else { + ui->cbFont->setFontFilters(QFontComboBox::FontFilter::AllFonts); + } +} + diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.h b/RedPandaIDE/settingsdialog/executorproblemsetwidget.h index cbae0196..1d0da60f 100644 --- a/RedPandaIDE/settingsdialog/executorproblemsetwidget.h +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.h @@ -21,6 +21,8 @@ private: protected: void doLoad() override; void doSave() override; +private slots: + void on_chkOnlyMonospaced_stateChanged(int arg1); }; #endif // EXECUTORPROBLEMSETWIDGET_H diff --git a/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui b/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui index a0d40ba5..bd893dce 100644 --- a/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui +++ b/RedPandaIDE/settingsdialog/executorproblemsetwidget.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 545 + 445 @@ -72,6 +72,117 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Font Size: + + + + + + + Font: + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + Only Monospaced + + +