From 002f9d48050611cfaf5652030ea77701f88ecb20 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 28 Jan 2022 00:31:11 +0800 Subject: [PATCH] - fix: mainwindow action's short cut doesn't work, if the action is not in menu or toolbar - fix: when run all cases for a problem, processing of output is slow --- NEWS.md | 1 + RedPandaIDE/compiler/compilermanager.cpp | 2 +- RedPandaIDE/compiler/ojproblemcasesrunner.cpp | 35 ++++++------------- RedPandaIDE/compiler/ojproblemcasesrunner.h | 2 +- RedPandaIDE/mainwindow.cpp | 11 +++--- RedPandaIDE/mainwindow.h | 2 +- RedPandaIDE/mainwindow.ui | 27 +++++--------- 7 files changed, 28 insertions(+), 52 deletions(-) diff --git a/NEWS.md b/NEWS.md index 408a8a95..07bf110e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ Red Panda C++ Version 0.14.0 - fix: code folding calcuation not correct when some codes are folded and editing after them - enhancement: code completion ui redesigned - fix: mainwindow action's short cut doesn't work, if the action is not in menu or toolbar + - fix: when run all cases for a problem, processing of output is slow Red Panda C++ Version 0.13.4 - fix: when copy comments, don't auto indent diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 14035398..fe32c699 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -325,7 +325,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); + connect(execRunner, &OJProblemCasesRunner::newOutputGetted, pMainWindow, &MainWindow::onOJProblemCaseNewOutputGetted); mRunner->start(); } diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp index 32129fd4..e2ccf6e2 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.cpp +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.cpp @@ -79,10 +79,10 @@ void OJProblemCasesRunner::runCase(int index,POJProblemCase problemCase) } QByteArray readed; QByteArray buffer; - QStringList outputLines; + QByteArray output; while (true) { process.waitForFinished(100); - readed = process.readAll(); + readed = process.read(5001); buffer += readed; if (process.state()!=QProcess::Running) { break; @@ -97,30 +97,15 @@ 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); - } + if (buffer.length()>5000) { + emit newOutputGetted(problemCase->getId(),QString::fromLocal8Bit(buffer)); + output.append(buffer); + buffer.clear(); } } - buffer += process.readAll(); - QList lines = splitByteArrayToLines(buffer); - for (int i=0;igetId(),line); - outputLines.append(line); - } + if (process.state() == QProcess::ProcessState::NotRunning) + buffer += process.readAll(); + output.append(buffer); if (errorOccurred) { //qDebug()<<"process error:"<output = linesToText(outputLines); + problemCase->output = QString::fromLocal8Bit(output); } void OJProblemCasesRunner::run() diff --git a/RedPandaIDE/compiler/ojproblemcasesrunner.h b/RedPandaIDE/compiler/ojproblemcasesrunner.h index 1e28b9b9..c4d127b3 100644 --- a/RedPandaIDE/compiler/ojproblemcasesrunner.h +++ b/RedPandaIDE/compiler/ojproblemcasesrunner.h @@ -32,7 +32,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); + void newOutputGetted(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 af511bd0..5d4d887f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -3117,9 +3117,9 @@ void MainWindow::onProblemCaseIndexChanged(const QModelIndex ¤t, const QMo POJProblemCase problemCase = mOJProblemModel.getCase(idx.row()); if (problemCase) { ui->btnRemoveProblemCase->setEnabled(true); - ui->txtProblemCaseInput->setText(problemCase->input); + ui->txtProblemCaseInput->setPlainText(problemCase->input); ui->txtProblemCaseInput->setReadOnly(false); - ui->txtProblemCaseExpected->setText(problemCase->expected); + ui->txtProblemCaseExpected->setPlainText(problemCase->expected); ui->txtProblemCaseExpected->setReadOnly(false); updateProblemCaseOutput(problemCase); return; @@ -4081,9 +4081,9 @@ void MainWindow::onOJProblemCaseFinished(const QString& id, int current, int tot updateProblemTitle(); } -void MainWindow::onOJProblemCaseNewOutputLineGetted(const QString &, const QString &line) +void MainWindow::onOJProblemCaseNewOutputGetted(const QString &, const QString &line) { - ui->txtProblemCaseOutput->append(line); + ui->txtProblemCaseOutput->appendPlainText(line); } void MainWindow::cleanUpCPUDialog() @@ -5519,7 +5519,7 @@ void MainWindow::doCompileRun(RunType runType) void MainWindow::updateProblemCaseOutput(POJProblemCase problemCase) { ui->txtProblemCaseOutput->clear(); - ui->txtProblemCaseOutput->setText(problemCase->output); + ui->txtProblemCaseOutput->setPlainText(problemCase->output); if (problemCase->testState == ProblemCaseTestState::Failed) { QStringList output = textToLines(problemCase->output); QStringList expected = textToLines(problemCase->expected); @@ -5666,7 +5666,6 @@ void MainWindow::on_actionExport_As_HTML_triggered() void MainWindow::on_actionMove_To_Other_View_triggered() { - qDebug()<<"test"; Editor * editor = mEditorList->getEditor(); if (editor) { mEditorList->swapEditor(editor); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index a0bf2324..c938f3ba 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -194,7 +194,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 onOJProblemCaseNewOutputGetted(const QString& id, const QString& line); void cleanUpCPUDialog(); void onDebugCommandInput(const QString& command); void onDebugEvaluateInput(); diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index af778c50..480c1d88 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -506,7 +506,7 @@ QTabWidget::South - 5 + 6 @@ -1348,33 +1348,24 @@ - - + + - QTextEdit::NoWrap - - - false + QPlainTextEdit::NoWrap - - + + - QTextEdit::NoWrap - - - true + QPlainTextEdit::NoWrap - + - QTextEdit::NoWrap - - - false + QPlainTextEdit::NoWrap