28 setTitle( tr(
"Expression Editor" ) );
31 setAutoCompletionCaseSensitivity(
false );
40 for (
const QString &var : variableNames )
42 mVariables <<
'@' + var;
50 for (
int i = 0; i < count; i++ )
62 QString signature = func->
name();
63 if ( !signature.startsWith(
'$' ) )
67 QStringList paramNames;
71 paramNames << param.name();
75 if ( parameters.isEmpty() && func->
params() )
76 signature += QChar( 0x2026 );
78 signature += paramNames.join(
", " );
82 mFunctions << signature;
105 mSqlLexer =
new QgsLexerExpression(
this );
106 mSqlLexer->setDefaultFont( font );
109 mSqlLexer->setFont( font, -1 );
110 font.setBold(
true );
111 mSqlLexer->setFont( font, QsciLexerSQL::Keyword );
113 font.setBold(
false );
114 font.setItalic(
true );
115 mSqlLexer->setFont( font, QsciLexerSQL::Comment );
116 mSqlLexer->setFont( font, QsciLexerSQL::CommentLine );
118 mSqlLexer->setColor( Qt::darkYellow, QsciLexerSQL::DoubleQuotedString );
120 mSqlLexer->setColor(
defaultColor, QsciLexerSQL::Default );
132 setLexer( mSqlLexer );
136 void QgsCodeEditorExpression::updateApis()
138 mApis =
new QgsSciApisExpression( mSqlLexer );
140 for (
const QString &var : std::as_const( mVariables ) )
145 for (
const QString &
function : std::as_const( mContextFunctions ) )
147 mApis->add(
function );
150 for (
const QString &
function : std::as_const( mFunctions ) )
152 mApis->add(
function );
155 for (
const QString &fieldName : std::as_const( mFieldNames ) )
157 mApis->add( fieldName );
160 mApis->add( QString(
"NULL" ) );
162 mSqlLexer->setAPIs( mApis );
166 QgsLexerExpression::QgsLexerExpression( QObject *parent )
167 : QsciLexerSQL( parent )
169 setBackslashEscapes(
true );
172 const char *QgsLexerExpression::language()
const
174 return "QGIS Expression";
177 bool QgsLexerExpression::caseSensitive()
const
182 const char *QgsLexerExpression::wordCharacters()
const
184 return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@";
187 QgsSciApisExpression::QgsSciApisExpression( QsciLexer *lexer )
193 QStringList QgsSciApisExpression::callTips(
const QStringList &context,
int commas, QsciScintilla::CallTipsStyle style, QList<int> &shifts )
195 const QStringList originalTips = QsciAPIs::callTips( context, commas, style, shifts );
196 QStringList lowercaseTips;
197 for (
const QString &tip : originalTips )
198 lowercaseTips << tip.toLower();
200 return lowercaseTips;
@ QuotedOperator
Quoted operator color.
@ Identifier
Identifier color.
@ DoubleQuote
Double quote color.
@ QuotedIdentifier
Quoted identifier color.
@ CommentLine
Line comment color.
@ Default
Default text color.
@ Background
Background color.
@ SingleQuote
Single quote color.
@ Operator
Operator color.
void initializeLexer() override
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
QgsCodeEditorExpression(QWidget *parent=nullptr)
Constructor for QgsCodeEditorExpression.
void setExpressionContext(const QgsExpressionContext &context)
Variables and functions from this expression context will be added to the API.
void setFields(const QgsFields &fields)
Field names will be added to the API.
A text editor based on QScintilla2.
void setFoldingVisible(bool folding)
Set whether the folding controls are visible in the editor.
void runPostLexerConfigurationTasks()
Performs tasks which must be run after a lexer has been set for the widget.
void setTitle(const QString &title)
Set the widget title.
QFont lexerFont() const
Returns the font to use in the lexer.
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.
static QColor defaultColor(QgsCodeEditorColorScheme::ColorRole role, const QString &theme=QString())
Returns the default color for the specified role.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QStringList functionNames() const
Retrieves a list of function names contained in the context.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
Represents a single parameter passed to a function.
A abstract base class for defining QgsExpression functions.
QList< QgsExpressionFunction::Parameter > ParameterList
List of parameters, used for function definition.
bool isContextual() const
Returns whether the function is only available if provided by a QgsExpressionContext object.
int params() const
The number of parameters this function takes.
virtual bool isDeprecated() const
Returns true if the function is deprecated and should not be presented as a valid option to users in ...
QString name() const
The name of the function.
const QgsExpressionFunction::ParameterList & parameters() const
Returns the list of named parameters for the function, if set.
static const QList< QgsExpressionFunction * > & Functions()
static int functionCount()
Returns the number of functions defined in the parser.
Encapsulate a field in an attribute table or data source.
Container of fields for a vector layer.