mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
add support for table names highlighting
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user