diff --git a/src/musredit_qt6/musredit/PMsrHighlighter.cpp b/src/musredit_qt6/musredit/PMsrHighlighter.cpp index cf134cfd..b5fdaa9c 100644 --- a/src/musredit_qt6/musredit/PMsrHighlighter.cpp +++ b/src/musredit_qt6/musredit/PMsrHighlighter.cpp @@ -1,6 +1,6 @@ /** * @file PMsrHighlighter.cpp - * @brief Implementation of the MsrHighlighter class for musredit. + * @brief Implementation of the PMsrHighlighter class for musredit. * * This file contains the implementation of a custom syntax highlighter for * (.msr) files, to be used by musredit. It identifies, for example, blocks, @@ -91,65 +91,65 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) Qt::ColorScheme scheme = QGuiApplication::styleHints()->colorScheme(); if (scheme == Qt::ColorScheme::Light) { - blockFormat.setForeground(tabOlive); // BLOCK keywords - theoryFormat.setForeground(tabGreen); // THEORY keywords - functionsFormat.setForeground(tabRed); // FUNCTION keywords - parFormat.setForeground(tabPink); // parX keywords - mapFormat.setForeground(tabOrange); // mapX keywords - funFormat.setForeground(tabPurple); // funX keywords - runFormat.setForeground(tabGreen); // RUN/GLOBAL keywords - commandsFormat.setForeground(tabGreen); // COMMANDS keywords - fourierFormat.setForeground(tabGreen); // FOURIER keywords - plotFormat.setForeground(tabGreen); // PLOT keywords - optionsFormat.setForeground(tabRed); // keywords input options - infoFormat.setForeground(tabGray); // auto-printed information - boolFormat.setForeground(tabRed); // boolean strings - nullFormat.setForeground(tabRed); // null strings - dateFormat.setForeground(tabPink); // date & time strings - numberFormat.setForeground(tabBlue); // integer & float strings - commentFormat.setForeground(tabGray); // comments - commentFormat.setFontItalic(true); - titleFormat.setForeground(Qt::black); // title + fBlockFormat.setForeground(tabOlive); // BLOCK keywords + fTheoryFormat.setForeground(tabGreen); // THEORY keywords + fFunctionsFormat.setForeground(tabRed); // FUNCTION keywords + fParFormat.setForeground(tabPink); // parX keywords + fMapFormat.setForeground(tabOrange); // mapX keywords + fFunFormat.setForeground(tabPurple); // funX keywords + fRunFormat.setForeground(tabGreen); // RUN/GLOBAL keywords + fCommandsFormat.setForeground(tabGreen); // COMMANDS keywords + fFourierFormat.setForeground(tabGreen); // FOURIER keywords + fPlotFormat.setForeground(tabGreen); // PLOT keywords + fOptionsFormat.setForeground(tabRed); // keywords input options + fInfoFormat.setForeground(tabGray); // auto-printed information + fBoolFormat.setForeground(tabRed); // boolean strings + fNullFormat.setForeground(tabRed); // null strings + fDateFormat.setForeground(tabPink); // date & time strings + fNumberFormat.setForeground(tabBlue); // integer & float strings + fCommentFormat.setForeground(tabGray); // comments + fCommentFormat.setFontItalic(true); + fTitleFormat.setForeground(Qt::black); // title } else if (scheme == Qt::ColorScheme::Dark) { - blockFormat.setForeground(tabOlive); // BLOCK keywords - theoryFormat.setForeground(tabGreen); // THEORY keywords - functionsFormat.setForeground(tabRed); // FUNCTION keywords - parFormat.setForeground(tabPink); // parX keywords - mapFormat.setForeground(tabOrange); // mapX keywords - funFormat.setForeground(tabPurple); // funX keywords - runFormat.setForeground(tabGreen); // RUN/GLOBAL keywords - commandsFormat.setForeground(tabGreen); // COMMANDS keywords - fourierFormat.setForeground(tabGreen); // FOURIER keywords - plotFormat.setForeground(tabGreen); // PLOT keywords - optionsFormat.setForeground(tabRed); // keywords input options - infoFormat.setForeground(tabGray); // auto-printed information - boolFormat.setForeground(tabRed); // boolean strings - nullFormat.setForeground(tabRed); // null strings - dateFormat.setForeground(tabPink); // date & time strings - numberFormat.setForeground(tabBlueLight); // integer & float strings - commentFormat.setForeground(tabGray); // comments - commentFormat.setFontItalic(true); - titleFormat.setForeground(Qt::white); // title + fBlockFormat.setForeground(tabOlive); // BLOCK keywords + fTheoryFormat.setForeground(tabGreen); // THEORY keywords + fFunctionsFormat.setForeground(tabRed); // FUNCTION keywords + fParFormat.setForeground(tabPink); // parX keywords + fMapFormat.setForeground(tabOrange); // mapX keywords + fFunFormat.setForeground(tabPurple); // funX keywords + fRunFormat.setForeground(tabGreen); // RUN/GLOBAL keywords + fCommandsFormat.setForeground(tabGreen); // COMMANDS keywords + fFourierFormat.setForeground(tabGreen); // FOURIER keywords + fPlotFormat.setForeground(tabGreen); // PLOT keywords + fOptionsFormat.setForeground(tabRed); // keywords input options + fInfoFormat.setForeground(tabGray); // auto-printed information + fBoolFormat.setForeground(tabRed); // boolean strings + fNullFormat.setForeground(tabRed); // null strings + fDateFormat.setForeground(tabPink); // date & time strings + fNumberFormat.setForeground(tabBlueLight); // integer & float strings + fCommentFormat.setForeground(tabGray); // comments + fCommentFormat.setFontItalic(true); + fTitleFormat.setForeground(Qt::white); // title } else { // set it to Light for now - blockFormat.setForeground(tabOlive); // BLOCK keywords - theoryFormat.setForeground(tabGreen); // THEORY keywords - functionsFormat.setForeground(tabRed); // FUNCTION keywords - parFormat.setForeground(tabPink); // parX keywords - mapFormat.setForeground(tabOrange); // mapX keywords - funFormat.setForeground(tabPurple); // funX keywords - runFormat.setForeground(tabGreen); // RUN/GLOBAL keywords - commandsFormat.setForeground(tabGreen); // COMMANDS keywords - fourierFormat.setForeground(tabGreen); // FOURIER keywords - plotFormat.setForeground(tabGreen); // PLOT keywords - optionsFormat.setForeground(tabRed); // keywords input options - infoFormat.setForeground(tabGray); // auto-printed information - boolFormat.setForeground(tabRed); // boolean strings - nullFormat.setForeground(tabRed); // null strings - dateFormat.setForeground(tabPink); // date & time strings - numberFormat.setForeground(tabBlue); // integer & float strings - commentFormat.setForeground(tabGray); // comments - commentFormat.setFontItalic(true); - titleFormat.setForeground(Qt::black); // title + fBlockFormat.setForeground(tabOlive); // BLOCK keywords + fTheoryFormat.setForeground(tabGreen); // THEORY keywords + fFunctionsFormat.setForeground(tabRed); // FUNCTION keywords + fParFormat.setForeground(tabPink); // parX keywords + fMapFormat.setForeground(tabOrange); // mapX keywords + fFunFormat.setForeground(tabPurple); // funX keywords + fRunFormat.setForeground(tabGreen); // RUN/GLOBAL keywords + fCommandsFormat.setForeground(tabGreen); // COMMANDS keywords + fFourierFormat.setForeground(tabGreen); // FOURIER keywords + fPlotFormat.setForeground(tabGreen); // PLOT keywords + fOptionsFormat.setForeground(tabRed); // keywords input options + fInfoFormat.setForeground(tabGray); // auto-printed information + fBoolFormat.setForeground(tabRed); // boolean strings + fNullFormat.setForeground(tabRed); // null strings + fDateFormat.setForeground(tabPink); // date & time strings + fNumberFormat.setForeground(tabBlue); // integer & float strings + fCommentFormat.setForeground(tabGray); // comments + fCommentFormat.setFontItalic(true); + fTitleFormat.setForeground(Qt::black); // title } // ========================================================================= @@ -158,7 +158,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) QStringList block_keywords = {"FITPARAMETER", "THEORY", "FUNCTIONS", "GLOBAL", "RUN", "COMMANDS", "FOURIER", "PLOT", "STATISTIC"}; - addRule(block_keywords, blockFormat); + AddRule(block_keywords, fBlockFormat); // ========================================================================= // THEORY KEYWORDS @@ -212,7 +212,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) // combine both theory keyword lists QStringList theory_keywords = theory_keywords_long + theory_keywords_short; - addRule(theory_keywords, theoryFormat); + AddRule(theory_keywords, fTheoryFormat); // ========================================================================= // FUNCTIONS KEYWORDS @@ -221,25 +221,25 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) "gamma_mu", "pi", "B", "b", "En", "en", "T\\d+", /* "+", "-", "*", "/", */ }; - addRule(functions_keywords, functionsFormat); + AddRule(functions_keywords, fFunctionsFormat); // ========================================================================= // funX KEYWORDS // ========================================================================= QStringList fun_keywords = {"fun\\d+"}; - addRule(fun_keywords, funFormat); + AddRule(fun_keywords, fFunFormat); // ========================================================================= // parX KEYWORDS // ========================================================================= QStringList par_keywords = {"par\\d+"}; - addRule(par_keywords, parFormat); + AddRule(par_keywords, fParFormat); // ========================================================================= // mapX KEYWORDS // ========================================================================= QStringList map_keywords = {"map\\d+"}; - addRule(map_keywords, mapFormat); + AddRule(map_keywords, fMapFormat); // ========================================================================= // RUN KEYWORDS @@ -251,7 +251,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) "norm", "backgr.fit", "lifetime", "lifetimecorrection", "map", "forward", "backward", "backgr.fix", "background", "xy-data"}; - addRule(run_keywords, runFormat); + AddRule(run_keywords, fRunFormat); // ========================================================================= // FOURIER KEYWORDS @@ -264,7 +264,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) "phase", "range_for_phase_correction", "range"}; - addRule(fourier_keywords, fourierFormat); + AddRule(fourier_keywords, fFourierFormat); // ========================================================================= // PLOT KEYWORDS @@ -280,7 +280,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) "rrf_packing value", "rrf_freq value unit", "rrf_phase value"}; - addRule(plot_keywords, plotFormat); + AddRule(plot_keywords, fPlotFormat); // ========================================================================= // UNITS OPTIONS @@ -314,7 +314,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) QStringList all_options = units_options + apodization_options + rrf_options + fourier_options + commands_options; - addRule(all_options, optionsFormat); + AddRule(all_options, fOptionsFormat); // ========================================================================= // FIT INFO @@ -388,7 +388,7 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) // ========================================================================= QStringList all_info = fit_info + run_info + plot_info + theory_info; - addRule(all_info, infoFormat); + AddRule(all_info, fInfoFormat); // ========================================================================= // COMMANDS BLOCK KEYWORDS @@ -401,41 +401,41 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) "FIT_RANGE", "SCALE_N0_BKG", "SECTOR", "OpenMP", "CUDA", "OpenCL-CPU", "OpenCL-GPU"}; - addRule(commands_keywords, commandsFormat); + AddRule(commands_keywords, fCommandsFormat); // ========================================================================= // BOOLEANS // ========================================================================= QStringList bool_keywords = {"true", "false"}; - addRule(bool_keywords, boolFormat); + AddRule(bool_keywords, fBoolFormat); // ========================================================================= // NULLS // ========================================================================= QStringList null_keywords = {"none"}; - addRule(null_keywords, nullFormat); + AddRule(null_keywords, fNullFormat); // ========================================================================= // NUMBERS // ========================================================================= // Distinguish integer/decimal numbers from raw text. - HighlightingRule number_rule; + PHighlightingRule number_rule; QRegularExpression number_regex("\\b-?\\d*\\.?\\d+\\b"); - number_rule.pattern = number_regex; - number_rule.format = numberFormat; - highlightingRules.append(number_rule); + number_rule.fPattern = number_regex; + number_rule.fFormat = fNumberFormat; + fHighlightingRules.append(number_rule); // ========================================================================= // DATES // ========================================================================= // Distinguish date/time strings from raw text. - HighlightingRule date_rule; + PHighlightingRule date_rule; // date regex (for dates of the form: YYYY-MM-DD HH:mm:ss) QRegularExpression date_regex("\\b\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[" "01]) (0\\d|1\\d|2[0-3]):[0-5]\\d:[0-5]\\d\\b"); - date_rule.pattern = date_regex; - date_rule.format = dateFormat; - highlightingRules.append(date_rule); + date_rule.fPattern = date_regex; + date_rule.fFormat = fDateFormat; + fHighlightingRules.append(date_rule); // ========================================================================= // INLINE AND LINE COMMENTS @@ -444,11 +444,11 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) // This matches a literal '#' symbol and captures everything remaining on that // line. Styled gray and italicized to quickly indicate non-executable text // annotations. - HighlightingRule comment_rule; + PHighlightingRule comment_rule; QRegularExpression comment_regex("#.*"); - comment_rule.pattern = comment_regex; - comment_rule.format = commentFormat; - highlightingRules.append(comment_rule); + comment_rule.fPattern = comment_regex; + comment_rule.fFormat = fCommentFormat; + fHighlightingRules.append(comment_rule); } /** @@ -459,10 +459,10 @@ PMsrHighlighter::PMsrHighlighter(QTextDocument *parent) * calculates the starting point index and length, passing this information back * to the Qt layout interface engine. */ -void PMsrHighlighter::addRule(const QStringList &keywords, +void PMsrHighlighter::AddRule(const QStringList &keywords, const QTextCharFormat &formatting) { - // Instantiate the HighlighingRule struct. - HighlightingRule rule; + // Instantiate the PHighlightingRule struct. + PHighlightingRule rule; // loop through every keyword for (const QString &keyword : keywords) { @@ -472,11 +472,11 @@ void PMsrHighlighter::addRule(const QStringList &keywords, QRegularExpression regex(QString("\\b%1\\b").arg(keyword)); // apply the formatting to the rule struct - rule.pattern = regex; - rule.format = formatting; + rule.fPattern = regex; + rule.fFormat = formatting; // add the rule to the main list - this->highlightingRules.append(rule); + this->fHighlightingRules.append(rule); } } @@ -491,10 +491,10 @@ 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 : std::as_const(highlightingRules)) { + for (const PHighlightingRule &rule : std::as_const(fHighlightingRules)) { // Execute a global search through the single block string provided. QRegularExpressionMatchIterator matchIterator = - rule.pattern.globalMatch(text); + rule.fPattern.globalMatch(text); // Loop over every match location instance discovered within this single // text string. @@ -507,7 +507,7 @@ void PMsrHighlighter::highlightBlock(const QString &text) { // Core Qt framework utility method which maps styles directly onto // coordinates of the running open source buffer segment. - setFormat(index, length, rule.format); + setFormat(index, length, rule.fFormat); } } @@ -515,6 +515,6 @@ void PMsrHighlighter::highlightBlock(const QString &text) { // over all other rules. if (currentBlock().blockNumber() == 0) { // applies the title formatting for the entirety of the first line - setFormat(0, text.length(), titleFormat); + setFormat(0, text.length(), fTitleFormat); } } diff --git a/src/musredit_qt6/musredit/PMsrHighlighter.h b/src/musredit_qt6/musredit/PMsrHighlighter.h index 1ad25ce6..5604b137 100644 --- a/src/musredit_qt6/musredit/PMsrHighlighter.h +++ b/src/musredit_qt6/musredit/PMsrHighlighter.h @@ -1,6 +1,6 @@ /** * @file PMsrHighlighter.h - * @brief Definition of the MsrHighlighter class for musredit. + * @brief Definition of the PMsrHighlighter class for musredit. * * This file contains the definition of a custom syntax highlighter for * (.msr) files, to be used by musredit. It identifies, for example, blocks, @@ -40,7 +40,7 @@ #include /** - * @class MsrHighlighter + * @class PMsrHighlighter * @brief Custom syntax highlighter for .msr (musrfit configuration) file * syntax. * @@ -70,6 +70,10 @@ protected: * overrides the text layout style wherever a character sequence matches a * rule. * + * @note The lowercase name is mandated by the Qt framework: this method + * overrides QSyntaxHighlighter::highlightBlock and therefore cannot follow + * the CERN/ROOT capitalized member-function convention. + * * @param text A single block (typically a line) of text provided by the * editor. */ @@ -77,49 +81,49 @@ protected: private: /** - * @struct HighlightingRule + * @struct PHighlightingRule * @brief Container grouping a lookup pattern with its visual theme mapping. */ - struct HighlightingRule { + struct PHighlightingRule { QRegularExpression - pattern; ///< The compiled regular expression pattern to search for. + fPattern; ///< The compiled regular expression pattern to search for. QTextCharFormat - format; ///< The text style (color, font, weight) applied upon match. + fFormat; ///< The text style (color, font, weight) applied upon match. }; /** * @brief A dynamic array tracking all active syntax parsing rules. */ - QVector highlightingRules; + QVector fHighlightingRules; /** * @brief Helper function for passing formatting information to the - * highlightingRules dynamic array. + * fHighlightingRules 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. - QTextCharFormat theoryFormat; ///< Formatting profile for THEORY keywords. + QTextCharFormat fBlockFormat; ///< Formatting profile for BLOCK keywords. + QTextCharFormat fTitleFormat; ///< Formatting profile for TITLE line. + QTextCharFormat fTheoryFormat; ///< Formatting profile for THEORY keywords. QTextCharFormat - functionsFormat; ///< Formatting profile for FUNCTION keywords. - QTextCharFormat parFormat; ///< Formatting profile for parX keywords. - QTextCharFormat mapFormat; ///< Formatting profile mapX keywords. - QTextCharFormat funFormat; ///< Formatting profile funX keywords. - QTextCharFormat runFormat; ///< Formatting profile RUN/GLOBAL keywords. - QTextCharFormat commandsFormat; ///< Formatting profile COMMANDS keywords. - QTextCharFormat fourierFormat; ///< Formatting profile FOURIER keywords. - QTextCharFormat plotFormat; ///< Formatting profile PLOT keywords. + fFunctionsFormat; ///< Formatting profile for FUNCTION keywords. + QTextCharFormat fParFormat; ///< Formatting profile for parX keywords. + QTextCharFormat fMapFormat; ///< Formatting profile mapX keywords. + QTextCharFormat fFunFormat; ///< Formatting profile funX keywords. + QTextCharFormat fRunFormat; ///< Formatting profile RUN/GLOBAL keywords. + QTextCharFormat fCommandsFormat; ///< Formatting profile COMMANDS keywords. + QTextCharFormat fFourierFormat; ///< Formatting profile FOURIER keywords. + QTextCharFormat fPlotFormat; ///< Formatting profile PLOT keywords. QTextCharFormat - optionsFormat; ///< Formatting profile for keyword input options. + fOptionsFormat; ///< Formatting profile for keyword input options. QTextCharFormat - infoFormat; ///< Formatting profile for auto-printed information. - QTextCharFormat boolFormat; ///< Formatting profile for boolean strings. - QTextCharFormat nullFormat; ///< Formatting profile for null strings. - QTextCharFormat dateFormat; ///< Formatting profile for date & time strings + fInfoFormat; ///< Formatting profile for auto-printed information. + QTextCharFormat fBoolFormat; ///< Formatting profile for boolean strings. + QTextCharFormat fNullFormat; ///< Formatting profile for null strings. + QTextCharFormat fDateFormat; ///< Formatting profile for date & time strings QTextCharFormat - numberFormat; ///< Formatting profile for integer & float strings. - QTextCharFormat commentFormat; ///< Formatting profile for comments. + fNumberFormat; ///< Formatting profile for integer & float strings. + QTextCharFormat fCommentFormat; ///< Formatting profile for comments. }; #endif // _PMSRHIGHLIGHTER_H_