Computer Assited Medical Intervention Tool Kit  version 5.0
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 
39 QT_BEGIN_NAMESPACE
40 class QTextDocument;
41 QT_END_NAMESPACE
42 
43 
51 class XmlHighlighter : public QSyntaxHighlighter {
52  Q_OBJECT
53 
54 public:
55  XmlHighlighter(QTextDocument* parent = nullptr);
56 
57 protected:
58  void highlightBlock(const QString& text) override;
59  void highlightSubBlock(const QString& text, const int startIndex, const int currState);
60 
61 private:
63  QRegExp pattern;
64  QTextCharFormat format;
65  };
66  QVector<HighlightingRule> hlRules;
67 
74 
83 
85 
86 
87  QTextCharFormat xmlProcInstFormat;
88  QTextCharFormat xmlDoctypeFormat;
89  QTextCharFormat xmlCommentFormat;
90  QTextCharFormat xmlTagFormat;
91  QTextCharFormat xmlEntityFormat;
92  QTextCharFormat xmlAttributeFormat;
93  QTextCharFormat xmlAttValFormat;
94 
95 //Enumeration for types of element, used for tracking what
96 //we're inside while highlighting over multiline blocks.
97  enum xmlState {
98  inNothing, //Don't know if we'll need this or not.
99  inProcInst, //starting with <? and ending with ?>
100  inDoctypeDecl, //starting with <!DOCTYPE and ending with >
101  inOpenTag, //starting with < + xmlName and ending with /?>
102  inOpenTagName, //after < and before whitespace. Implies inOpenTag.
103  inAttribute, //if inOpenTag, starting with /s*xmlName/s*=/s*" and ending with ".
104  inAttName, //after < + xmlName + whitespace, and before =". Implies inOpenTag.
105  inAttVal, //after =" and before ". May also use single quotes. Implies inOpenTag.
106  inCloseTag, //starting with </ and ending with >.
107  inCloseTagName,//after </ and before >. Implies inCloseTag.
108  inComment //starting with <!-- and ending with -->. Overrides all others.
109  };
110 };
111 
112 
113 #endif
XmlHighlighter::xmlAttributeEndExpression
QRegExp xmlAttributeEndExpression
Definition: Xmlhighlighter.h:80
XmlHighlighter::xmlOpenTagEndExpression
QRegExp xmlOpenTagEndExpression
Definition: Xmlhighlighter.h:76
XmlHighlighter::xmlCommentFormat
QTextCharFormat xmlCommentFormat
Definition: Xmlhighlighter.h:89
XmlHighlighter::xmlAttributeFormat
QTextCharFormat xmlAttributeFormat
Definition: Xmlhighlighter.h:92
XmlHighlighter::inAttName
@ inAttName
Definition: Xmlhighlighter.h:104
XmlHighlighter::xmlTagFormat
QTextCharFormat xmlTagFormat
Definition: Xmlhighlighter.h:90
XmlHighlighter::inProcInst
@ inProcInst
Definition: Xmlhighlighter.h:99
XmlHighlighter::XmlHighlighter
XmlHighlighter(QTextDocument *parent=nullptr)
[0]
Definition: Xmlhighlighter.cpp:39
XmlHighlighter::xmlAttValExpression
QRegExp xmlAttValExpression
Definition: Xmlhighlighter.h:84
XmlHighlighter::inCloseTagName
@ inCloseTagName
Definition: Xmlhighlighter.h:107
XmlHighlighter::xmlCommentStartExpression
QRegExp xmlCommentStartExpression
Definition: Xmlhighlighter.h:70
XmlHighlighter::xmlAttributeStartExpression
QRegExp xmlAttributeStartExpression
Definition: Xmlhighlighter.h:79
XmlHighlighter::xmlAttValStartExpression
QRegExp xmlAttValStartExpression
Definition: Xmlhighlighter.h:81
XmlHighlighter::xmlProcInstFormat
QTextCharFormat xmlProcInstFormat
Definition: Xmlhighlighter.h:87
XmlHighlighter::inComment
@ inComment
Definition: Xmlhighlighter.h:108
Xmlhighlighter.h
XmlHighlighter::xmlEntityFormat
QTextCharFormat xmlEntityFormat
Definition: Xmlhighlighter.h:91
XmlHighlighter::highlightSubBlock
void highlightSubBlock(const QString &text, const int startIndex, const int currState)
Definition: Xmlhighlighter.cpp:131
XmlHighlighter::xmlDoctypeFormat
QTextCharFormat xmlDoctypeFormat
Definition: Xmlhighlighter.h:88
XmlHighlighter::xmlProcInstEndExpression
QRegExp xmlProcInstEndExpression
Definition: Xmlhighlighter.h:69
XmlHighlighter::xmlDoctypeEndExpression
QRegExp xmlDoctypeEndExpression
Definition: Xmlhighlighter.h:73
XmlHighlighter::inCloseTag
@ inCloseTag
Definition: Xmlhighlighter.h:106
XmlHighlighter::hlRules
QVector< HighlightingRule > hlRules
Definition: Xmlhighlighter.h:66
XmlHighlighter::inDoctypeDecl
@ inDoctypeDecl
Definition: Xmlhighlighter.h:100
XmlHighlighter::inAttribute
@ inAttribute
Definition: Xmlhighlighter.h:103
XmlHighlighter::xmlCloseTagStartExpression
QRegExp xmlCloseTagStartExpression
Definition: Xmlhighlighter.h:77
XmlHighlighter::xmlAttValFormat
QTextCharFormat xmlAttValFormat
Definition: Xmlhighlighter.h:93
XmlHighlighter
TODO Comment class here.
Definition: Xmlhighlighter.h:51
XmlHighlighter::inAttVal
@ inAttVal
Definition: Xmlhighlighter.h:105
XmlHighlighter::inOpenTag
@ inOpenTag
Definition: Xmlhighlighter.h:101
XmlHighlighter::inNothing
@ inNothing
Definition: Xmlhighlighter.h:98
XmlHighlighter::HighlightingRule::pattern
QRegExp pattern
Definition: Xmlhighlighter.h:63
XmlHighlighter::highlightBlock
void highlightBlock(const QString &text) override
Definition: Xmlhighlighter.cpp:363
XmlHighlighter::HighlightingRule
Definition: Xmlhighlighter.h:62
XmlHighlighter::xmlCloseTagEndExpression
QRegExp xmlCloseTagEndExpression
Definition: Xmlhighlighter.h:78
XmlHighlighter::xmlDoctypeStartExpression
QRegExp xmlDoctypeStartExpression
Definition: Xmlhighlighter.h:72
XmlHighlighter::xmlProcInstStartExpression
QRegExp xmlProcInstStartExpression
Definition: Xmlhighlighter.h:68
XmlHighlighter::inOpenTagName
@ inOpenTagName
Definition: Xmlhighlighter.h:102
XmlHighlighter::xmlState
xmlState
Definition: Xmlhighlighter.h:97
XmlHighlighter::xmlOpenTagStartExpression
QRegExp xmlOpenTagStartExpression
Definition: Xmlhighlighter.h:75
XmlHighlighter::xmlAttValEndExpression
QRegExp xmlAttValEndExpression
Definition: Xmlhighlighter.h:82
XmlHighlighter::HighlightingRule::format
QTextCharFormat format
Definition: Xmlhighlighter.h:64
XmlHighlighter::xmlCommentEndExpression
QRegExp xmlCommentEndExpression
Definition: Xmlhighlighter.h:71