source: s10k/CommonLibs/BasicXMLSyntaxHighlighter/BasicXMLSyntaxHighlighter.h@ 1171

Last change on this file since 1171 was 1110, checked in by s10k, 6 years ago

slightly modifications to allow subclassing, added Q_OBJECT macro, since usually all classes derived from QObject should use it

File size: 2.4 KB
RevLine 
[1110]1/*
2 *
3The MIT License (MIT)
4
5Copyright (c) 2015 Dmitry Ivanov
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in
15all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23THE SOFTWARE.
24*
25*/
26
27// This XML highligter is the same from Dmitry Ivanov available here:
28// https://github.com/d1vanov/basic-xml-syntax-highlighter
29// with some slightly modifications by fabiobento512 (https://github.com/fabiobento512)
30// (like different colors, and remove of unneeded constructors)
31
32#ifndef BASIC_XML_SYNTAX_HIGHLIGHTER_H
33#define BASIC_XML_SYNTAX_HIGHLIGHTER_H
34
35#include <QSyntaxHighlighter>
36#include <QTextEdit>
37
38class BasicXMLSyntaxHighlighter : public QSyntaxHighlighter
39{
40 Q_OBJECT
41public:
42 BasicXMLSyntaxHighlighter(QTextDocument * parent = nullptr);
43
44protected:
45 virtual void highlightBlock(const QString & text);
46
47private:
48 void highlightByRegex(const QTextCharFormat & format,
49 const QRegExp & regex, const QString & text);
50
51 void setRegexes();
52 void setFormats();
53
54protected:
55 QTextCharFormat m_xmlKeywordFormat;
56 QTextCharFormat m_xmlElementFormat;
57 QTextCharFormat m_xmlAttributeFormat;
58 QTextCharFormat m_xmlValueFormat;
59 QTextCharFormat m_xmlCommentFormat;
60
61 QList<QRegExp> m_xmlKeywordRegexes;
62 QRegExp m_xmlElementRegex;
63 QRegExp m_xmlAttributeRegex;
64 QRegExp m_xmlValueRegex;
65 QRegExp m_xmlCommentRegex;
66};
67
68#endif // BASIC_XML_SYNTAX_HIGHLIGHTER_H
Note: See TracBrowser for help on using the repository browser.