mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
SyntaxHighlighter: Add SQLite functions
Also highlight the names of functions supported by SQLite such as COUNT.
This commit is contained in:
@@ -152,9 +152,9 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
|
||||
// syntaxhighlighter?
|
||||
if(group == "syntaxhighlighter")
|
||||
{
|
||||
// Bold? Only tables and keywords are bold by default
|
||||
// Bold? Only tables, functions and keywords are bold by default
|
||||
if(name.right(4) == "bold")
|
||||
return name == "keyword_bold" || name == "table_bold";
|
||||
return name == "keyword_bold" || name == "table_bold" || name == "function_bold";
|
||||
|
||||
// Italic? Nothing by default
|
||||
if(name.right(6) == "italic")
|
||||
@@ -169,6 +169,8 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
|
||||
{
|
||||
if(name == "keyword_colour")
|
||||
return QColor(Qt::darkBlue).name();
|
||||
else if(name == "function_colour")
|
||||
return QColor(Qt::blue).name();
|
||||
else if(name == "table_colour")
|
||||
return QColor(Qt::darkCyan).name();
|
||||
else if(name == "comment_colour")
|
||||
|
||||
@@ -187,6 +187,14 @@
|
||||
<string/>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>function</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Function</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">table</string>
|
||||
|
||||
@@ -11,7 +11,9 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) :
|
||||
singleLineCommentFormat = createFormat("comment");
|
||||
identifierFormat = createFormat("identifier");
|
||||
stringFormat = createFormat("string");
|
||||
functionFormat = createFormat("function");
|
||||
|
||||
// Keywords
|
||||
QStringList keywordPatterns;
|
||||
keywordPatterns
|
||||
<< "ABORT" << "ACTION" << "ADD" << "AFTER" << "ALL"
|
||||
@@ -40,10 +42,35 @@ SQLiteSyntaxHighlighter::SQLiteSyntaxHighlighter(QTextDocument *parent) :
|
||||
<< "VACUUM" << "VALUES" << "VIEW" << "VIRTUAL" << "WHEN"
|
||||
<< "WHERE";
|
||||
|
||||
rule.format = keywordFormat;
|
||||
foreach (const QString &pattern, keywordPatterns) {
|
||||
rule.pattern = QRegExp(QString("\\b%1\\b").arg(pattern));
|
||||
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
rule.format = keywordFormat;
|
||||
highlightingRules.append(rule);
|
||||
}
|
||||
|
||||
// Functions
|
||||
QStringList functionPatterns;
|
||||
functionPatterns
|
||||
// Core functions
|
||||
<< "ABS" << "CHANGES" << "CHAR" << "COALESCE" << "GLOB"
|
||||
<< "IFNULL" << "INSTR" << "HEX" << "LAST_INSERT_ROW" << "LENGTH"
|
||||
<< "LIKE" << "LOAD_EXTENSION" << "LOWER" << "LTRIM" << "MAX"
|
||||
<< "MIN" << "NULLIF" << "QUOTE" << "RANDOM" << "RANDOMBLOB"
|
||||
<< "REPLACE" << "ROUND" << "RTRIM" << "SOUNDEX" << "SQLITE_COMPILEOPTION_GET"
|
||||
<< "SQLITE_COMPILEOPTION_USED" << "SQLITE_SOURCE_ID" << "SQLITE_VERSION" << "SUBSTR" << "TOTAL_CHANGES"
|
||||
<< "TRIM" << "TYPEOF" << "UNICODE" << "UPPER" << "ZEROBLOB"
|
||||
// Date and time functions
|
||||
<< "DATE" << "TIME" << "DATETIME" << "JULIANDAY" << "STRFTIME"
|
||||
// Aggregate functions
|
||||
<< "AVG" << "COUNT" << "GROUP_CONCAT" << "MAX" << "MIN"
|
||||
<< "SUM" << "TOTAL";
|
||||
|
||||
rule.format = functionFormat;
|
||||
foreach(const QString& pattern, functionPatterns)
|
||||
{
|
||||
rule.pattern = QRegExp(QString("\\b%1\\b").arg(pattern));
|
||||
rule.pattern.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
highlightingRules.append(rule);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ private:
|
||||
QTextCharFormat stringFormat;
|
||||
QTextCharFormat identifierFormat;
|
||||
QTextCharFormat tableFormat;
|
||||
QTextCharFormat functionFormat;
|
||||
|
||||
QTextCharFormat createFormat(const QString& settings_name);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user