| 1 | #pragma once |
| 2 | |
| 3 | // QCodeEditor |
| 4 | #include <QStyleSyntaxHighlighter> // Required for inheritance |
| 5 | |
| 6 | // Qt |
| 7 | #include <QVector> |
| 8 | #include <QRegularExpression> |
| 9 | |
| 10 | /** |
| 11 | * @brief Class, that describes XML code |
| 12 | * highlighter. |
| 13 | */ |
| 14 | class QXMLHighlighter : public QStyleSyntaxHighlighter |
| 15 | { |
| 16 | Q_OBJECT |
| 17 | public: |
| 18 | |
| 19 | /** |
| 20 | * @brief Constructor. |
| 21 | * @param document Pointer to document. |
| 22 | */ |
| 23 | explicit QXMLHighlighter(QTextDocument* document=nullptr); |
| 24 | |
| 25 | protected: |
| 26 | |
| 27 | void highlightBlock(const QString& text) override; |
| 28 | |
| 29 | private: |
| 30 | |
| 31 | void highlightByRegex(const QTextCharFormat& format, |
| 32 | const QRegularExpression& regex, |
| 33 | const QString& text); |
| 34 | |
| 35 | QVector<QRegularExpression> m_xmlKeywordRegexes; |
| 36 | QRegularExpression m_xmlElementRegex; |
| 37 | QRegularExpression m_xmlAttributeRegex; |
| 38 | QRegularExpression m_xmlValueRegex; |
| 39 | QRegularExpression m_xmlCommentBeginRegex; |
| 40 | QRegularExpression m_xmlCommentEndRegex; |
| 41 | |
| 42 | }; |
| 43 |