If there is a selection in the query then only that part is Executed or explained.

Replaced QTextEdit with QPLainTextEdit as it is more efficient and CAN do syntax highlighting.
This commit is contained in:
Eelke Klein 2017-01-16 17:31:46 +01:00
parent c555182ddd
commit 5831f18008
5 changed files with 44 additions and 39 deletions

View file

@ -22,7 +22,7 @@ SqlHighlighter::SqlHighlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent)
{
// {
// static auto keywords = R"-(as|alter|all|and|any|by|column|create|database|from|group|having|in|not|or|order|select|table|where|(?:(?:inner|(?:left|right|full)(\s+outer)?)\s+)?join)-";
static auto keywords = R"-(as|alter|all|and|any|by|column|create|database|from|group|having|in|not|or|order|select|table|where|(?:(?:inner|(?:left|right|full)(\s+outer)?)\s+)?join)-";
// static auto types = R"-(bigint|boolean|char|character varying|date|int[248]|integer|numeric|smallint|time|timestamp(?:tz)?|timestamp(?:\s+with\s+timezone)?|varchar)-";
// static auto err = R"-(left|right|inner|outer)-";
@ -31,10 +31,10 @@ SqlHighlighter::SqlHighlighter(QTextDocument *parent)
// errFormat.setFontWeight(QFont::Bold);
// highlightingRules.emplace_back(QRegExp(err, Qt::CaseInsensitive), errFormat);
// QTextCharFormat keywordFormat;
// keywordFormat.setForeground(QColor(128, 128, 255));
// keywordFormat.setFontWeight(QFont::Bold);
// highlightingRules.emplace_back(QRegExp(keywords, Qt::CaseInsensitive), keywordFormat);
QTextCharFormat keywordFormat;
keywordFormat.setForeground(QColor(128, 128, 255));
keywordFormat.setFontWeight(QFont::Bold);
highlightingRules.emplace_back(QRegExp(keywords, Qt::CaseInsensitive), keywordFormat);
// QTextCharFormat typesFormat;
// typesFormat.setForeground(QColor(128, 255, 128));
@ -104,15 +104,15 @@ namespace {
void SqlHighlighter::highlightBlock(const QString &text)
{
// foreach (const HighlightingRule &rule, highlightingRules) {
// QRegExp expression(rule.pattern);
// int index = expression.indexIn(text);
// while (index >= 0) {
// int length = expression.matchedLength();
// setFormat(index, length, rule.format);
// index = expression.indexIn(text, index + length);
// }
// }
foreach (const HighlightingRule &rule, highlightingRules) {
QRegExp expression(rule.pattern);
int index = expression.indexIn(text);
while (index >= 0) {
int length = expression.matchedLength();
setFormat(index, length, rule.format);
index = expression.indexIn(text, index + length);
}
}
setCurrentBlockState(0);
}