18#include <QVersionNumber>
33 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
34 .arg( QCoreApplication::translate(
"relation_help",
"relation %1" ).arg( relation.
name() ),
35 QObject::tr(
"Inserts the relation ID for the relation named '%1'." ).arg( relation.
name() ) );
37 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
38 .arg( QObject::tr(
"Current value" ), relation.
id() );
47 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
48 .arg( QCoreApplication::translate(
"layer_help",
"map layer %1" ).arg( layer->
name() ),
49 QObject::tr(
"Inserts the layer ID for the layer named '%1'." ).arg( layer->
name() ) );
51 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
52 .arg( QObject::tr(
"Current value" ), layer->
id() );
60 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
61 .arg( QCoreApplication::translate(
"recent_expression_help",
"expression %1" ).arg( label ),
62 QCoreApplication::translate(
"recent_expression_help",
"Recently used expression." ) );
64 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
65 .arg( QObject::tr(
"Expression" ), expression );
73 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
74 .arg( QCoreApplication::translate(
"user_expression_help",
"expression %1" ).arg( label ), description );
76 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
77 .arg( QObject::tr(
"Expression" ), expression );
83QString
formatVariableHelp(
const QString &variable,
const QString &description,
bool showValue,
const QVariant &value )
85 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
86 .arg( QCoreApplication::translate(
"variable_help",
"variable %1" ).arg( variable ), description );
90 QString valueString = !value.isValid()
91 ? QCoreApplication::translate(
"variable_help",
"not set" )
94 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><p>%2</p></div>" )
95 .arg( QObject::tr(
"Current value" ), valueString );
109 : QTreeView( parent )
112 connect(
this, &QTreeView::doubleClicked,
this, &QgsExpressionTreeView::onDoubleClicked );
114 mModel = std::make_unique<QStandardItemModel>();
115 mProxyModel = std::make_unique<QgsExpressionItemSearchProxy>();
116 mProxyModel->setDynamicSortFilter(
true );
117 mProxyModel->setSourceModel( mModel.get() );
118 setModel( mProxyModel.get() );
119 setSortingEnabled(
true );
120 sortByColumn( 0, Qt::AscendingOrder );
122 setSelectionMode( QAbstractItemView::SelectionMode::SingleSelection );
124 setContextMenuPolicy( Qt::CustomContextMenu );
125 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsExpressionTreeView::showContextMenu );
126 connect( selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsExpressionTreeView::currentItemChanged );
128 updateFunctionTree();
133 QModelIndex firstItem = mProxyModel->index( 0, 0, QModelIndex() );
134 setCurrentIndex( firstItem );
151 mExpressionContext = context;
152 updateFunctionTree();
160 mMenuProvider = provider;
165 updateFunctionTree();
173 QModelIndex idx = mProxyModel->mapToSource( currentIndex() );
191 updateFunctionTree();
197 mProxyModel->setFilterString( text );
198 if ( text.isEmpty() )
205 QModelIndex index = mProxyModel->index( 0, 0 );
206 if ( mProxyModel->hasChildren( index ) )
208 QModelIndex child = mProxyModel->index( 0, 0, index );
209 selectionModel()->setCurrentIndex( child, QItemSelectionModel::ClearAndSelect );
214void QgsExpressionTreeView::onDoubleClicked(
const QModelIndex &index )
216 QModelIndex idx = mProxyModel->mapToSource( index );
228void QgsExpressionTreeView::showContextMenu( QPoint pt )
230 QModelIndex idx = indexAt( pt );
231 idx = mProxyModel->mapToSource( idx );
236 if ( !mMenuProvider )
242 menu->popup( mapToGlobal( pt ) );
245void QgsExpressionTreeView::currentItemChanged(
const QModelIndex &index,
const QModelIndex & )
248 QModelIndex idx = mProxyModel->mapToSource( index );
256void QgsExpressionTreeView::updateFunctionTree()
259 mExpressionGroups.clear();
262 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"+" ), QStringLiteral(
" + " ) );
263 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"-" ), QStringLiteral(
" - " ) );
264 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"*" ), QStringLiteral(
" * " ) );
265 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"/" ), QStringLiteral(
" / " ) );
266 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"%" ), QStringLiteral(
" % " ) );
267 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"^" ), QStringLiteral(
" ^ " ) );
268 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"=" ), QStringLiteral(
" = " ) );
269 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"~" ), QStringLiteral(
" ~ " ) );
270 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
">" ), QStringLiteral(
" > " ) );
271 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"<" ), QStringLiteral(
" < " ) );
272 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"<>" ), QStringLiteral(
" <> " ) );
273 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"<=" ), QStringLiteral(
" <= " ) );
274 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
">=" ), QStringLiteral(
" >= " ) );
275 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"[]" ), QStringLiteral(
"[ ]" ) );
276 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"||" ), QStringLiteral(
" || " ) );
277 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"BETWEEN" ), QStringLiteral(
" BETWEEN " ) );
278 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"NOT BETWEEN" ), QStringLiteral(
" NOT BETWEEN " ) );
279 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IN" ), QStringLiteral(
" IN " ) );
280 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"LIKE" ), QStringLiteral(
" LIKE " ) );
281 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"ILIKE" ), QStringLiteral(
" ILIKE " ) );
282 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IS" ), QStringLiteral(
" IS " ) );
283 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IS NOT" ), QStringLiteral(
" IS NOT " ) );
284 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"OR" ), QStringLiteral(
" OR " ) );
285 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"AND" ), QStringLiteral(
" AND " ) );
286 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"NOT" ), QStringLiteral(
" NOT " ) );
288 QString casestring = QStringLiteral(
"CASE WHEN condition THEN result END" );
289 registerItem( QStringLiteral(
"Conditionals" ), QStringLiteral(
"CASE" ), casestring );
292 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"NULL" ), QStringLiteral(
"NULL" ), QString(),
QgsExpressionItem::ExpressionNode,
false, -1 );
296 for (
int i = 0; i < count; i++ )
299 QString name = func->
name();
300 if ( name.startsWith(
'_' ) )
310 if ( func->
params() != 0 )
312 else if ( !name.startsWith(
'$' ) )
313 name += QLatin1String(
"()" );
324 loadExpressionContext();
328 const QString &label,
329 const QString &expressionText,
330 const QString &helpText,
331 QgsExpressionItem::ItemType type,
bool highlightedItem,
int sortOrder,
const QIcon &icon,
const QStringList &tags,
const QString &name )
334 item->setData( label, Qt::UserRole );
338 item->setIcon( icon );
341 if ( mExpressionGroups.contains( group ) )
344 groupNode->appendRow( item );
350 newgroupNode->setData( group, Qt::UserRole );
353 newgroupNode->appendRow( item );
354 newgroupNode->setBackground( QBrush( QColor( 150, 150, 150, 150 ) ) );
355 mModel->appendRow( newgroupNode );
356 mExpressionGroups.insert( group, newgroupNode );
359 if ( highlightedItem )
363 topLevelItem->setData( label, Qt::UserRole );
365 QFont font = topLevelItem->font();
366 font.setBold(
true );
367 topLevelItem->setFont( font );
368 mModel->appendRow( topLevelItem );
373void QgsExpressionTreeView::registerItemForAllGroups(
const QStringList &groups,
const QString &label,
const QString &expressionText,
const QString &helpText,
QgsExpressionItem::ItemType type,
bool highlightedItem,
int sortOrder,
const QStringList &tags )
375 const auto constGroups = groups;
376 for (
const QString &group : constGroups )
378 registerItem( group, label, expressionText, helpText, type, highlightedItem, sortOrder, QIcon(), tags );
382void QgsExpressionTreeView::loadExpressionContext()
385 const auto constVariableNames = variableNames;
386 for (
const QString &variable : constVariableNames )
388 registerItem( QStringLiteral(
"Variables" ), variable,
" @" + variable +
' ',
395 QStringList contextFunctions = mExpressionContext.
functionNames();
396 const auto constContextFunctions = contextFunctions;
397 for (
const QString &functionName : constContextFunctions )
400 QString name = func->
name();
401 if ( name.startsWith(
'_' ) )
403 if ( func->
params() != 0 )
409void QgsExpressionTreeView::loadLayers()
414 QMap<QString, QgsMapLayer *> layers = mProject->mapLayers();
415 QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
416 for ( ; layerIt != layers.constEnd(); ++layerIt )
420 loadLayerFields( qobject_cast<QgsVectorLayer *>( layerIt.value() ), parentItem );
431 for (
int fieldIdx = 0; fieldIdx < fields.
count(); ++fieldIdx )
437 item->setData( label, Qt::UserRole );
442 item->setIcon( icon );
443 parentItem->appendRow( item );
449 for (
int i = 0; i < fields.
count(); ++i )
458void QgsExpressionTreeView::loadFieldNames()
461 if ( mExpressionGroups.contains( QStringLiteral(
"Fields and Values" ) ) )
463 QgsExpressionItem *node = mExpressionGroups.value( QStringLiteral(
"Fields and Values" ) );
464 node->removeRows( 0, node->rowCount() );
467 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"NULL" ), QStringLiteral(
"NULL" ), QString(),
QgsExpressionItem::ExpressionNode,
false, -1 );
478 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"feature" ), QStringLiteral(
"@feature" ), currentFeatureHelp,
QgsExpressionItem::ExpressionNode,
false, -1 );
479 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"id" ), QStringLiteral(
"@id" ), currentFeatureIdHelp,
QgsExpressionItem::ExpressionNode,
false, -1 );
480 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"geometry" ), QStringLiteral(
"@geometry" ), currentGeometryHelp,
QgsExpressionItem::ExpressionNode,
false, -1 );
486 registerItem( tr(
"Record and Attributes" ), QStringLiteral(
"feature" ), QStringLiteral(
"@feature" ), currentFeatureHelp,
QgsExpressionItem::ExpressionNode,
true, -1 );
487 registerItem( tr(
"Record and Attributes" ), QStringLiteral(
"id" ), QStringLiteral(
"@id" ), currentFeatureIdHelp,
QgsExpressionItem::ExpressionNode,
true, -1 );
488 registerItem( tr(
"Record and Attributes" ), QStringLiteral(
"geometry" ), QStringLiteral(
"@geometry" ), currentGeometryHelp,
QgsExpressionItem::ExpressionNode,
true, -1 );
500void QgsExpressionTreeView::loadRelations()
505 QMap<QString, QgsRelation> relations = mProject->relationManager()->relations();
506 QMap<QString, QgsRelation>::const_iterator relIt = relations.constBegin();
507 for ( ; relIt != relations.constEnd(); ++relIt )
509 registerItemForAllGroups( QStringList() << tr(
"Relations" ), relIt->name(), QStringLiteral(
"'%1'" ).arg( relIt->id() ),
formatRelationHelp( relIt.value() ) );
515 mRecentKey = collection;
516 QString name = tr(
"Recent (%1)" ).arg( collection );
517 if ( mExpressionGroups.contains( name ) )
520 node->removeRows( 0, node->rowCount() );
524 const QString location = QStringLiteral(
"/expressions/recent/%1" ).arg( collection );
525 const QStringList expressions = settings.
value( location ).toStringList();
527 for (
const QString &expression : expressions )
530 QString label = expression;
531 label.replace(
'\n',
' ' );
540 QString location = QStringLiteral(
"/expressions/recent/%1" ).arg( collection );
541 QStringList expressions = settings.
value( location ).toStringList();
542 expressions.removeAll( expressionText );
544 expressions.prepend( expressionText );
546 while ( expressions.count() > 20 )
548 expressions.pop_back();
551 settings.
setValue( location, expressions );
558 const QString location = QStringLiteral(
"user" );
559 settings.
beginGroup( location, QgsSettings::Section::Expressions );
561 settings.
setValue( QStringLiteral(
"expression" ), expression );
562 settings.
setValue( QStringLiteral(
"helpText" ), helpText );
565 const QModelIndexList idxs { mModel->match( mModel->index( 0, 0 ), Qt::DisplayRole, label, 1, Qt::MatchFlag::MatchRecursive ) };
566 if ( ! idxs.isEmpty() )
568 scrollTo( idxs.first() );
575 settings.
remove( QStringLiteral(
"user/%1" ).arg( label ), QgsSettings::Section::Expressions );
583 if ( mExpressionGroups.contains( QStringLiteral(
"UserGroup" ) ) )
585 QgsExpressionItem *node = mExpressionGroups.value( QStringLiteral(
"UserGroup" ) );
586 node->removeRows( 0, node->rowCount() );
590 const QString location = QStringLiteral(
"user" );
591 settings.
beginGroup( location, QgsSettings::Section::Expressions );
596 for (
const auto &label : std::as_const( mUserExpressionLabels ) )
599 expression = settings.
value( QStringLiteral(
"expression" ) ).toString();
608 return mUserExpressionLabels;
613 const QString group = QStringLiteral(
"user" );
615 QJsonArray exportList;
616 QJsonObject exportObject
619 {
"exported_at", QDateTime::currentDateTime().toString( Qt::ISODate )},
621 {
"expressions", exportList}
624 settings.
beginGroup( group, QgsSettings::Section::Expressions );
628 for (
const QString &label : std::as_const( mUserExpressionLabels ) )
632 const QString expression = settings.
value( QStringLiteral(
"expression" ) ).toString();
633 const QString helpText = settings.
value( QStringLiteral(
"helpText" ) ).toString();
634 const QJsonObject expressionObject
637 {
"type",
"expression"},
638 {
"expression", expression},
640 {
"description", helpText}
642 exportList.push_back( expressionObject );
647 exportObject[QStringLiteral(
"expressions" )] = exportList;
648 QJsonDocument exportJson = QJsonDocument( exportObject );
656 if ( ! expressionsDocument.isObject() )
659 QJsonObject expressionsObject = expressionsDocument.object();
662 if ( ! expressionsObject[QStringLiteral(
"qgis_version" )].isString()
663 || ! expressionsObject[QStringLiteral(
"exported_at" )].isString()
664 || ! expressionsObject[QStringLiteral(
"author" )].isString()
665 || ! expressionsObject[QStringLiteral(
"expressions" )].isArray() )
669 QVersionNumber qgisJsonVersion = QVersionNumber::fromString( expressionsObject[QStringLiteral(
"qgis_version" )].toString() );
670 QVersionNumber qgisVersion = QVersionNumber::fromString(
Qgis::version() );
674 if ( qgisJsonVersion > qgisVersion )
676 QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No;
677 switch ( QMessageBox::question(
this,
678 tr(
"QGIS Version Mismatch" ),
679 tr(
"The imported expressions are from newer version of QGIS (%1) "
680 "and some of the expression might not work the current version (%2). "
681 "Are you sure you want to continue?" ).arg( qgisJsonVersion.toString(), qgisVersion.toString() ), buttons ) )
683 case QMessageBox::No:
686 case QMessageBox::Yes:
695 QStringList skippedExpressionLabels;
696 bool isApplyToAll =
false;
697 bool isOkToOverwrite =
false;
700 settings.
beginGroup( QStringLiteral(
"user" ), QgsSettings::Section::Expressions );
703 const QJsonArray expressions = expressionsObject[QStringLiteral(
"expressions" )].toArray();
704 for (
const QJsonValue && expressionValue : expressions )
707 if ( ! expressionValue.isObject() )
710 skippedExpressionLabels.append( expressionValue.toString() );
714 QJsonObject expressionObj = expressionValue.toObject();
717 if ( ! expressionObj[QStringLiteral(
"name" )].isString()
718 || ! expressionObj[QStringLiteral(
"type" )].isString()
719 || ! expressionObj[QStringLiteral(
"expression" )].isString()
720 || ! expressionObj[QStringLiteral(
"group" )].isString()
721 || ! expressionObj[QStringLiteral(
"description" )].isString() )
724 if ( ! expressionObj[QStringLiteral(
"name" )].toString().isEmpty() )
725 skippedExpressionLabels.append( expressionObj[QStringLiteral(
"name" )].toString() );
727 skippedExpressionLabels.append( expressionObj[QStringLiteral(
"expression" )].toString() );
733 if ( expressionObj[QStringLiteral(
"type" )].toString() != QLatin1String(
"expression" ) )
735 skippedExpressionLabels.append( expressionObj[QStringLiteral(
"name" )].toString() );
740 if ( expressionObj[QStringLiteral(
"group" )].toString() != QLatin1String(
"user" ) )
742 skippedExpressionLabels.append( expressionObj[QStringLiteral(
"name" )].toString() );
746 const QString label = expressionObj[QStringLiteral(
"name" )].toString();
747 const QString expression = expressionObj[QStringLiteral(
"expression" )].toString();
748 const QString helpText = expressionObj[QStringLiteral(
"description" )].toString();
751 if ( label.contains( QLatin1String(
"\\" ) ) || label.contains(
'/' ) )
753 skippedExpressionLabels.append( expressionObj[QStringLiteral(
"name" )].toString() );
758 const QString oldExpression = settings.
value( QStringLiteral(
"expression" ) ).toString();
762 if ( mUserExpressionLabels.contains( label ) && expression != oldExpression )
764 if ( ! isApplyToAll )
765 showMessageBoxConfirmExpressionOverwrite( isApplyToAll, isOkToOverwrite, label, oldExpression, expression );
767 if ( isOkToOverwrite )
771 skippedExpressionLabels.append( label );
783 if ( ! skippedExpressionLabels.isEmpty() )
785 QStringList skippedExpressionLabelsQuoted;
786 skippedExpressionLabelsQuoted.reserve( skippedExpressionLabels.size() );
787 for (
const QString &skippedExpressionLabel : skippedExpressionLabels )
788 skippedExpressionLabelsQuoted.append( QStringLiteral(
"'%1'" ).arg( skippedExpressionLabel ) );
790 QMessageBox::information(
this,
791 tr(
"Skipped Expression Imports" ),
792 QStringLiteral(
"%1\n%2" ).arg( tr(
"The following expressions have been skipped:" ),
793 skippedExpressionLabelsQuoted.join( QLatin1String(
", " ) ) ) );
799 QList<QgsExpressionItem *> result;
800 const QList<QStandardItem *> found { mModel->findItems( label, Qt::MatchFlag::MatchRecursive ) };
801 result.reserve( found.size() );
802 std::transform( found.begin(), found.end(), std::back_inserter( result ),
803 []( QStandardItem * item ) ->
QgsExpressionItem* { return static_cast<QgsExpressionItem *>( item ); } );
807void QgsExpressionTreeView::showMessageBoxConfirmExpressionOverwrite(
809 bool &isOkToOverwrite,
810 const QString &label,
811 const QString &oldExpression,
812 const QString &newExpression )
814 QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll;
815 switch ( QMessageBox::question(
this,
816 tr(
"Expression Overwrite" ),
817 tr(
"The expression with label '%1' was already defined."
818 "The old expression \"%2\" will be overwritten by \"%3\"."
819 "Are you sure you want to overwrite the expression?" ).arg( label, oldExpression, newExpression ), buttons ) )
821 case QMessageBox::NoToAll:
823 isOkToOverwrite =
false;
826 case QMessageBox::No:
827 isApplyToAll =
false;
828 isOkToOverwrite =
false;
831 case QMessageBox::YesToAll:
833 isOkToOverwrite =
true;
836 case QMessageBox::Yes:
837 isApplyToAll =
false;
838 isOkToOverwrite =
true;
855 setFilterCaseSensitivity( Qt::CaseInsensitive );
860 QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
866 int count = sourceModel()->rowCount( index );
867 bool matchchild =
false;
868 for (
int i = 0; i < count; ++i )
880 const QString name = sourceModel()->data( index, Qt::DisplayRole ).toString();
881 if ( name.contains( mFilterString, Qt::CaseInsensitive ) )
887 return std::any_of( tags.begin(), tags.end(), [
this](
const QString & tag )
889 return tag.contains( mFilterString, Qt::CaseInsensitive );
895 mFilterString = string;
903 if ( leftSort != rightSort )
904 return leftSort < rightSort;
906 QString leftString = sourceModel()->data( left, Qt::DisplayRole ).toString();
907 QString rightString = sourceModel()->data( right, Qt::DisplayRole ).toString();
910 if ( leftString.startsWith(
'$' ) )
911 leftString = leftString.mid( 1 );
912 if ( rightString.startsWith(
'$' ) )
913 rightString = rightString.mid( 1 );
915 return QString::localeAwareCompare( leftString, rightString ) < 0;
static QString version()
Version string.
static QString userFullName()
Returns the user's operating system login account full display name.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QString description(const QString &name) const
Returns a translated description string for the variable with specified name.
QStringList functionNames() const
Retrieves a list of function names contained in the context.
bool isHighlightedFunction(const QString &name) const
Returns true if the specified function name is intended to be highlighted to the user.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
QgsExpressionFunction * function(const QString &name) const
Fetches a matching function from the context.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
A abstract base class for defining QgsExpression functions.
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.
QStringList groups() const
Returns a list of the groups the function belongs to.
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 QString helpText() const
The help text for the function.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
void setFilterString(const QString &string)
Sets the search filter string.
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QgsExpressionItemSearchProxy()
An expression item that can be used in the QgsExpressionBuilderWidget tree.
static const int LAYER_ID_ROLE
Layer ID role.
QString getExpressionText() const
static const int SEARCH_TAGS_ROLE
Search tags role.
static const int ITEM_TYPE_ROLE
Item type role.
static const int CUSTOM_SORT_ROLE
Custom sort order role.
QgsExpressionItem::ItemType getItemType() const
Gets the type of expression item, e.g., header, field, ExpressionNode.
static const int ITEM_NAME_ROLE
Item name role.
QgsProject * project()
Returns the project currently associated with the widget.
void refresh()
Refreshes the content of the tree.
void setProject(QgsProject *project)
Sets the project currently associated with the widget.
void saveToUserExpressions(const QString &label, const QString &expression, const QString &helpText)
Stores the user expression with given label and helpText.
QgsExpressionItem * currentItem() const
Returns the current item or a nullptr.
void setLayer(QgsVectorLayer *layer)
Sets layer in order to get the fields and values.
void setMenuProvider(MenuProvider *provider)
Sets the menu provider.
QStringList userExpressionLabels() const
Returns the user expression labels.
void expressionItemDoubleClicked(const QString &text)
Emitted when a expression item is double clicked.
void currentExpressionItemChanged(QgsExpressionItem *item)
Emitter when the current expression item changed.
QJsonDocument exportUserExpressions()
Create the expressions JSON document storing all the user expressions to be exported.
QgsExpressionTreeView(QWidget *parent=nullptr)
Constructor.
void loadExpressionsFromJson(const QJsonDocument &expressionsDocument)
Load and permanently store the expressions from the expressions JSON document.
void saveToRecent(const QString &expressionText, const QString &collection="generic")
Adds the current expression to the given collection.
void setSearchText(const QString &text)
Sets the text to filter the expression tree.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context for the tree view.
const QList< QgsExpressionItem * > findExpressions(const QString &label)
Returns the list of expression items matching a label.
void removeFromUserExpressions(const QString &label)
Removes the expression label from the user stored expressions.
void loadRecent(const QString &collection=QStringLiteral("generic"))
Loads the recent expressions from the given collection.
void loadUserExpressions()
Loads the user expressions.
Q_DECL_DEPRECATED QStandardItemModel * model()
Returns a pointer to the dialog's function item model.
void loadFieldNames(const QgsFields &fields)
This allows loading fields without specifying a layer.
static const QList< QgsExpressionFunction * > & Functions()
static int functionCount()
Returns the number of functions defined in the parser.
static QString variableHelpText(const QString &variableName)
Returns the help text for a specified variable.
static QString formatPreviewString(const QVariant &value, bool htmlOutput=true, int maximumPreviewLength=60)
Formats an expression result for friendly display to the user.
static QStringList tags(const QString &name)
Returns a string list of search tags for a specified function.
static QString group(const QString &group)
Returns the translated name for a function group.
Encapsulate a field in an attribute table or data source.
QString displayNameWithAlias() const
Returns the name to use when displaying this field and adds the alias in parenthesis if it is defined...
Container of fields for a vector layer.
int count() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
QIcon iconForField(int fieldIdx, bool considerOrigin=false) const
Returns an icon corresponding to a field index, based on the field's type and source.
static QIcon iconForLayer(const QgsMapLayer *layer)
Returns the icon corresponding to a specified map layer.
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
This class is a composition of two QSettings instances:
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
void endGroup()
Resets the group to what it was before the corresponding beginGroup() call.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QString formatLayerHelp(const QgsMapLayer *layer)
Returns a HTML formatted string for use as a layer item help.
QString formatUserExpressionHelp(const QString &label, const QString &expression, const QString &description)
Returns a HTML formatted string for use as a user expression item help.
QString formatVariableHelp(const QString &variable, const QString &description, bool showValue, const QVariant &value)
Returns a HTML formatted string for use as a variable item help.
QString formatRecentExpressionHelp(const QString &label, const QString &expression)
Returns a HTML formatted string for use as a recent expression item help.
QString formatRelationHelp(const QgsRelation &relation)
Returns a HTML formatted string for use as a relation item help.