- enhancement: In problem view's output control, indicates which line is different with the expected

- fix: current input/expected not correctly applied when save/run problem cases
 - fix: colors of the syntax issues view are not correctly set using the current color sheme
This commit is contained in:
royqh1979 2021-11-02 19:26:11 +08:00
parent 5ba79d522a
commit b6ab20e69e
4 changed files with 78 additions and 13 deletions

View File

@ -1,3 +1,8 @@
Version 0.7.8
- enhancement: In problem view's output control, indicates which line is different with the expected
- fix: current input/expected not correctly applied when save/run problem cases
- fix: colors of the syntax issues view are not correctly set using the current color sheme
Version 0.7.7 Version 0.7.7
- enhancement: Problem Set - enhancement: Problem Set
- enhancement: Competitive Companion Support - enhancement: Competitive Companion Support

View File

@ -34,6 +34,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QMimeData> #include <QMimeData>
#include <QTcpSocket> #include <QTcpSocket>
#include <QTextBlock>
#include <QTranslator> #include <QTranslator>
#include "settingsdialog/settingsdialog.h" #include "settingsdialog/settingsdialog.h"
@ -114,10 +115,6 @@ MainWindow::MainWindow(QWidget *parent)
// ui->actionIndent->setShortcut(Qt::Key_Tab); // ui->actionIndent->setShortcut(Qt::Key_Tab);
// ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier); // ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier);
ui->tableIssues->setErrorColor(QColor("Red"));
ui->tableIssues->setWarningColor(QColor("Orange"));
mMenuNew = new QMenu(); mMenuNew = new QMenu();
mMenuNew->setTitle(tr("New")); mMenuNew->setTitle(tr("New"));
mMenuNew->addAction(ui->actionNew); mMenuNew->addAction(ui->actionNew);
@ -516,6 +513,19 @@ void MainWindow::updateEditorColorSchemes()
mStatementColors->insert(StatementKind::skNamespace,item); mStatementColors->insert(StatementKind::skNamespace,item);
mStatementColors->insert(StatementKind::skNamespaceAlias,item); mStatementColors->insert(StatementKind::skNamespaceAlias,item);
} }
item = pColorManager->getItem(schemeName, COLOR_SCHEME_ERROR);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
mErrorColor = item->foreground();
} else {
mErrorColor = palette().color(QPalette::Text);
}
ui->tableIssues->setErrorColor(mErrorColor);
item = pColorManager->getItem(schemeName, COLOR_SCHEME_WARNING);
if (item && haveGoodContrast(item->foreground(), baseColor)) {
ui->tableIssues->setWarningColor(item->foreground());
} else {
ui->tableIssues->setWarningColor(palette().color(QPalette::Text));
}
} }
void MainWindow::applySettings() void MainWindow::applySettings()
@ -2560,7 +2570,7 @@ void MainWindow::onFilesViewContextMenu(const QPoint &pos)
menu.exec(ui->treeFiles->mapToGlobal(pos)); menu.exec(ui->treeFiles->mapToGlobal(pos));
} }
void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &previous) void MainWindow::onProblemSetIndexChanged(const QModelIndex &current, const QModelIndex &/* previous */)
{ {
QModelIndex idx = current; QModelIndex idx = current;
if (!idx.isValid()) { if (!idx.isValid()) {
@ -2599,8 +2609,7 @@ void MainWindow::onProblemCaseIndexChanged(const QModelIndex &current, const QMo
ui->txtProblemCaseInput->setReadOnly(false); ui->txtProblemCaseInput->setReadOnly(false);
ui->txtProblemCaseExpected->setText(problemCase->expected); ui->txtProblemCaseExpected->setText(problemCase->expected);
ui->txtProblemCaseExpected->setReadOnly(false); ui->txtProblemCaseExpected->setReadOnly(false);
ui->txtProblemCaseOutput->setText(problemCase->output); updateProblemCaseOutput(problemCase);
ui->txtProblemCaseOutput->setReadOnly(true);
return; return;
} }
} }
@ -2610,7 +2619,6 @@ void MainWindow::onProblemCaseIndexChanged(const QModelIndex &current, const QMo
ui->txtProblemCaseExpected->clear(); ui->txtProblemCaseExpected->clear();
ui->txtProblemCaseExpected->setReadOnly(true); ui->txtProblemCaseExpected->setReadOnly(true);
ui->txtProblemCaseOutput->clear(); ui->txtProblemCaseOutput->clear();
ui->txtProblemCaseOutput->setReadOnly(true);
} }
void MainWindow::onProblemNameChanged(int index) void MainWindow::onProblemNameChanged(int index)
@ -2836,7 +2844,7 @@ void MainWindow::enableDebugActions()
ui->cbMemoryAddress->setEnabled(true); ui->cbMemoryAddress->setEnabled(true);
} }
void MainWindow::onTodoParseStarted(const QString& filename) void MainWindow::onTodoParseStarted(const QString&)
{ {
mTodoModel.clear(); mTodoModel.clear();
} }
@ -3459,8 +3467,9 @@ void MainWindow::onOJProblemCaseFinished(const QString &id, int current, int tot
mOJProblemModel.update(row); mOJProblemModel.update(row);
QModelIndex idx = ui->lstProblemCases->currentIndex(); QModelIndex idx = ui->lstProblemCases->currentIndex();
if (idx.isValid()) { if (idx.isValid()) {
if (row == idx.row()) if (row == idx.row()) {
ui->txtProblemCaseOutput->setText(problemCase->output); updateProblemCaseOutput(problemCase);
}
} }
} }
ui->pbProblemCases->setMaximum(total); ui->pbProblemCases->setMaximum(total);
@ -4794,6 +4803,48 @@ void MainWindow::doCompileRun(RunType runType)
compile(); compile();
} }
void MainWindow::updateProblemCaseOutput(POJProblemCase problemCase)
{
ui->txtProblemCaseOutput->clear();
ui->txtProblemCaseOutput->setText(problemCase->output);
if (problemCase->testState == ProblemCaseTestState::Failed) {
QStringList output = TextToLines(problemCase->output);
QStringList expected = TextToLines(problemCase->expected);
for (int i=0;i<output.count();i++) {
if (i>=expected.count() || output[i]!=expected[i]) {
QTextBlock block = ui->txtProblemCaseOutput->document()->findBlockByLineNumber(i);
QTextCursor cur(block);
cur.select(QTextCursor::LineUnderCursor);
QTextCharFormat format = cur.charFormat();
format.setUnderlineColor(mErrorColor);
format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
cur.setCharFormat(format);
}
}
if (output.count()<expected.count()) {
QTextBlock block = ui->txtProblemCaseOutput->document()->findBlockByLineNumber(output.count()-1);
QTextCursor cur(block);
cur.select(QTextCursor::LineUnderCursor);
QTextCharFormat format = cur.charFormat();
format.setUnderlineColor(mErrorColor);
format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
cur.setCharFormat(format);
}
}
}
void MainWindow::applyCurrentProblemCaseChanges()
{
QModelIndex idx = ui->lstProblemCases->currentIndex();
if (idx.isValid()) {
POJProblemCase problemCase = mOJProblemModel.getCase(idx.row());
if (problemCase) {
problemCase->input = ui->txtProblemCaseInput->toPlainText();
problemCase->expected = ui->txtProblemCaseExpected->toPlainText();
}
}
}
Ui::MainWindow *MainWindow::mainWidget() const Ui::MainWindow *MainWindow::mainWidget() const
{ {
return ui; return ui;
@ -5097,6 +5148,7 @@ void MainWindow::on_btnSaveProblemSet_clicked()
tr("Problem Set Files (*.pbs)")); tr("Problem Set Files (*.pbs)"));
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
try { try {
applyCurrentProblemCaseChanges();
mOJProblemSetModel.saveToFile(fileName); mOJProblemSetModel.saveToFile(fileName);
} catch (FileError& error) { } catch (FileError& error) {
QMessageBox::critical(this,tr("Save Error"), QMessageBox::critical(this,tr("Save Error"),
@ -5144,6 +5196,7 @@ void MainWindow::on_btnAddProblemCase_clicked()
void MainWindow::on_btnRunAllProblemCases_clicked() void MainWindow::on_btnRunAllProblemCases_clicked()
{ {
applyCurrentProblemCaseChanges();
runExecutable(RunType::ProblemCases); runExecutable(RunType::ProblemCases);
} }

View File

@ -210,6 +210,8 @@ private:
void setFilesViewRoot(const QString& path); void setFilesViewRoot(const QString& path);
void clearIssues(); void clearIssues();
void doCompileRun(RunType runType); void doCompileRun(RunType runType);
void updateProblemCaseOutput(POJProblemCase problemCase);
void applyCurrentProblemCaseChanges();
private slots: private slots:
void onAutoSaveTimeout(); void onAutoSaveTimeout();
@ -527,6 +529,7 @@ private:
bool mSystemTurnedOff; bool mSystemTurnedOff;
QPoint mEditorContextMenuPos; QPoint mEditorContextMenuPos;
QTcpServer mTcpServer; QTcpServer mTcpServer;
QColor mErrorColor;
//actions for compile issue table //actions for compile issue table
QAction * mTableIssuesCopyAction; QAction * mTableIssuesCopyAction;

View File

@ -497,7 +497,7 @@
<enum>QTabWidget::South</enum> <enum>QTabWidget::South</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>6</number> <number>0</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -1308,7 +1308,11 @@
<widget class="QTextEdit" name="txtProblemCaseInput"/> <widget class="QTextEdit" name="txtProblemCaseInput"/>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QTextEdit" name="txtProblemCaseOutput"/> <widget class="QTextEdit" name="txtProblemCaseOutput">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QTextEdit" name="txtProblemCaseExpected"/> <widget class="QTextEdit" name="txtProblemCaseExpected"/>