add support for table names highlighting

This commit is contained in:
Peinthor Rene
2012-03-07 18:20:45 +01:00
parent 474cbf04eb
commit cc82b47a77
2 changed files with 28 additions and 3 deletions

View File

@@ -5,6 +5,9 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) :
{
HighlightingRule rule;
tableFormat.setForeground(Qt::darkCyan);
tableFormat.setFontWeight(QFont::Bold);
keywordFormat.setForeground(Qt::darkBlue);
keywordFormat.setFontWeight(QFont::Bold);
QStringList keywordPatterns;
@@ -68,9 +71,20 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) :
highlightingRules.append(rule);
}
void SQLiteSyntaxHighlighter::highlightBlock(const QString &text)
void SQLiteSyntaxHighlighter::setTableNames(const QStringList &tablenames)
{
foreach (const HighlightingRule &rule, highlightingRules) {
tableNameRules.clear();
foreach(const QString& tblname, tablenames) {
HighlightingRule rule;
rule.pattern = QRegExp(tblname);
rule.format = tableFormat;
tableNameRules.append(rule);
}
}
void SQLiteSyntaxHighlighter::highlightBlockVector(const QString& text, const QVector<HighlightingRule>& vec)
{
foreach (const HighlightingRule &rule, vec) {
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
@@ -80,3 +94,9 @@ void SQLiteSyntaxHighlighter::highlightBlock(const QString &text)
}
}
}
void SQLiteSyntaxHighlighter::highlightBlock(const QString &text)
{
highlightBlockVector(text, tableNameRules);
highlightBlockVector(text, highlightingRules);
}

View File

@@ -9,6 +9,8 @@ class SQLiteSyntaxHighlighter : public QSyntaxHighlighter
public:
explicit SQLiteSyntaxHighlighter(QTextDocument *parent = 0);
void setTableNames(const QStringList& tablenames);
protected:
void highlightBlock(const QString &text);
@@ -18,7 +20,10 @@ private:
QRegExp pattern;
QTextCharFormat format;
};
void highlightBlockVector(const QString& text, const QVector<HighlightingRule>& vec);
QVector<HighlightingRule> highlightingRules;
QVector<HighlightingRule> tableNameRules;
QRegExp commentStartExpression;
QRegExp commentEndExpression;
@@ -27,7 +32,7 @@ private:
QTextCharFormat singleLineCommentFormat;
QTextCharFormat multiLineCommentFormat;
QTextCharFormat quotationFormat;
QTextCharFormat tableFormat;
};
#endif // SQLITESYNTAXHIGHLIGHTER_H