QSS Solver GUI  4.5.3
mmohighlight.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #pragma once
21 
22 #include <QHash>
23 #include <QRegularExpression>
24 #include <QSyntaxHighlighter>
25 #include <QTextCharFormat>
26 
27 class MmoHighlighter : public QSyntaxHighlighter {
28  Q_OBJECT
29  public:
30  using h_type = enum { MMO_MODEL, MMO_LOG };
31  MmoHighlighter(QTextDocument *parent = nullptr, h_type file = MMO_MODEL);
32 
33  protected:
34  void initialize(h_type file);
35  void addHighlightingRule(const QString &pattern, const QTextCharFormat &format, bool bold = true);
37  void setupLogHighlighting();
38  void highlightBlock(const QString &text) override;
39  void highlightSyntax(const QString &text);
40  void highlightComments(const QString &text);
41 
42  private:
43  struct MmoHighlightingRule {
44  QRegularExpression pattern;
45  QTextCharFormat format;
46  };
47 
48  // Keywords
49  static const QStringList _model_keywords;
50  static const QStringList _model_functions;
51  static const QStringList _model_annotations;
52  static const QStringList _model_qss_tags;
53  static const QStringList _log_keywords;
54 
55  // Member variables
56  QVector<MmoHighlightingRule> _highlighting_rules;
57  QRegularExpression _comment_start_expression;
58  QRegularExpression _comment_end_expression;
59  QTextCharFormat _single_line_comment_format;
60 };
MmoHighlighter::setupLogHighlighting
void setupLogHighlighting()
Definition: mmohighlight.cpp:210
MmoHighlighter::_highlighting_rules
QVector< MmoHighlightingRule > _highlighting_rules
Definition: mmohighlight.hpp:73
MmoHighlighter::h_type
enum { MMO_MODEL, MMO_LOG } h_type
Definition: mmohighlight.hpp:47
MmoHighlighter::addHighlightingRule
void addHighlightingRule(const QString &pattern, const QTextCharFormat &format, bool bold=true)
Definition: mmohighlight.cpp:160
MmoHighlighter::MmoHighlightingRule::pattern
QRegularExpression pattern
Definition: mmohighlight.hpp:61
MmoHighlighter
Definition: mmohighlight.hpp:27
MmoHighlighter::_comment_start_expression
QRegularExpression _comment_start_expression
Definition: mmohighlight.hpp:74
MmoHighlighter::_single_line_comment_format
QTextCharFormat _single_line_comment_format
Definition: mmohighlight.hpp:76
MmoHighlighter::setupModelHighlighting
void setupModelHighlighting()
Definition: mmohighlight.cpp:169
MmoHighlighter::initialize
void initialize(h_type file)
Definition: mmohighlight.cpp:146
MmoHighlighter::MmoHighlightingRule
Definition: mmohighlight.hpp:60
MmoHighlighter::highlightBlock
void highlightBlock(const QString &text) override
Definition: mmohighlight.cpp:221
MmoHighlighter::_model_qss_tags
static const QStringList _model_qss_tags
Definition: mmohighlight.hpp:69
MmoHighlighter::_log_keywords
static const QStringList _log_keywords
Definition: mmohighlight.hpp:70
MmoHighlighter::MmoHighlighter
MmoHighlighter(QTextDocument *parent=nullptr, h_type file=MMO_MODEL)
Definition: mmohighlight.cpp:144
MmoHighlighter::_comment_end_expression
QRegularExpression _comment_end_expression
Definition: mmohighlight.hpp:75
MmoHighlighter::highlightComments
void highlightComments(const QString &text)
Definition: mmohighlight.cpp:242
MmoHighlighter::_model_annotations
static const QStringList _model_annotations
Definition: mmohighlight.hpp:68
MmoHighlighter::highlightSyntax
void highlightSyntax(const QString &text)
Definition: mmohighlight.cpp:227
MmoHighlighter::_model_functions
static const QStringList _model_functions
Definition: mmohighlight.hpp:67
MmoHighlighter::_model_keywords
static const QStringList _model_keywords
Definition: mmohighlight.hpp:66
MmoHighlighter::MmoHighlightingRule::format
QTextCharFormat format
Definition: mmohighlight.hpp:62