From ab9524e134002feb08b8c619db694b73ff6b5d63 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 13 Jul 2023 10:08:01 +0800 Subject: [PATCH] - change: Don't print repeated values in gdb individually --- NEWS.md | 1 + RedPandaIDE/debugger.cpp | 7 +- RedPandaIDE/mainwindow.cpp | 42 +-- RedPandaIDE/translations/RedPandaIDE_pt_BR.ts | 7 + RedPandaIDE/translations/RedPandaIDE_zh_CN.ts | 335 +++++++++--------- RedPandaIDE/translations/RedPandaIDE_zh_TW.ts | 7 + RedPandaIDE/widgets/linenumbertexteditor.cpp | 33 ++ RedPandaIDE/widgets/linenumbertexteditor.h | 5 + 8 files changed, 233 insertions(+), 204 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8ecab2aa..13922f0f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -44,6 +44,7 @@ Red Panda C++ Version 2.23 - enhancement: Add the option "redirect stderr to the Tools output panel" in the options dialog -> executor -> problem set page. - fix: Can't correctly uncomment multiple "//" comment lines that doesn't have spaces at linestarts. - fix: Autoindent for "{" is not correct. + - change: Don't print repeated values in gdb individually Red Panda C++ Version 2.22 diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 6a42e914..db738365 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -1626,13 +1626,16 @@ void DebugReader::handleStack(const QList & stack void DebugReader::handleLocalVariables(const QList &variables) { QStringList locals; + QRegularExpression exp(""); foreach (const GDBMIResultParser::ParseValue& varValue, variables) { GDBMIResultParser::ParseObject varObject = varValue.object(); + QString name = QString(varObject["name"].value()); + QString value = QString(varObject["value"].value()).replace(exp, tr("")); locals.append( QString("%1 = %2") .arg( - QString(varObject["name"].value()), - QString(varObject["value"].value()) + name, + value )); } emit localsUpdated(locals); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 914a7103..ee730f2e 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -2424,7 +2424,7 @@ void MainWindow::debug() mDebugger->sendCommand("-data-list-register-names",""); mDebugger->sendCommand("-gdb-set", "width 0"); // don't wrap output, very annoying mDebugger->sendCommand("-gdb-set", "confirm off"); - mDebugger->sendCommand("-gdb-set", "print repeats 0"); // don't repeat elements + mDebugger->sendCommand("-gdb-set", "print repeats 10"); mDebugger->sendCommand("-gdb-set", QString("print elements %1").arg(pSettings->debugger().arrayElements())); // limit array elements to 500 //mDebugger->sendCommand("-environment-cd", QString("\"%1\"").arg(extractFileDir(filePath))); // restore working directory if (pSettings->debugger().useGDBServer()) { @@ -8015,49 +8015,17 @@ void MainWindow::updateProblemCaseOutput(POJProblemCase problemCase) } else return; if (diffLine < problemCase->outputLineCounts) { - QTextBlock block = ui->txtProblemCaseOutput->document()->findBlockByLineNumber(diffLine); - if (!block.isValid()) - return; - QTextCursor cur(block); - if (cur.isNull()) - return; - cur = QTextCursor(block); - QTextCharFormat oldFormat = cur.charFormat(); - QTextCharFormat format = QTextCharFormat(cur.charFormat()); - cur.select(QTextCursor::LineUnderCursor); - format.setUnderlineColor(mErrorColor); - format.setUnderlineStyle(QTextCharFormat::WaveUnderline); - format.setTextOutline(mErrorColor); - cur.setCharFormat(format); - cur.clearSelection(); - cur.setCharFormat(oldFormat); - ui->txtProblemCaseOutput->setTextCursor(cur); - ui->txtProblemCaseOutput->moveCursor(QTextCursor::MoveOperation::StartOfLine); + ui->txtProblemCaseOutput->highlightLine(diffLine, mErrorColor); } else { ui->txtProblemCaseOutput->moveCursor(QTextCursor::MoveOperation::End); ui->txtProblemCaseOutput->moveCursor(QTextCursor::MoveOperation::StartOfLine); } if (diffLine < problemCase->expectedLineCounts) { - QTextBlock block = ui->txtProblemCaseExpected->document()->findBlockByLineNumber(diffLine); - if (!block.isValid()) - return; - QTextCursor cur(block); - if (cur.isNull()) - return; - cur = QTextCursor(block); if (ui->txtProblemCaseExpected->document()->blockCount()<=5000) { - QTextCharFormat oldFormat = cur.charFormat(); - QTextCharFormat format = QTextCharFormat(cur.charFormat()); - cur.select(QTextCursor::LineUnderCursor); - format.setUnderlineColor(mErrorColor); - format.setUnderlineStyle(QTextCharFormat::WaveUnderline); - format.setTextOutline(mErrorColor); - cur.setCharFormat(format); - cur.clearSelection(); - cur.setCharFormat(oldFormat); + ui->txtProblemCaseExpected->highlightLine(diffLine, mErrorColor); + } else { + ui->txtProblemCaseExpected->locateLine(diffLine); } - ui->txtProblemCaseExpected->setTextCursor(cur); - ui->txtProblemCaseExpected->moveCursor(QTextCursor::MoveOperation::StartOfLine); } else { ui->txtProblemCaseExpected->moveCursor(QTextCursor::MoveOperation::End); ui->txtProblemCaseExpected->moveCursor(QTextCursor::MoveOperation::StartOfLine); diff --git a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts index 58c74d3b..0356c052 100644 --- a/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts +++ b/RedPandaIDE/translations/RedPandaIDE_pt_BR.ts @@ -929,6 +929,13 @@ + + DebugReader + + <repeats \1 times> + + + Debugger diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts index 609d11d9..66a7edf3 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_CN.ts @@ -193,17 +193,17 @@ p, li { white-space: pre-wrap; } BacktraceModel - + Function 函数 - + Filename 文件名 - + Line @@ -249,17 +249,17 @@ p, li { white-space: pre-wrap; } BreakpointModel - + Filename 文件名 - + Line - + Condition 条件 @@ -1323,6 +1323,11 @@ Are you really want to continue? Please turn off your compiler set's "Strip executable (-s)" option, recompile and retry debug. 请在选项对话框的编译器配置集页中取消“剥除附加信息(-s)”选项,重新编译后再调试。 + + + <repeats \1 times> + <重复\1次> + Debugger @@ -4777,7 +4782,7 @@ Are you really want to continue? - + New Problem Set 新建试题集 @@ -4799,7 +4804,7 @@ Are you really want to continue? - + Save Problem Set 保存试题集 @@ -4807,7 +4812,7 @@ Are you really want to continue? - + Load Problem Set 载入试题集 @@ -4938,14 +4943,14 @@ Are you really want to continue? - + Import FPS Problem Set 导入FPS试题集 - + Export FPS Problem Set 导出FPS试题集 @@ -5623,13 +5628,13 @@ Are you really want to continue? - + Export As RTF 导出为RTF - + Export As HTML 导出为HTML @@ -6187,22 +6192,22 @@ Are you really want to continue? 全部复制 - + Go to Line 跳转到行 - + Line - + Template Exists 模板已存在 - + Template %1 already exists. Do you want to overwrite? 模板%1已存在。是否覆盖? @@ -6228,7 +6233,7 @@ Are you really want to continue? - + Problem Set %1 试题集%1 @@ -6298,15 +6303,15 @@ Are you really want to continue? - - + + Bookmark Description 书签描述 - - + + Description: 描述: @@ -6623,12 +6628,12 @@ Are you really want to continue? 保存设置失败 - + Watchpoint variable name 被监控的变量 - + Stop execution when the following variable is modified (it must be visible from the currect scope): 当下面的变量被修改时暂停执行(该变量必须可以从当前程序处访问): @@ -6637,17 +6642,17 @@ Are you really want to continue? 中止 - + FPS Problem Set Files (*.fps;*.xml) FPS试题集文件(*.fps;*.xml) - + FPS Problem Set Files (*.fps) FPS试题集文件(*.fps) - + Export Error 导出时出错 @@ -6709,7 +6714,7 @@ Are you really want to continue? - + Do you want to save it? 需要保存吗? @@ -6721,15 +6726,15 @@ Are you really want to continue? - - + + New Project File? 新建项目文件? - - + + Do you want to add the new file to the project? 您是否要将新建的文件加入项目? @@ -6738,7 +6743,7 @@ Are you really want to continue? - + Save Error 保存失败 @@ -6840,18 +6845,18 @@ Are you really want to continue? 你真的要删除它吗? - + Change working folder 改变工作文件夹 - + File '%1' is not in the current working folder. File '%1' is not in the current working folder 文件'%1'不在当前工作文件夹中。 - + Do you want to change working folder to '%1'? 是否将工作文件夹改设为'%1'? @@ -6860,28 +6865,28 @@ Are you really want to continue? 正在删除试题... - + Can't Commit 无法提交 - + Git needs user info to commit. Git需要用信息进行提交。 - + Choose Input Data File 选择输入数据文件 - - + + All files (*.*) 所有文件 (*.*) - + Choose Expected Output Data File Choose Expected Input Data File 选择期望输出文件 @@ -6893,59 +6898,59 @@ Are you really want to continue? - + Choose Working Folder 选择工作文件夹 - - + + Header Exists 头文件已存在 - - + + Header file "%1" already exists! 头文件"%1"已存在! - + Source Exists 源文件已存在! - + Source file "%1" already exists! 源文件"%1"已存在! - + Can't commit! 无法提交! - + The following files are in conflicting: 下列文件处于冲突状态,请解决后重新添加和提交: - + Commit Message 提交信息 - + Commit Message: 提交信息: - + Commit Failed 提交失败 - + Commit message shouldn't be empty! 提交信息不能为空! @@ -7084,58 +7089,58 @@ Are you really want to continue? 新名称 - + + + - - Replace Error 替换出错 - + Can't open file '%1' for replace! 无法打开文件'%1'进行替换! - + Contents has changed since last search! 内容和上次查找时不一致。 - + Rich Text Format Files (*.rtf) RTF格式文件 (*.rtf) - + HTML Files (*.html) HTML文件 (*.html) - + The current problem set is not empty. 当前的试题集不是空的。 - + Problem %1 试题%1 - - + + Problem Set Files (*.pbs) 试题集文件 (*.pbs) - - + + Load Error 载入失败 - + Problem Case %1 试题案例%1 @@ -7153,7 +7158,7 @@ Are you really want to continue? - + Error 错误 @@ -7227,7 +7232,7 @@ Are you really want to continue? - + Confirm Convertion 确认转换 @@ -7242,7 +7247,7 @@ Are you really want to continue? - + The editing file will be saved using %1 encoding. <br />This operation can't be reverted. <br />Are you sure to continue? 当前编辑器中的文件将会使用%1编码保存。<br />这项操作无法被撤回。<br />你确定要继续吗? @@ -7276,17 +7281,17 @@ Are you really want to continue? MemoryModel - + addr: %1 地址: %1 - + dec: %1 十进制: %1 - + oct: %1 八进制: %1 @@ -7295,12 +7300,12 @@ Are you really want to continue? 16进制: %1 - + bin: %1 二进制: %1 - + ascii: '%1' ASCII字符: '%1' @@ -9363,9 +9368,6 @@ Are you really want to continue? RegisterModel - - - @@ -9380,14 +9382,17 @@ Are you really want to continue? - - - + + + + + + 64-bit 64位 @@ -9396,22 +9401,22 @@ Are you really want to continue? 累加器 - - - - - - + + + + + + General purpose 通用 @@ -9420,9 +9425,6 @@ Are you really want to continue? 指令 - - - @@ -9437,13 +9439,13 @@ Are you really want to continue? + + + 32-bit 32位 - - - @@ -9458,13 +9460,13 @@ Are you really want to continue? + + + lower 16 bits of %1 %1的低16位 - - - @@ -9478,24 +9480,27 @@ Are you really want to continue? + + + lower 8 bits of %1 %1的低8位 - - - + + + 8 high bits of lower 16 bits of %1 %1的低16位数据中的高8位 - - - + + + 16-bit 16位 @@ -9508,9 +9513,6 @@ Are you really want to continue? 媒体 - - - @@ -9523,147 +9525,147 @@ Are you really want to continue? + + + 128-bit 128位 - + Floating-point control 浮点运算控制 - - + + Accumulator for operands and results data 操作数和结果的累加器 - - + + Pointer to data in the DS segment 指向DS段中数据的指针 - - + + Counter for string and loop operations 字符串和循环操作计数器 - - + + I/O pointer I/O指针 - - + + Source index for string operations; Pointer to data in the segment pointed to by the DS register 字符串操作来源下标;指向DS段中数据的指针 - - + + Destination index for string operations; Pointer to data (or destination) in the segment pointed to by the ES register 字符串操作目的下标;指向ES段中数据(或目标)的指针 - - + + Stack pointer (in the SS segment) 栈指针(在SS段中) - - + + Pointer to data on the stack (in the SS segment) 指向(SS段中)栈内数据的指针 - - + + Instruction pointer 指令指针 - - + + Flags 标志 - + Code segment selector 代码段选择器 - + Data segment selector 数据段选择器 - - - + + + Extra data segment selector 额外的数据段选择器 - + Stack segment selector 栈段选择器 - - - + + + Floating-point data 浮点运算数据 - + Floating-point status 浮点运算状态 - + Floating-point tag word 浮点运算标签word - + Floating-point operation 浮点运算操作 - + Floating-point last instruction segment 浮点运算上次指令段 - + Floating-point last instruction offset 浮点运算上次指令位移 - + Floating-point last operand segment 浮点运算上次操作数段 - + Floating-point last operand offset 浮点运算上次操作数位移 - - - @@ -9676,21 +9678,24 @@ Are you really want to continue? + + + 256-bit 256位 - + SSE status and control SSE状态和控制 - + Register 寄存器 - + Value @@ -10396,8 +10401,8 @@ Are you really want to continue? - - + + Compiler Set @@ -10405,7 +10410,7 @@ Are you really want to continue? - + Compiler @@ -10417,7 +10422,7 @@ Are you really want to continue? 自动链接 - + @@ -10493,15 +10498,15 @@ Are you really want to continue? 杂项 - - + + Program Runner 程序运行 - + Problem Set 试题集 @@ -10561,7 +10566,7 @@ Are you really want to continue? - + @@ -11041,14 +11046,14 @@ Are you really want to continue? JSON文件'%1':%2中存在错误:%3 - - + + Execute to evaluate 执行以求值 - - + + Not Valid 在当前作用域中无效 @@ -11057,17 +11062,17 @@ Are you really want to continue? 无法读取文件'%1'. - + Expression 表达式 - + Type 类型 - + Value diff --git a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts index 6b8ff0f8..20f96b8e 100644 --- a/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts +++ b/RedPandaIDE/translations/RedPandaIDE_zh_TW.ts @@ -790,6 +790,13 @@ + + DebugReader + + <repeats \1 times> + + + Debugger diff --git a/RedPandaIDE/widgets/linenumbertexteditor.cpp b/RedPandaIDE/widgets/linenumbertexteditor.cpp index 100f35de..f4e9406b 100644 --- a/RedPandaIDE/widgets/linenumbertexteditor.cpp +++ b/RedPandaIDE/widgets/linenumbertexteditor.cpp @@ -95,6 +95,39 @@ void LineNumberTextEditor::clearAll() clearStartFormat(); } +void LineNumberTextEditor::highlightLine(int line, QColor highlightColor) +{ + QTextBlock block = document()->findBlockByLineNumber(line); + if (!block.isValid()) + return; + QTextCursor cur(block); + if (cur.isNull()) + return; + QTextCharFormat oldFormat = cur.charFormat(); + QTextCharFormat format = QTextCharFormat(cur.charFormat()); + cur.select(QTextCursor::LineUnderCursor); + format.setUnderlineColor(highlightColor); + format.setUnderlineStyle(QTextCharFormat::WaveUnderline); + format.setTextOutline(highlightColor); + cur.setCharFormat(format); + cur.clearSelection(); + cur.setCharFormat(oldFormat); + setTextCursor(cur); + moveCursor(QTextCursor::MoveOperation::StartOfLine); +} + +void LineNumberTextEditor::locateLine(int line) +{ + QTextBlock block = document()->findBlockByLineNumber(line); + if (!block.isValid()) + return; + QTextCursor cur(block); + if (cur.isNull()) + return; + setTextCursor(cur); + moveCursor(QTextCursor::MoveOperation::StartOfLine); +} + const QColor &LineNumberTextEditor::lineNumberAreaBackground() const { return mLineNumberAreaBackground; diff --git a/RedPandaIDE/widgets/linenumbertexteditor.h b/RedPandaIDE/widgets/linenumbertexteditor.h index 911d928b..602e0224 100644 --- a/RedPandaIDE/widgets/linenumbertexteditor.h +++ b/RedPandaIDE/widgets/linenumbertexteditor.h @@ -18,6 +18,7 @@ #define LINENUMBERTEXTEDITOR_H #include +#include class LineNumberTextEditor : public QPlainTextEdit { @@ -41,6 +42,10 @@ public: void clearAll(); + void highlightLine(int line, QColor highlightColor); + + void locateLine(int line); + signals: void lineNumberAreaCurrentLineChanged();