18 #include "qgsexpression.h" 19 #include "qgsexpressionfunction.h" 34 #include <QTextStream> 36 #include <QInputDialog> 38 #include <QGraphicsOpacityEffect> 39 #include <QPropertyAnimation> 47 connect( btnRun, &QToolButton::pressed,
this, &QgsExpressionBuilderWidget::btnRun_pressed );
48 connect( btnNewFile, &QToolButton::pressed,
this, &QgsExpressionBuilderWidget::btnNewFile_pressed );
49 connect( cmbFileNames, &QListWidget::currentItemChanged,
this, &QgsExpressionBuilderWidget::cmbFileNames_currentItemChanged );
50 connect( expressionTree, &QTreeView::doubleClicked,
this, &QgsExpressionBuilderWidget::expressionTree_doubleClicked );
51 connect( txtExpressionString, &QgsCodeEditorSQL::textChanged,
this, &QgsExpressionBuilderWidget::txtExpressionString_textChanged );
52 connect( txtPython, &QgsCodeEditorPython::textChanged,
this, &QgsExpressionBuilderWidget::txtPython_textChanged );
53 connect( txtSearchEditValues, &QgsFilterLineEdit::textChanged,
this, &QgsExpressionBuilderWidget::txtSearchEditValues_textChanged );
54 connect( txtSearchEdit, &QgsFilterLineEdit::textChanged,
this, &QgsExpressionBuilderWidget::txtSearchEdit_textChanged );
55 connect( lblPreview, &QLabel::linkActivated,
this, &QgsExpressionBuilderWidget::lblPreview_linkActivated );
56 connect( mValuesListView, &QListView::doubleClicked,
this, &QgsExpressionBuilderWidget::mValuesListView_doubleClicked );
58 mValueGroupBox->hide();
59 mLoadGroupBox->hide();
62 mModel =
new QStandardItemModel();
64 mProxyModel->setDynamicSortFilter(
true );
65 mProxyModel->setSourceModel( mModel );
66 expressionTree->setModel( mProxyModel );
67 expressionTree->setSortingEnabled(
true );
68 expressionTree->sortByColumn( 0, Qt::AscendingOrder );
70 expressionTree->setContextMenuPolicy( Qt::CustomContextMenu );
72 connect( expressionTree, &QWidget::customContextMenuRequested,
this, &QgsExpressionBuilderWidget::showContextMenu );
73 connect( expressionTree->selectionModel(), &QItemSelectionModel::currentChanged,
74 this, &QgsExpressionBuilderWidget::currentChanged );
79 Q_FOREACH ( QPushButton *button, mOperatorsGroupBox->findChildren<QPushButton *>() )
81 connect( button, &QAbstractButton::pressed,
this, &QgsExpressionBuilderWidget::operatorButtonClicked );
84 txtSearchEdit->setPlaceholderText( tr(
"Search" ) );
86 mValuesModel =
new QStringListModel();
87 mProxyValues =
new QSortFilterProxyModel();
88 mProxyValues->setSourceModel( mValuesModel );
89 mValuesListView->setModel( mProxyValues );
90 txtSearchEditValues->setPlaceholderText( tr(
"Search" ) );
93 splitter->restoreState( settings.
value( QStringLiteral(
"Windows/QgsExpressionBuilderWidget/splitter" ) ).toByteArray() );
94 editorSplit->restoreState( settings.
value( QStringLiteral(
"Windows/QgsExpressionBuilderWidget/editorsplitter" ) ).toByteArray() );
95 functionsplit->restoreState( settings.
value( QStringLiteral(
"Windows/QgsExpressionBuilderWidget/functionsplitter" ) ).toByteArray() );
97 txtExpressionString->setFoldingVisible(
false );
113 QModelIndex firstItem = mProxyModel->index( 0, 0, QModelIndex() );
114 expressionTree->setCurrentIndex( firstItem );
116 lblAutoSave->clear();
117 txtExpressionString->setWrapMode( QsciScintilla::WrapWord );
124 settings.
setValue( QStringLiteral(
"Windows/QgsExpressionBuilderWidget/splitter" ), splitter->saveState() );
125 settings.
setValue( QStringLiteral(
"Windows/QgsExpressionBuilderWidget/editorsplitter" ), editorSplit->saveState() );
126 settings.
setValue( QStringLiteral(
"Windows/QgsExpressionBuilderWidget/functionsplitter" ), functionsplit->saveState() );
144 void QgsExpressionBuilderWidget::currentChanged(
const QModelIndex &index,
const QModelIndex & )
146 txtSearchEditValues->clear();
149 QModelIndex idx = mProxyModel->mapToSource( index );
156 const QStringList &values = mFieldValues[item->text()];
157 mValuesModel->setStringList( values );
164 QString help = loadFunctionHelp( item );
165 txtHelpText->setText( help );
168 void QgsExpressionBuilderWidget::btnRun_pressed()
170 if ( !cmbFileNames->currentItem() )
173 QString file = cmbFileNames->currentItem()->text();
175 runPythonCode( txtPython->text() );
178 void QgsExpressionBuilderWidget::runPythonCode(
const QString &code )
182 QString pythontext = code;
185 updateFunctionTree();
192 QDir
myDir( mFunctionsPath );
193 if ( !myDir.exists() )
195 myDir.mkpath( mFunctionsPath );
198 if ( !fileName.endsWith( QLatin1String(
".py" ) ) )
200 fileName.append(
".py" );
203 fileName = mFunctionsPath + QDir::separator() + fileName;
204 QFile myFile( fileName );
205 if ( myFile.open( QIODevice::WriteOnly | QFile::Truncate ) )
207 QTextStream myFileStream( &myFile );
208 myFileStream << txtPython->text() << endl;
215 mFunctionsPath = path;
217 dir.setNameFilters( QStringList() << QStringLiteral(
"*.py" ) );
218 QStringList
files = dir.entryList( QDir::Files );
219 cmbFileNames->clear();
220 Q_FOREACH (
const QString &name, files )
222 QFileInfo info( mFunctionsPath + QDir::separator() + name );
223 if ( info.baseName() == QLatin1String(
"__init__" ) )
continue;
224 QListWidgetItem *item =
new QListWidgetItem(
QgsApplication::getThemeIcon( QStringLiteral(
"console/iconTabEditorConsole.png" ) ), info.baseName() );
225 cmbFileNames->addItem( item );
227 if ( !cmbFileNames->currentItem() )
228 cmbFileNames->setCurrentRow( 0 );
233 QList<QListWidgetItem *> items = cmbFileNames->findItems( fileName, Qt::MatchExactly );
234 if ( !items.isEmpty() )
237 QListWidgetItem *item =
new QListWidgetItem(
QgsApplication::getThemeIcon( QStringLiteral(
"console/iconTabEditorConsole.png" ) ), fileName );
238 cmbFileNames->insertItem( 0, item );
239 cmbFileNames->setCurrentRow( 0 );
243 txtPython->setText( templatetxt );
247 void QgsExpressionBuilderWidget::btnNewFile_pressed()
250 QString text = QInputDialog::getText(
this, tr(
"Enter new file name" ),
251 tr(
"File name:" ), QLineEdit::Normal,
252 QLatin1String(
"" ), &ok );
253 if ( ok && !text.isEmpty() )
259 void QgsExpressionBuilderWidget::cmbFileNames_currentItemChanged( QListWidgetItem *item, QListWidgetItem *lastitem )
263 QString filename = lastitem->text();
266 QString path = mFunctionsPath + QDir::separator() + item->text();
272 if ( !path.endsWith( QLatin1String(
".py" ) ) )
273 path.append(
".py" );
275 txtPython->loadScript( path );
280 txtPython->setText( code );
283 void QgsExpressionBuilderWidget::expressionTree_doubleClicked(
const QModelIndex &index )
285 QModelIndex idx = mProxyModel->mapToSource( index );
296 txtExpressionString->setFocus();
314 QStringList fieldNames;
316 fieldNames.reserve( fields.
count() );
317 for (
int i = 0; i < fields.
count(); ++i )
319 QString fieldName = fields.
at( i ).
name();
320 fieldNames << fieldName;
329 for (
auto it = fieldValues.constBegin(); it != fieldValues.constEnd(); ++it )
334 mFieldValues = fieldValues;
337 void QgsExpressionBuilderWidget::fillFieldValues(
const QString &fieldName,
int countLimit )
348 if ( fieldIndex < 0 )
351 QStringList strValues;
352 QList<QVariant> values = mLayer->
uniqueValues( fieldIndex, countLimit ).toList();
353 std::sort( values.begin(), values.end() );
354 Q_FOREACH (
const QVariant &value, values )
357 if ( value.isNull() )
358 strValue = QStringLiteral(
"NULL" );
359 else if ( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
360 strValue = value.toString();
362 strValue =
'\'' + value.toString().replace(
'\'', QLatin1String(
"''" ) ) +
'\'';
363 strValues.append( strValue );
365 mValuesModel->setStringList( strValues );
366 mFieldValues[fieldName] = strValues;
370 const QString &label,
372 const QString &helpText,
376 item->setData( label, Qt::UserRole );
380 if ( mExpressionGroups.contains( group ) )
383 groupNode->appendRow( item );
389 newgroupNode->setData( group, Qt::UserRole );
392 newgroupNode->appendRow( item );
393 newgroupNode->setBackground( QBrush( QColor( 238, 238, 238 ) ) );
394 mModel->appendRow( newgroupNode );
395 mExpressionGroups.insert( group, newgroupNode );
398 if ( highlightedItem )
402 topLevelItem->setData( label, Qt::UserRole );
404 QFont font = topLevelItem->font();
405 font.setBold(
true );
406 topLevelItem->setFont( font );
407 mModel->appendRow( topLevelItem );
414 return mExpressionValid;
420 QString location = QStringLiteral(
"/expressions/recent/%1" ).arg( collection );
421 QStringList expressions = settings.
value( location ).toStringList();
426 while ( expressions.count() > 20 )
428 expressions.pop_back();
431 settings.
setValue( location, expressions );
437 mRecentKey = collection;
438 QString name = tr(
"Recent (%1)" ).arg( collection );
439 if ( mExpressionGroups.contains( name ) )
442 node->removeRows( 0, node->rowCount() );
446 QString location = QStringLiteral(
"/expressions/recent/%1" ).arg( collection );
447 QStringList expressions = settings.
value( location ).toStringList();
449 Q_FOREACH (
const QString &expression, expressions )
456 void QgsExpressionBuilderWidget::loadLayers()
461 QMap<QString, QgsMapLayer *> layers = mProject->mapLayers();
462 QMap<QString, QgsMapLayer *>::const_iterator layerIt = layers.constBegin();
463 for ( ; layerIt != layers.constEnd(); ++layerIt )
465 registerItemForAllGroups( QStringList() << tr(
"Map Layers" ), layerIt.value()->name(), QStringLiteral(
"'%1'" ).arg( layerIt.key() ), formatLayerHelp( layerIt.value() ) );
469 void QgsExpressionBuilderWidget::loadRelations()
474 QMap<QString, QgsRelation> relations = mProject->relationManager()->relations();
475 QMap<QString, QgsRelation>::const_iterator relIt = relations.constBegin();
476 for ( ; relIt != relations.constEnd(); ++relIt )
478 registerItemForAllGroups( QStringList() << tr(
"Relations" ), relIt->name(), QStringLiteral(
"'%1'" ).arg( relIt->id() ), formatRelationHelp( relIt.value() ) );
482 void QgsExpressionBuilderWidget::updateFunctionTree()
485 mExpressionGroups.clear();
487 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"+" ), QStringLiteral(
" + " ) );
488 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"-" ), QStringLiteral(
" - " ) );
489 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"*" ), QStringLiteral(
" * " ) );
490 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"/" ), QStringLiteral(
" / " ) );
491 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"%" ), QStringLiteral(
" % " ) );
492 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"^" ), QStringLiteral(
" ^ " ) );
493 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"=" ), QStringLiteral(
" = " ) );
494 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"~" ), QStringLiteral(
" ~ " ) );
495 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
">" ), QStringLiteral(
" > " ) );
496 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"<" ), QStringLiteral(
" < " ) );
497 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"<>" ), QStringLiteral(
" <> " ) );
498 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"<=" ), QStringLiteral(
" <= " ) );
499 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
">=" ), QStringLiteral(
" >= " ) );
500 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"||" ), QStringLiteral(
" || " ) );
501 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IN" ), QStringLiteral(
" IN " ) );
502 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"LIKE" ), QStringLiteral(
" LIKE " ) );
503 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"ILIKE" ), QStringLiteral(
" ILIKE " ) );
504 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"IS" ), QStringLiteral(
" IS " ) );
505 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"OR" ), QStringLiteral(
" OR " ) );
506 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"AND" ), QStringLiteral(
" AND " ) );
507 registerItem( QStringLiteral(
"Operators" ), QStringLiteral(
"NOT" ), QStringLiteral(
" NOT " ) );
509 QString casestring = QStringLiteral(
"CASE WHEN condition THEN result END" );
510 registerItem( QStringLiteral(
"Conditionals" ), QStringLiteral(
"CASE" ), casestring );
512 registerItem( QStringLiteral(
"Fields and Values" ), QStringLiteral(
"NULL" ), QStringLiteral(
"NULL" ) );
515 int count = QgsExpression::functionCount();
516 for (
int i = 0; i < count; i++ )
518 QgsExpressionFunction *func = QgsExpression::Functions()[i];
519 QString name = func->name();
520 if ( name.startsWith(
'_' ) )
522 if ( func->isDeprecated() )
524 if ( func->isContextual() )
530 if ( func->params() != 0 )
532 else if ( !name.startsWith(
'$' ) )
533 name += QLatin1String(
"()" );
534 registerItemForAllGroups( func->groups(), func->name(),
' ' + name +
' ', func->helpText() );
543 loadExpressionContext();
553 return txtExpressionString->text();
558 txtExpressionString->setText( expression );
563 mExpressionContext = context;
564 updateFunctionTree();
569 void QgsExpressionBuilderWidget::txtExpressionString_textChanged()
575 if ( text.isEmpty() )
578 lblPreview->setStyleSheet( QLatin1String(
"" ) );
579 txtExpressionString->setToolTip( QLatin1String(
"" ) );
580 lblPreview->setToolTip( QLatin1String(
"" ) );
582 setParserError(
true );
583 setEvalError(
true );
587 QgsExpression exp( text );
592 exp.setGeomCalculator( &mDa );
603 QVariant value = exp.evaluate( &mExpressionContext );
604 if ( !exp.hasEvalError() )
606 lblPreview->setText( QgsExpression::formatPreviewString( value ) );
609 if ( exp.hasParserError() || exp.hasEvalError() )
611 QString tooltip = QStringLiteral(
"<b>%1:</b><br>%2" ).arg( tr(
"Parser Error" ), exp.parserErrorString() );
612 if ( exp.hasEvalError() )
613 tooltip += QStringLiteral(
"<br><br><b>%1:</b><br>%2" ).arg( tr(
"Eval Error" ), exp.evalErrorString() );
615 lblPreview->setText( tr(
"Expression is invalid <a href=""more"">(more info)</a>" ) );
616 lblPreview->setStyleSheet( QStringLiteral(
"color: rgba(255, 6, 10, 255);" ) );
617 txtExpressionString->setToolTip( tooltip );
618 lblPreview->setToolTip( tooltip );
620 setParserError( exp.hasParserError() );
621 setEvalError( exp.hasEvalError() );
626 lblPreview->setStyleSheet( QString() );
627 txtExpressionString->setToolTip( QString() );
628 lblPreview->setToolTip( QString() );
630 setParserError(
false );
631 setEvalError(
false );
635 void QgsExpressionBuilderWidget::loadExpressionContext()
638 Q_FOREACH (
const QString &variable, variableNames )
640 registerItem( QStringLiteral(
"Variables" ), variable,
" @" + variable +
' ',
641 QgsExpression::formatVariableHelp( mExpressionContext.
description( variable ),
true, mExpressionContext.
variable( variable ) ),
647 QStringList contextFunctions = mExpressionContext.
functionNames();
648 Q_FOREACH (
const QString &functionName, contextFunctions )
650 QgsExpressionFunction *func = mExpressionContext.
function( functionName );
651 QString name = func->name();
652 if ( name.startsWith(
'_' ) )
654 if ( func->params() != 0 )
656 registerItemForAllGroups( func->groups(), func->name(),
' ' + name +
' ', func->helpText() );
660 void QgsExpressionBuilderWidget::registerItemForAllGroups(
const QStringList &groups,
const QString &label,
const QString &
expressionText,
const QString &helpText,
QgsExpressionItem::ItemType type,
bool highlightedItem,
int sortOrder )
662 Q_FOREACH (
const QString &group, groups )
668 QString QgsExpressionBuilderWidget::formatRelationHelp(
const QgsRelation &relation )
const 670 QString text = QStringLiteral(
"<p>%1</p>" ).arg( tr(
"Inserts the relation ID for the relation named '%1'." ).arg( relation.
name() ) );
671 text.append( QStringLiteral(
"<p>%1</p>" ).arg( tr(
"Current value: '%1'" ).arg( relation.
id() ) ) );
675 QString QgsExpressionBuilderWidget::formatLayerHelp(
const QgsMapLayer *layer )
const 677 QString text = QStringLiteral(
"<p>%1</p>" ).arg( tr(
"Inserts the layer ID for the layer named '%1'." ).arg( layer->
name() ) );
678 text.append( QStringLiteral(
"<p>%1</p>" ).arg( tr(
"Current value: '%1'" ).arg( layer->
id() ) ) );
687 void QgsExpressionBuilderWidget::setParserError(
bool parserError )
689 if ( parserError == mParserError )
701 void QgsExpressionBuilderWidget::setEvalError(
bool evalError )
703 if ( evalError == mEvalError )
723 updateFunctionTree();
728 QWidget::showEvent( e );
729 txtExpressionString->setFocus();
732 void QgsExpressionBuilderWidget::txtSearchEdit_textChanged()
734 mProxyModel->setFilterWildcard( txtSearchEdit->text() );
735 if ( txtSearchEdit->text().isEmpty() )
737 expressionTree->collapseAll();
741 expressionTree->expandAll();
742 QModelIndex index = mProxyModel->index( 0, 0 );
743 if ( mProxyModel->hasChildren( index ) )
745 QModelIndex child = mProxyModel->index( 0, 0, index );
746 expressionTree->selectionModel()->setCurrentIndex( child, QItemSelectionModel::ClearAndSelect );
751 void QgsExpressionBuilderWidget::txtSearchEditValues_textChanged()
753 mProxyValues->setFilterCaseSensitivity( Qt::CaseInsensitive );
754 mProxyValues->setFilterWildcard( txtSearchEditValues->text() );
757 void QgsExpressionBuilderWidget::lblPreview_linkActivated(
const QString &link )
761 mv->setWindowTitle( tr(
"More Info on Expression Error" ) );
766 void QgsExpressionBuilderWidget::mValuesListView_doubleClicked(
const QModelIndex &index )
769 txtExpressionString->insertText(
' ' + index.data( Qt::DisplayRole ).toString() +
' ' );
770 txtExpressionString->setFocus();
773 void QgsExpressionBuilderWidget::operatorButtonClicked()
775 QPushButton *button =
dynamic_cast<QPushButton *
>( sender() );
778 txtExpressionString->insertText(
' ' + button->text() +
' ' );
779 txtExpressionString->setFocus();
782 void QgsExpressionBuilderWidget::showContextMenu( QPoint pt )
784 QModelIndex idx = expressionTree->indexAt( pt );
785 idx = mProxyModel->mapToSource( idx );
792 QMenu *menu =
new QMenu(
this );
793 menu->addAction( tr(
"Load top 10 unique values" ),
this, SLOT(
loadSampleValues() ) );
794 menu->addAction( tr(
"Load all unique values" ),
this, SLOT(
loadAllValues() ) );
795 menu->popup( expressionTree->mapToGlobal( pt ) );
801 QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
805 if ( !mLayer || !item )
808 mValueGroupBox->show();
809 fillFieldValues( item->text(), 10 );
814 QModelIndex idx = mProxyModel->mapToSource( expressionTree->currentIndex() );
818 if ( !mLayer || !item )
821 mValueGroupBox->show();
822 fillFieldValues( item->text(), -1 );
825 void QgsExpressionBuilderWidget::txtPython_textChanged()
827 lblAutoSave->setText( tr(
"Saving…" ) );
837 if ( tabWidget->currentIndex() != 1 )
840 QListWidgetItem *item = cmbFileNames->currentItem();
844 QString file = item->text();
846 lblAutoSave->setText( QStringLiteral(
"Saved" ) );
847 QGraphicsOpacityEffect *effect =
new QGraphicsOpacityEffect();
848 lblAutoSave->setGraphicsEffect( effect );
849 QPropertyAnimation *anim =
new QPropertyAnimation( effect,
"opacity" );
850 anim->setDuration( 2000 );
851 anim->setStartValue( 1.0 );
852 anim->setEndValue( 0.0 );
853 anim->setEasingCurve( QEasingCurve::OutQuad );
854 anim->start( QAbstractAnimation::DeleteWhenStopped );
857 void QgsExpressionBuilderWidget::setExpressionState(
bool state )
859 mExpressionValid = state;
862 QString QgsExpressionBuilderWidget::helpStylesheet()
const 868 style +=
" .functionname {color: #0a6099; font-weight: bold;} " 869 " .argument {font-family: monospace; color: #bf0c0c; font-style: italic; } " 870 " td.argument { padding-right: 10px; }";
875 QString QgsExpressionBuilderWidget::loadFunctionHelp(
QgsExpressionItem *expressionItem )
877 if ( !expressionItem )
878 return QLatin1String(
"" );
880 QString helpContents = expressionItem->
getHelpText();
883 if ( helpContents.isEmpty() )
885 QString name = expressionItem->data( Qt::UserRole ).toString();
888 helpContents = QgsExpression::helpText( QStringLiteral(
"Field" ) );
890 helpContents = QgsExpression::helpText( name );
893 return "<head><style>" + helpStylesheet() +
"</style></head><body>" + helpContents +
"</body>";
902 setFilterCaseSensitivity( Qt::CaseInsensitive );
907 QModelIndex index = sourceModel()->index( source_row, 0, source_parent );
910 int count = sourceModel()->rowCount( index );
911 bool matchchild =
false;
912 for (
int i = 0; i < count; ++i )
914 if ( filterAcceptsRow( i, index ) )
927 return QSortFilterProxyModel::filterAcceptsRow( source_row, source_parent );
934 if ( leftSort != rightSort )
935 return leftSort < rightSort;
937 QString leftString = sourceModel()->data( left, Qt::DisplayRole ).toString();
938 QString rightString = sourceModel()->data( right, Qt::DisplayRole ).toString();
941 if ( leftString.startsWith(
'$' ) )
942 leftString = leftString.mid( 1 );
943 if ( rightString.startsWith(
'$' ) )
944 rightString = rightString.mid( 1 );
946 return QString::localeAwareCompare( leftString, rightString ) < 0;
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
bool isValid() const
Returns the validity of this feature.
Base class for all map layer types.
QStringList filteredVariableNames() const
Returns a filtered list of variables names set by all scopes in the context.
This class is a composition of two QSettings instances:
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Container of fields for a vector layer.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QSet< QVariant > uniqueValues(int fieldIndex, int limit=-1) const override
Calculates a list of unique values contained within an attribute in the layer.
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
static QString reportStyleSheet()
get a standard css style sheet for reports.
QgsExpressionItemSearchProxy()
int count() const
Return number of items.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QString description(const QString &name) const
Returns a translated description string for the variable with specified name.
QgsField at(int i) const
Get field at particular index (must be in range 0..N-1)
void setMessageAsHtml(const QString &msg)
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Search proxy used to filter the QgsExpressionBuilderWidget tree.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
QgsFields fields() const override
Returns the list of fields of this layer.
bool isHighlightedVariable(const QString &name) const
Returns true if the specified variable name is intended to be highlighted to the user.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
Reads and writes project states.
static const int ITEM_TYPE_ROLE
Item type role.
Encapsulate a field in an attribute table or data source.
static bool eval(const QString &command, QString &result)
Eval a Python statement.
QgsExpressionItem::ItemType getItemType() const
Get the type of expression item, e.g., header, field, ExpressionNode.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override
Query the layer for features specified in request.
static const int CUSTOM_SORT_ROLE
Custom sort order role.
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
An expression item that can be used in the QgsExpressionBuilderWidget tree.
QStringList functionNames() const
Retrieves a list of function names contained in the context.
static bool run(const QString &command, const QString &messageOnError=QString())
Execute a Python statement.
QString getExpressionText() const
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
A generic message view for displaying QGIS messages.
bool isEmpty() const
Check whether the container is empty.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
QString getHelpText() const
Get the help text that is associated with this expression item.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
Represents a vector layer which manages a vector based data sets.
static bool isValid()
Returns true if the runner has an instance (and thus is able to run commands)
QgsExpressionFunction * function(const QString &name) const
Fetches a matching function from the context.