Computer Assisted Medical Intervention Tool Kit version 6.0
 
Loading...
Searching...
No Matches
Xmlhighlighter.h
Go to the documentation of this file.
1/*
2** Copyright 2009-10 Martin Holmes, Meagan Timney and the
3** University of Victoria Humanities Computing and Media
4** Centre.
5
6** This file is part of the projXMLEditor project which in
7** turn belongs to the Image Markup Tool version 2.0
8** project. The purpose of svgIconsTest is to provide a
9** platform to test and learn various features of Qt, and
10** to provide a semi-useful tool to aid in the rapid
11** creation and editing of resource files containing SVG
12** icons for Qt application development.
13
14** GNU Lesser General Public License Usage
15** This file may be used under the terms of the GNU Lesser
16** General Public License version 2.1 as published by the Free Software
17** Foundation and appearing in the file LICENSE.LGPL included in the
18** packaging of this file. Please review the following information to
19** ensure the GNU Lesser General Public License version 2.1 requirements
20** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
21
22** You may also use this code under the Mozilla Public Licence
23** version 1.1. MPL 1.1 can be found at http://www.mozilla.org/MPL/MPL-1.1.html.
24
25** "svgIconsTest" is distributed in the hope that it will be useful,
26** but WITHOUT ANY WARRANTY; without even the implied warranty of
27** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28** GNU Lesser General Public License for more details.
29*/
30
31#ifndef XMLHIGHLIGHTER_H
32#define XMLHIGHLIGHTER_H
33
34#include <QSyntaxHighlighter>
35
36#include <QHash>
37#include <QTextCharFormat>
38#include <QRegularExpression>
39
40QT_BEGIN_NAMESPACE
41class QTextDocument;
42QT_END_NAMESPACE
43
44
52class XmlHighlighter : public QSyntaxHighlighter {
53 Q_OBJECT
54
55public:
56 XmlHighlighter(QTextDocument* parent = nullptr);
57
58protected:
59 void highlightBlock(const QString& text) override;
60 void highlightSubBlock(const QString& text, const int startIndex, const int currState);
61
62private:
63 struct HighlightingRule {
64 QRegularExpression pattern;
65 QTextCharFormat format;
66 };
67 QVector<HighlightingRule> hlRules;
68
69 QRegularExpression xmlProcInstStartExpression;
70 QRegularExpression xmlProcInstEndExpression;
71 QRegularExpression xmlCommentStartExpression;
72 QRegularExpression xmlCommentEndExpression;
73 QRegularExpression xmlDoctypeStartExpression;
74 QRegularExpression xmlDoctypeEndExpression;
75
76 QRegularExpression xmlOpenTagStartExpression;
77 QRegularExpression xmlOpenTagEndExpression;
78 QRegularExpression xmlCloseTagStartExpression;
79 QRegularExpression xmlCloseTagEndExpression;
80 QRegularExpression xmlAttributeStartExpression;
81 QRegularExpression xmlAttributeEndExpression;
82 QRegularExpression xmlAttValStartExpression;
83 QRegularExpression xmlAttValEndExpression;
84
85 QRegularExpression xmlAttValExpression;
86
87
88 QTextCharFormat xmlProcInstFormat;
89 QTextCharFormat xmlDoctypeFormat;
90 QTextCharFormat xmlCommentFormat;
91 QTextCharFormat xmlTagFormat;
92 QTextCharFormat xmlEntityFormat;
93 QTextCharFormat xmlAttributeFormat;
94 QTextCharFormat xmlAttValFormat;
95
96//Enumeration for types of element, used for tracking what
97//we're inside while highlighting over multiline blocks.
98 enum xmlState {
99 inNothing, //Don't know if we'll need this or not.
100 inProcInst, //starting with <? and ending with ?>
101 inDoctypeDecl, //starting with <!DOCTYPE and ending with >
102 inOpenTag, //starting with < + xmlName and ending with /?>
103 inOpenTagName, //after < and before whitespace. Implies inOpenTag.
104 inAttribute, //if inOpenTag, starting with /s*xmlName/s*=/s*" and ending with ".
105 inAttName, //after < + xmlName + whitespace, and before =". Implies inOpenTag.
106 inAttVal, //after =" and before ". May also use single quotes. Implies inOpenTag.
107 inCloseTag, //starting with </ and ending with >.
108 inCloseTagName,//after </ and before >. Implies inCloseTag.
109 inComment //starting with <!-- and ending with -->. Overrides all others.
110 };
111};
112
113
114#endif
TODO Comment class here.
Definition Xmlhighlighter.h:52
void highlightSubBlock(const QString &text, const int startIndex, const int currState)
Definition Xmlhighlighter.cpp:123
void highlightBlock(const QString &text) override
Definition Xmlhighlighter.cpp:356