Commit 0b92043c authored by Laurent Montel's avatar Laurent Montel 😁

Use QVector

parent cae4affe
......@@ -38,7 +38,7 @@ void XMLPrintingSyntaxHighLighter::init()
Q_FOREACH ( const QString &s, testType ) {
const QRegExp regex( s, Qt::CaseInsensitive );
m_rules.append( Rule( regex, testFormat ) );
m_rules.append( PimCommon::Rule( regex, testFormat ) );
}
QTextCharFormat quoteFormat;
......@@ -48,7 +48,7 @@ void XMLPrintingSyntaxHighLighter::init()
quoteType << QLatin1String("quoted") << QLatin1String("hash") << QLatin1String("bracket") << QLatin1String("multiline");
Q_FOREACH ( const QString &s, quoteType ) {
const QRegExp regex( s, Qt::CaseInsensitive );
m_rules.append( Rule( regex, quoteFormat ) );
m_rules.append( PimCommon::Rule( regex, quoteFormat ) );
}
......@@ -60,13 +60,13 @@ void XMLPrintingSyntaxHighLighter::init()
miscType << QLatin1String("num") << QLatin1String("tag")<< QLatin1String("list")<< QLatin1String("str")<< QLatin1String("test") <<QLatin1String("crlf/");
Q_FOREACH ( const QString &s, miscType ) {
const QRegExp regex( s, Qt::CaseInsensitive );
m_rules.append( Rule( regex, misc ) );
m_rules.append( PimCommon::Rule( regex, misc ) );
}
QTextCharFormat header;
header.setForeground( Qt::black );
header.setFontWeight( QFont::Bold );
m_rules.append( Rule( QRegExp(QLatin1String("<\\?xml.*"), Qt::CaseInsensitive), header ) );
m_rules.append( PimCommon::Rule( QRegExp(QLatin1String("<\\?xml.*"), Qt::CaseInsensitive), header ) );
}
......@@ -34,21 +34,21 @@ void AdBlockSyntaxHighlighter::init()
QTextCharFormat commentFormat;
commentFormat.setForeground( Qt::darkYellow );
QRegExp commentRegex( QLatin1String( "^!.*" ) );
m_rules.append( Rule( commentRegex, commentFormat ) );
m_rules.append( PimCommon::Rule( commentRegex, commentFormat ) );
QTextCharFormat exceptionFormat;
exceptionFormat.setForeground( Qt::magenta );
QRegExp exceptionRegex( QLatin1String( "^@@.*" ) );
m_rules.append( Rule( exceptionRegex, exceptionFormat ) );
m_rules.append( PimCommon::Rule( exceptionRegex, exceptionFormat ) );
QTextCharFormat headerFormat;
headerFormat.setForeground( Qt::red );
QRegExp headerRegex( QLatin1String( "^\\[.*" ) );
m_rules.append( Rule( headerRegex, headerFormat ) );
m_rules.append( PimCommon::Rule( headerRegex, headerFormat ) );
QTextCharFormat elementFormat;
elementFormat.setForeground( Qt::blue );
QRegExp elementRegex( QLatin1String( ".*##.*" ) );
m_rules.append( Rule( elementRegex, elementFormat ) );
m_rules.append( PimCommon::Rule( elementRegex, elementFormat ) );
}
......@@ -21,6 +21,16 @@
#include <QSyntaxHighlighter>
#include "pimcommon_export.h"
namespace PimCommon {
class PIMCOMMON_EXPORT Rule {
public:
Rule() {}
Rule( const QRegExp &r, const QTextCharFormat &f )
: pattern( r ), format( f ) {}
QRegExp pattern;
QTextCharFormat format;
};
class PIMCOMMON_EXPORT SyntaxHighlighterBase : public QSyntaxHighlighter
{
Q_OBJECT
......@@ -32,15 +42,9 @@ public:
protected:
virtual void init() = 0;
struct Rule {
QRegExp pattern;
QTextCharFormat format;
Rule( const QRegExp &r, const QTextCharFormat &f )
: pattern( r ), format( f ) {}
};
QList<Rule> m_rules;
QVector<Rule> m_rules;
};
}
Q_DECLARE_TYPEINFO( PimCommon::Rule, Q_MOVABLE_TYPE );
#endif // SYNTAXHIGHLIGHTERBASE_H
......@@ -43,7 +43,7 @@ void TemplatesSyntaxHighlighter::init()
Q_FOREACH ( const QString & s, keywords ) {
const QRegExp regex( s, Qt::CaseInsensitive );
m_rules.append( Rule( regex, keywordFormat ) );
m_rules.append( PimCommon::Rule( regex, keywordFormat ) );
}
QTextCharFormat keywordWithArgsFormat;
......@@ -53,7 +53,7 @@ void TemplatesSyntaxHighlighter::init()
Q_FOREACH ( const QString & s, keywordsWithArgs ) {
const QRegExp regex( s, Qt::CaseInsensitive );
m_rules.append( Rule( regex, keywordWithArgsFormat ) );
m_rules.append( PimCommon::Rule( regex, keywordWithArgsFormat ) );
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment