From 3aeaa5477fb786c740325cdc823b19cefa2c7e80 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Sun, 12 Jul 2026 15:38:58 +0200 Subject: [PATCH] PMsrHighlighter: fix keyword bugs and C++17 tidy-ups - Fix missing comma that concatenated "ab" and "skg" into the bogus keyword "abskg", dropping abragam/skewedGss highlighting. - Remove duplicate "snkzf" short name in the theory keyword list. - Add missing theory keywords: "sg" (simpleGss short form), "userFcn" and its short form "u", to match src/include/PTheory.h. - Use std::as_const in highlightBlock's range-for to avoid a potential QVector detach on every call. - Pass QTextCharFormat to addRule by const reference. Co-Authored-By: Claude Opus 4.8 --- src/musredit_qt6/musredit/PMsrHighlighter.cpp | 15 +++++++++------ src/musredit_qt6/musredit/PMsrHighlighter.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/musredit_qt6/musredit/PMsrHighlighter.cpp b/src/musredit_qt6/musredit/PMsrHighlighter.cpp index c4adbfda..cf134cfd 100644 --- a/src/musredit_qt6/musredit/PMsrHighlighter.cpp +++ b/src/musredit_qt6/musredit/PMsrHighlighter.cpp @@ -30,6 +30,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include + #include #include #include //as35 @@ -170,12 +172,13 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) "Bessel", "internbsl", "internFldGK", "internFldLL", "F_mu_F", "abragam", "skewedGss", "staticNKZF", "staticNKTF", "dynamicNKZF", "dynamicNKTF", "muMinusExpTF", - "polynom"}; + "polynom", "userFcn"}; QStringList theory_keywords_short = {"c", "a", "se", "ge", + "sg", "stg", "sgktlf", "dgktlf", @@ -196,15 +199,15 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) "ifgk", "ifll", "fmuf", - "ab" + "ab", "skg", "snkzf", "snktf", - "snkzf", "dnkzf", "dnktf", "mmsetf", - "p"}; + "p", + "u"}; // combine both theory keyword lists QStringList theory_keywords = theory_keywords_long + theory_keywords_short; @@ -457,7 +460,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) * to the Qt layout interface engine. */ void PMsrHighlighter::addRule(const QStringList &keywords, - const QTextCharFormat formatting) { + const QTextCharFormat &formatting) { // Instantiate the HighlighingRule struct. HighlightingRule rule; @@ -488,7 +491,7 @@ void PMsrHighlighter::addRule(const QStringList &keywords, void PMsrHighlighter::highlightBlock(const QString &text) { // Sequentially process each entry stored inside the rules vector array. - for (const HighlightingRule &rule : highlightingRules) { + for (const HighlightingRule &rule : std::as_const(highlightingRules)) { // Execute a global search through the single block string provided. QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); diff --git a/src/musredit_qt6/musredit/PMsrHighlighter.h b/src/musredit_qt6/musredit/PMsrHighlighter.h index 2f14aa79..1ad25ce6 100644 --- a/src/musredit_qt6/musredit/PMsrHighlighter.h +++ b/src/musredit_qt6/musredit/PMsrHighlighter.h @@ -96,7 +96,7 @@ private: * @brief Helper function for passing formatting information to the * highlightingRules dynamic array. */ - void addRule(const QStringList &keywords, const QTextCharFormat formatting); + void addRule(const QStringList &keywords, const QTextCharFormat &formatting); QTextCharFormat blockFormat; ///< Formatting profile for BLOCK keywords. QTextCharFormat titleFormat; ///< Formatting profile for TITLE line.