16 #ifndef QGSEXPRESSIONBUILDER_H 17 #define QGSEXPRESSIONBUILDER_H 21 #include "ui_qgsexpressionbuilder.h" 25 #include "QStandardItemModel" 26 #include "QStandardItem" 27 #include "QSortFilterProxyModel" 28 #include "QStringListModel" 50 const QString &expressionText,
51 const QString &helpText,
53 : QStandardItem( label )
55 mExpressionText = expressionText;
58 setData( itemType, ITEM_TYPE_ROLE );
62 const QString &expressionText,
64 : QStandardItem( label )
66 mExpressionText = expressionText;
68 setData( itemType, ITEM_TYPE_ROLE );
85 void setHelpText(
const QString &helpText ) { mHelpText = helpText; }
95 static const int CUSTOM_SORT_ROLE = Qt::UserRole + 1;
97 static const int ITEM_TYPE_ROLE = Qt::UserRole + 2;
100 QString mExpressionText;
119 bool filterAcceptsRow(
int source_row,
const QModelIndex &source_parent )
const override;
123 bool lessThan(
const QModelIndex &left,
const QModelIndex &right )
const override;
153 void loadFieldNames();
155 void loadFieldNames(
const QgsFields &fields );
162 void loadFieldsAndValues(
const QMap<QString, QStringList> &fieldValues );
170 QString expressionText();
173 void setExpressionText(
const QString &expression );
180 QString expectedOutputFormat();
188 void setExpectedOutputFormat(
const QString &expected );
218 void registerItem(
const QString &group,
const QString &label,
const QString &expressionText,
219 const QString &helpText = QString(),
221 bool highlightedItem =
false,
int sortOrder = 1,
222 QIcon icon = QIcon() );
224 bool isExpressionValid();
230 void saveToRecent(
const QString &collection =
"generic" );
236 void loadRecent(
const QString &collection =
"generic" );
241 void newFunctionFile(
const QString &fileName =
"scratch" );
246 void saveFunctionFile( QString fileName );
251 void loadCodeFromFile( QString path );
256 void loadFunctionCode(
const QString &code );
261 void updateFunctionFileList(
const QString &path );
268 QStandardItemModel *model();
291 bool evalError()
const;
299 bool parserError()
const;
306 void loadSampleValues();
311 void loadAllValues();
326 void indicatorClicked(
int line,
int index, Qt::KeyboardModifiers state );
327 void showContextMenu( QPoint );
328 void setExpressionState(
bool state );
329 void currentChanged(
const QModelIndex &index,
const QModelIndex & );
330 void operatorButtonClicked();
331 void btnRun_pressed();
332 void btnNewFile_pressed();
333 void cmbFileNames_currentItemChanged( QListWidgetItem *item, QListWidgetItem *lastitem );
334 void expressionTree_doubleClicked(
const QModelIndex &index );
335 void txtExpressionString_textChanged();
336 void txtSearchEdit_textChanged();
337 void txtSearchEditValues_textChanged();
338 void lblPreview_linkActivated(
const QString &link );
339 void mValuesListView_doubleClicked(
const QModelIndex &index );
340 void txtPython_textChanged();
350 void expressionParsed(
bool isValid );
358 void evalErrorChanged();
366 void parserErrorChanged();
369 void showEvent( QShowEvent *e )
override;
372 int FUNCTION_MARKER_ID = 25;
373 void createErrorMarkers( QList<QgsExpression::ParserError> errors );
375 void clearFunctionMarkers();
377 void runPythonCode(
const QString &code );
378 void updateFunctionTree();
379 void fillFieldValues(
const QString &fieldName,
int countLimit );
382 QString helpStylesheet()
const;
384 void loadExpressionContext();
387 void loadRelations();
402 void registerItemForAllGroups(
const QStringList &groups,
const QString &label,
const QString &expressionText,
403 const QString &helpText = QString(),
405 bool highlightedItem =
false,
int sortOrder = 1 );
410 QString formatRelationHelp(
const QgsRelation &relation )
const;
415 QString formatLayerHelp(
const QgsMapLayer *layer )
const;
423 void setEvalError(
bool evalError );
431 void setParserError(
bool parserError );
433 bool mAutoSave =
true;
434 QString mFunctionsPath;
436 QStandardItemModel *mModel =
nullptr;
437 QStringListModel *mValuesModel =
nullptr;
438 QSortFilterProxyModel *mProxyValues =
nullptr;
440 QMap<QString, QgsExpressionItem *> mExpressionGroups;
442 bool mExpressionValid =
false;
445 QMap<QString, QStringList> mFieldValues;
447 QPointer< QgsProject > mProject;
448 bool mEvalError =
true;
449 bool mParserError =
true;
454 #endif // QGSEXPRESSIONBUILDER_H Base class for all map layer types.
QString getExpressionText() const
QString getHelpText() const
Gets the help text that is associated with this expression item.
QgsExpressionItem(const QString &label, const QString &expressionText, const QString &helpText, QgsExpressionItem::ItemType itemType=ExpressionNode)
Container of fields for a vector layer.
Search proxy used to filter the QgsExpressionBuilderWidget tree.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Reads and writes project states.
Abstract base class for all nodes that can appear in an expression.
QgsExpressionItem(const QString &label, const QString &expressionText, QgsExpressionItem::ItemType itemType=ExpressionNode)
A general purpose distance and area calculator, capable of performing ellipsoid based calculations...
A abstract base class for defining QgsExpression functions.
An expression item that can be used in the QgsExpressionBuilderWidget tree.
Represents a vector layer which manages a vector based data sets.
QgsExpressionItem::ItemType getItemType() const
Gets the type of expression item, e.g., header, field, ExpressionNode.
void setHelpText(const QString &helpText)
Set the help text for the current item.