28 setTitle( tr(
"Expression Editor" ) );
32 setAutoCompletionCaseSensitivity(
false );
41 for (
const QString &var : variableNames )
43 mVariables <<
'@' + var;
51 for (
int i = 0; i < count; i++ )
63 QString signature = func->
name();
64 if ( !signature.startsWith(
'$' ) )
68 QStringList paramNames;
72 paramNames << param.name();
76 if ( parameters.isEmpty() && func->
params() )
77 signature += QChar( 0x2026 );
79 signature += paramNames.join(
", " );
83 mFunctions << signature;
93 for (
const QgsField &field : fields )
95 mFieldNames << field.name();
102 void QgsCodeEditorExpression::initializeLexer()
104 QHash< QString, QColor > colors;
108 for (
const auto &key : ini.allKeys() )
115 QColor defaultColor = colors.value( QStringLiteral(
"sql/defaultFontColor" ), Qt::black );
117 mSqlLexer =
new QgsLexerExpression(
this );
118 mSqlLexer->setDefaultFont( font );
119 mSqlLexer->setDefaultColor( defaultColor );
120 mSqlLexer->setDefaultPaper( colors.value( QStringLiteral(
"sql/paperBackgroundColor" ), Qt::white ) );
121 mSqlLexer->setFont( font, -1 );
122 font.setBold(
true );
123 mSqlLexer->setFont( font, QsciLexerSQL::Keyword );
125 mSqlLexer->setColor( Qt::darkYellow, QsciLexerSQL::DoubleQuotedString );
127 mSqlLexer->setColor( defaultColor, QsciLexerSQL::Default );
128 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/commentFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerSQL::Comment );
129 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/commentLineFontColor" ), QColor( 142, 144, 140 ) ), QsciLexerSQL::CommentLine );
130 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/numberFontColor" ), QColor( 200, 40, 41 ) ), QsciLexerSQL::Number );
131 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/keywordFontColor" ), QColor( 137, 89, 168 ) ), QsciLexerSQL::Keyword );
132 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/singleQuoteFontColor" ), QColor( 113, 140, 0 ) ), QsciLexerSQL::SingleQuotedString );
133 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/doubleQuoteFontColor" ), QColor( 234, 183, 0 ) ), QsciLexerSQL::DoubleQuotedString );
134 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/operatorFontColor" ), QColor( 66, 113, 174 ) ), QsciLexerSQL::Operator );
135 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/identifierFontColor" ), QColor( 62, 153, 159 ) ), QsciLexerSQL::Identifier );
136 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/QuotedIdentifierFontColor" ), Qt::black ), QsciLexerSQL::QuotedIdentifier );
137 mSqlLexer->setColor( colors.value( QStringLiteral(
"sql/QuotedOperatorFontColor" ), Qt::black ), QsciLexerSQL::QuotedOperator );
139 setLexer( mSqlLexer );
142 void QgsCodeEditorExpression::updateApis()
144 mApis =
new QgsSciApisExpression( mSqlLexer );
146 for (
const QString &var : qgis::as_const( mVariables ) )
151 for (
const QString &
function : qgis::as_const( mContextFunctions ) )
153 mApis->add(
function );
156 for (
const QString &
function : qgis::as_const( mFunctions ) )
158 mApis->add(
function );
161 for (
const QString &fieldName : qgis::as_const( mFieldNames ) )
163 mApis->add( fieldName );
167 mSqlLexer->setAPIs( mApis );
171 QgsLexerExpression::QgsLexerExpression( QObject *parent )
172 : QsciLexerSQL( parent )
176 const char *QgsLexerExpression::language()
const
178 return "QGIS Expression";
181 bool QgsLexerExpression::caseSensitive()
const
186 const char *QgsLexerExpression::wordCharacters()
const
188 return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@";
191 QgsSciApisExpression::QgsSciApisExpression( QsciLexer *lexer )
197 QStringList QgsSciApisExpression::callTips(
const QStringList &context,
int commas, QsciScintilla::CallTipsStyle style, QList<int> &shifts )
199 const QStringList originalTips = QsciAPIs::callTips( context, commas, style, shifts );
200 QStringList lowercaseTips;
201 for (
const QString &tip : originalTips )
202 lowercaseTips << tip.toLower();
204 return lowercaseTips;