17 #include <QMessageBox>
18 #include <QVersionNumber>
25 #include "qgssettings.h"
34 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
35 .arg( QCoreApplication::translate(
"relation_help",
"relation %1" ).arg( relation.
name() ),
36 QObject::tr(
"Inserts the relation ID for the relation named '%1'." ).arg( relation.
name() ) );
38 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
39 .arg( QObject::tr(
"Current value" ), relation.
id() );
48 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
49 .arg( QCoreApplication::translate(
"layer_help",
"map layer %1" ).arg( layer->
name() ),
50 QObject::tr(
"Inserts the layer ID for the layer named '%1'." ).arg( layer->
name() ) );
52 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
53 .arg( QObject::tr(
"Current value" ), layer->
id() );
61 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
62 .arg( QCoreApplication::translate(
"recent_expression_help",
"expression %1" ).arg( label ),
63 QCoreApplication::translate(
"recent_expression_help",
"Recently used expression." ) );
65 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
66 .arg( QObject::tr(
"Expression" ), expression );
74 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
75 .arg( QCoreApplication::translate(
"user_expression_help",
"expression %1" ).arg( label ), description );
77 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><pre>%2</pre></div>" )
78 .arg( QObject::tr(
"Expression" ), expression );
84 QString
formatVariableHelp(
const QString &variable,
const QString &description,
bool showValue,
const QVariant &value )
86 QString text = QStringLiteral(
"<h3>%1</h3>\n<div class=\"description\"><p>%2</p></div>" )
87 .arg( QCoreApplication::translate(
"variable_help",
"variable %1" ).arg( variable ), description );
91 QString valueString = !value.isValid()
92 ? QCoreApplication::translate(
"variable_help",
"not set" )
95 text += QStringLiteral(
"<h4>%1</h4><div class=\"description\"><p>%2</p></div>" )
96 .arg( QObject::tr(
"Current value" ), valueString );
110 : QTreeView( parent )
113 connect(
this, &QTreeView::doubleClicked,
this, &QgsExpressionTreeView::onDoubleClicked );
115 mModel = std::make_unique<QStandardItemModel>();
116 mProxyModel = std::make_unique<QgsExpressionItemSearchProxy>();
117 mProxyModel->setDynamicSortFilter(
true );
118 mProxyModel->setSourceModel( mModel.get() );
119 setModel( mProxyModel.get() );
120 setSortingEnabled(
true );
121 sortByColumn( 0, Qt::AscendingOrder );
123 setSelectionMode( QAbstractItemView::SelectionMode::SingleSelection );
125 setContextMenuPolicy( Qt::CustomContextMenu );
126 connect(
this, &QWidget::customContextMenuRequested,
this, &QgsExpressionTreeView::showContextMenu );
127 connect( selectionModel(), &QItemSelectionModel::currentChanged,
this, &QgsExpressionTreeView::currentItemChanged );
129 updateFunctionTree();
134 QModelIndex firstItem = mProxyModel->index( 0, 0, QModelIndex() );
135 setCurrentIndex( firstItem );
152 mExpressionContext = context;
153 updateFunctionTree();
161 mMenuProvider = provider;
166 updateFunctionTree();
174 QModelIndex idx = mProxyModel->mapToSource( currentIndex() );
192 updateFunctionTree();
198 mProxyModel->setFilterWildcard( text );
199 if ( text.isEmpty() )
206 QModelIndex index = mProxyModel->index( 0, 0 );
207 if ( mProxyModel->hasChildren( index ) )
209 QModelIndex child = mProxyModel->index( 0, 0, index );
210 selectionModel()->setCurrentIndex( child, QItemSelectionModel::ClearAndSelect );
215 void QgsExpressionTreeView::onDoubleClicked(
const QModelIndex &index )
217 QModelIndex idx = mProxyModel->mapToSource( index );
229 void QgsExpressionTreeView::showContextMenu( QPoint pt )
231 QModelIndex idx = indexAt( pt );
232 idx = mProxyModel->mapToSource( idx );
237 if ( !mMenuProvider )
243 menu->popup( mapToGlobal( pt ) );
246 void QgsExpressionTreeView::currentItemChanged(
const QModelIndex &index,
const QModelIndex & )
249 QModelIndex idx = mProxyModel->mapToSource( index );
257 void QgsExpressionTreeView::updateFunctionTree()
260 mExpressionGroups.clear();
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(
"||" ), QStringLiteral(
" || " ) );
278 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IN" ), QStringLiteral(
" IN " ) );
279 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"LIKE" ), QStringLiteral(
" LIKE " ) );
280 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"ILIKE" ), QStringLiteral(
" ILIKE " ) );
281 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IS" ), QStringLiteral(
" IS " ) );
282 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IS NOT" ), QStringLiteral(
" IS NOT " ) );
283 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"OR" ), QStringLiteral(
" OR " ) );
284 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"AND" ), QStringLiteral(
" AND " ) );
285 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"NOT" ), QStringLiteral(
" NOT " ) );
287 QString casestring = QStringLiteral(
"CASE WHEN condition THEN result END" );
288 registerItem( QStringLiteral(
"Conditionals" ), QStringLiteral(
"CASE" ), casestring );
291 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"NULL" ), QStringLiteral(
"NULL" ), QString(),
QgsExpressionItem::ExpressionNode,
false, -1 );
295 for (
int i = 0; i < count; i++ )
298 QString name = func->
name();
299 if ( name.startsWith(
'_' ) )
309 if ( func->
params() != 0 )
311 else if ( !name.startsWith(
'$' ) )
312 name += QLatin1String(
"()" );
323 loadExpressionContext();
326 void QgsExpressionTreeView::registerItem(
const QString &group,
327 const QString &label,
328 const QString &expressionText,
329 const QString &helpText,
333 item->setData( label, Qt::UserRole );
337 item->setIcon( icon );
340 if ( mExpressionGroups.contains( group ) )
343 groupNode->appendRow( item );
349 newgroupNode->setData( group, Qt::UserRole );
352 newgroupNode->appendRow( item );
353 newgroupNode->setBackground( QBrush( QColor( 150, 150, 150, 150 ) ) );
354 mModel->appendRow( newgroupNode );
355 mExpressionGroups.insert( group, newgroupNode );
358 if ( highlightedItem )
362 topLevelItem->setData( label, Qt::UserRole );
364 QFont font = topLevelItem->font();
365 font.setBold(
true );
366 topLevelItem->setFont( font );
367 mModel->appendRow( topLevelItem );
371 void QgsExpressionTreeView::registerItemForAllGroups(
const QStringList &groups,
const QString &label,
const QString &expressionText,
const QString &helpText,
QgsExpressionItem::ItemType type,
bool highlightedItem,
int sortOrder,
const QStringList &tags )
373 const auto constGroups = groups;
374 for (
const QString &group : constGroups )
376 registerItem( group, label, expressionText, helpText, type, highlightedItem, sortOrder, QIcon(), tags );
380 void QgsExpressionTreeView::loadExpressionContext()
383 const auto constVariableNames = variableNames;
384 for (
const QString &variable : constVariableNames )
386 registerItem( QStringLiteral(
"Variables" ), variable,
" @" + variable +
' ',
393 QStringList contextFunctions = mExpressionContext.
functionNames();
394 const auto constContextFunctions = contextFunctions;
395 for (
const QString &functionName : constContextFunctions )
398 QString name = func->
name();
399 if ( name.startsWith(
'_' ) )
401 if ( func->
params() != 0 )
407 void QgsExpressionTreeView::loadLayers()
412 QMap<QString, QgsMapLayer *> layers = mProject->mapLayers();
413 QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
414 for ( ; layerIt != layers.constEnd(); ++layerIt )
423 for (
int i = 0; i < fields.
count(); ++i )
432 void QgsExpressionTreeView::loadFieldNames()
435 if ( mExpressionGroups.contains( QStringLiteral(
"Fields and Values" ) ) )
437 QgsExpressionItem *node = mExpressionGroups.value( QStringLiteral(
"Fields and Values" ) );
438 node->removeRows( 0, node->rowCount() );
441 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"NULL" ), QStringLiteral(
"NULL" ), QString(),
QgsExpressionItem::ExpressionNode,
false, -1 );
453 void QgsExpressionTreeView::loadRelations()
458 QMap<QString, QgsRelation> relations = mProject->relationManager()->relations();
459 QMap<QString, QgsRelation>::const_iterator relIt = relations.constBegin();
460 for ( ; relIt != relations.constEnd(); ++relIt )
462 registerItemForAllGroups( QStringList() << tr(
"Relations" ), relIt->name(), QStringLiteral(
"'%1'" ).arg( relIt->id() ),
formatRelationHelp( relIt.value() ) );
468 mRecentKey = collection;
469 QString name = tr(
"Recent (%1)" ).arg( collection );
470 if ( mExpressionGroups.contains( name ) )
473 node->removeRows( 0, node->rowCount() );
476 QgsSettings settings;
477 const QString location = QStringLiteral(
"/expressions/recent/%1" ).arg( collection );
478 const QStringList expressions = settings.value( location ).toStringList();
480 for (
const QString &expression : expressions )
483 QString label = expression;
484 label.replace(
'\n',
' ' );
492 QgsSettings settings;
493 QString location = QStringLiteral(
"/expressions/recent/%1" ).arg( collection );
494 QStringList expressions = settings.value( location ).toStringList();
495 expressions.removeAll( expressionText );
497 expressions.prepend( expressionText );
499 while ( expressions.count() > 20 )
501 expressions.pop_back();
504 settings.setValue( location, expressions );
510 QgsSettings settings;
511 const QString location = QStringLiteral(
"user" );
512 settings.beginGroup( location, QgsSettings::Section::Expressions );
513 settings.beginGroup( label );
514 settings.setValue( QStringLiteral(
"expression" ), expression );
515 settings.setValue( QStringLiteral(
"helpText" ), helpText );
518 const QModelIndexList idxs { mModel->match( mModel->index( 0, 0 ), Qt::DisplayRole, label, 1, Qt::MatchFlag::MatchRecursive ) };
519 if ( ! idxs.isEmpty() )
521 scrollTo( idxs.first() );
527 QgsSettings settings;
528 settings.remove( QStringLiteral(
"user/%1" ).arg( label ), QgsSettings::Section::Expressions );
536 if ( mExpressionGroups.contains( QStringLiteral(
"UserGroup" ) ) )
538 QgsExpressionItem *node = mExpressionGroups.value( QStringLiteral(
"UserGroup" ) );
539 node->removeRows( 0, node->rowCount() );
542 QgsSettings settings;
543 const QString location = QStringLiteral(
"user" );
544 settings.beginGroup( location, QgsSettings::Section::Expressions );
549 mUserExpressionLabels = settings.childGroups();
550 for (
const auto &label : std::as_const( mUserExpressionLabels ) )
552 settings.beginGroup( label );
553 expression = settings.value( QStringLiteral(
"expression" ) ).toString();
554 helpText =
formatUserExpressionHelp( label, expression, settings.value( QStringLiteral(
"helpText" ) ).toString() );
562 return mUserExpressionLabels;
567 const QString group = QStringLiteral(
"user" );
568 QgsSettings settings;
569 QJsonArray exportList;
570 QJsonObject exportObject
573 {
"exported_at", QDateTime::currentDateTime().toString( Qt::ISODate )},
575 {
"expressions", exportList}
578 settings.beginGroup( group, QgsSettings::Section::Expressions );
580 mUserExpressionLabels = settings.childGroups();
582 for (
const QString &label : std::as_const( mUserExpressionLabels ) )
584 settings.beginGroup( label );
586 const QString expression = settings.value( QStringLiteral(
"expression" ) ).toString();
587 const QString helpText = settings.value( QStringLiteral(
"helpText" ) ).toString();
588 const QJsonObject expressionObject
591 {
"type",
"expression"},
592 {
"expression", expression},
594 {
"description", helpText}
596 exportList.push_back( expressionObject );
601 exportObject[
"expressions"] = exportList;
602 QJsonDocument exportJson = QJsonDocument( exportObject );
610 if ( ! expressionsDocument.isObject() )
613 QJsonObject expressionsObject = expressionsDocument.object();
616 if ( ! expressionsObject[
"qgis_version"].isString()
617 || ! expressionsObject[
"exported_at"].isString()
618 || ! expressionsObject[
"author"].isString()
619 || ! expressionsObject[
"expressions"].isArray() )
623 QVersionNumber qgisJsonVersion = QVersionNumber::fromString( expressionsObject[
"qgis_version"].toString() );
624 QVersionNumber qgisVersion = QVersionNumber::fromString(
Qgis::version() );
628 if ( qgisJsonVersion > qgisVersion )
630 QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No;
631 switch ( QMessageBox::question(
this,
632 tr(
"QGIS Version Mismatch" ),
633 tr(
"The imported expressions are from newer version of QGIS (%1) "
634 "and some of the expression might not work the current version (%2). "
635 "Are you sure you want to continue?" ).arg( qgisJsonVersion.toString(), qgisVersion.toString() ), buttons ) )
637 case QMessageBox::No:
640 case QMessageBox::Yes:
649 QStringList skippedExpressionLabels;
650 bool isApplyToAll =
false;
651 bool isOkToOverwrite =
false;
653 QgsSettings settings;
654 settings.beginGroup( QStringLiteral(
"user" ), QgsSettings::Section::Expressions );
655 mUserExpressionLabels = settings.childGroups();
657 for (
const QJsonValue && expressionValue : expressionsObject[
"expressions"].toArray() )
660 if ( ! expressionValue.isObject() )
663 skippedExpressionLabels.append( expressionValue.toString() );
667 QJsonObject expressionObj = expressionValue.toObject();
670 if ( ! expressionObj[
"name"].isString()
671 || ! expressionObj[
"type"].isString()
672 || ! expressionObj[
"expression"].isString()
673 || ! expressionObj[
"group"].isString()
674 || ! expressionObj[
"description"].isString() )
677 if ( ! expressionObj[
"name"].toString().isEmpty() )
678 skippedExpressionLabels.append( expressionObj[
"name"].toString() );
680 skippedExpressionLabels.append( expressionObj[
"expression"].toString() );
686 if ( expressionObj[
"type"].toString() != QLatin1String(
"expression" ) )
688 skippedExpressionLabels.append( expressionObj[
"name"].toString() );
693 if ( expressionObj[
"group"].toString() != QLatin1String(
"user" ) )
695 skippedExpressionLabels.append( expressionObj[
"name"].toString() );
699 const QString label = expressionObj[
"name"].toString();
700 const QString expression = expressionObj[
"expression"].toString();
701 const QString helpText = expressionObj[
"description"].toString();
704 if ( label.contains(
"\\" ) || label.contains(
'/' ) )
706 skippedExpressionLabels.append( expressionObj[
"name"].toString() );
710 settings.beginGroup( label );
711 const QString oldExpression = settings.value( QStringLiteral(
"expression" ) ).toString();
715 if ( mUserExpressionLabels.contains( label ) && expression != oldExpression )
717 if ( ! isApplyToAll )
718 showMessageBoxConfirmExpressionOverwrite( isApplyToAll, isOkToOverwrite, label, oldExpression, expression );
720 if ( isOkToOverwrite )
724 skippedExpressionLabels.append( label );
736 if ( ! skippedExpressionLabels.isEmpty() )
738 QStringList skippedExpressionLabelsQuoted;
739 for (
const QString &skippedExpressionLabel : skippedExpressionLabels )
740 skippedExpressionLabelsQuoted.append( QStringLiteral(
"'%1'" ).arg( skippedExpressionLabel ) );
742 QMessageBox::information(
this,
743 tr(
"Skipped Expression Imports" ),
744 QStringLiteral(
"%1\n%2" ).arg( tr(
"The following expressions have been skipped:" ),
745 skippedExpressionLabelsQuoted.join(
", " ) ) );
751 QList<QgsExpressionItem *> result;
752 const QList<QStandardItem *> found { mModel->findItems( label, Qt::MatchFlag::MatchRecursive ) };
753 for (
const auto &item : std::as_const( found ) )
760 void QgsExpressionTreeView::showMessageBoxConfirmExpressionOverwrite(
762 bool &isOkToOverwrite,
763 const QString &label,
764 const QString &oldExpression,
765 const QString &newExpression )
767 QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll;
768 switch ( QMessageBox::question(
this,
769 tr(
"Expression Overwrite" ),
770 tr(
"The expression with label '%1' was already defined."
771 "The old expression \"%2\" will be overwritten by \"%3\"."
772 "Are you sure you want to overwrite the expression?" ).arg( label, oldExpression, newExpression ), buttons ) )
774 case QMessageBox::NoToAll:
776 isOkToOverwrite =
false;
779 case QMessageBox::No:
780 isApplyToAll =
false;
781 isOkToOverwrite =
false;
784 case QMessageBox::YesToAll:
786 isOkToOverwrite =
true;
789 case QMessageBox::Yes:
790 isApplyToAll =
false;
791 isOkToOverwrite =
true;
808 setFilterCaseSensitivity( Qt::CaseInsensitive );
813 QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
816 int count = sourceModel()->rowCount( index );
817 bool matchchild =
false;
818 for (
int i = 0; i < count; ++i )
834 if ( QSortFilterProxyModel::filterAcceptsRow( source_row, source_parent ) )
841 for (
const QString &tag : tags )
843 if ( tag.contains( filterRegExp() ) )
854 if ( leftSort != rightSort )
855 return leftSort < rightSort;
857 QString leftString = sourceModel()->data( left, Qt::DisplayRole ).toString();
858 QString rightString = sourceModel()->data( right, Qt::DisplayRole ).toString();
861 if ( leftString.startsWith(
'$' ) )
862 leftString = leftString.mid( 1 );
863 if ( rightString.startsWith(
'$' ) )
864 rightString = rightString.mid( 1 );
866 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
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QgsExpressionItemSearchProxy()
An expression item that can be used in the QgsExpressionBuilderWidget tree.
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 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,...
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.