16 #ifndef QGSEXPRESSIONBUILDER_H 17 #define QGSEXPRESSIONBUILDER_H 21 #include "ui_qgsexpressionbuilder.h" 26 #include "QStandardItemModel" 27 #include "QStandardItem" 28 #include "QSortFilterProxyModel" 29 #include "QStringListModel" 51 const QString &expressionText,
52 const QString &helpText,
54 : QStandardItem( label )
56 mExpressionText = expressionText;
59 setData( itemType, ITEM_TYPE_ROLE );
63 const QString &expressionText,
65 : QStandardItem( label )
67 mExpressionText = expressionText;
69 setData( itemType, ITEM_TYPE_ROLE );
86 void setHelpText(
const QString &helpText ) { mHelpText = helpText; }
96 static const int CUSTOM_SORT_ROLE = Qt::UserRole + 1;
98 static const int ITEM_TYPE_ROLE = Qt::UserRole + 2;
101 QString mExpressionText;
120 bool filterAcceptsRow(
int source_row,
const QModelIndex &source_parent )
const override;
124 bool lessThan(
const QModelIndex &left,
const QModelIndex &right )
const override;
154 void loadFieldNames();
156 void loadFieldNames(
const QgsFields &fields );
163 void loadFieldsAndValues(
const QMap<QString, QStringList> &fieldValues );
171 QString expressionText();
174 void setExpressionText(
const QString &expression );
181 QString expectedOutputFormat();
189 void setExpectedOutputFormat(
const QString &expected );
219 void registerItem(
const QString &group,
const QString &label,
const QString &expressionText,
220 const QString &helpText = QString(),
222 bool highlightedItem =
false,
int sortOrder = 1,
223 QIcon icon = QIcon() );
225 bool isExpressionValid();
231 void saveToRecent(
const QString &collection =
"generic" );
237 void loadRecent(
const QString &collection =
"generic" );
242 void newFunctionFile(
const QString &fileName =
"scratch" );
247 void saveFunctionFile( QString fileName );
252 void loadCodeFromFile( QString path );
257 void loadFunctionCode(
const QString &code );
262 void updateFunctionFileList(
const QString &path );
269 QStandardItemModel *model();
292 bool evalError()
const;
300 bool parserError()
const;
307 void loadSampleValues();
312 void loadAllValues();
327 void indicatorClicked(
int line,
int index, Qt::KeyboardModifiers state );
328 void showContextMenu( QPoint );
329 void setExpressionState(
bool state );
330 void currentChanged(
const QModelIndex &index,
const QModelIndex & );
331 void operatorButtonClicked();
332 void btnRun_pressed();
333 void btnNewFile_pressed();
334 void cmbFileNames_currentItemChanged( QListWidgetItem *item, QListWidgetItem *lastitem );
335 void expressionTree_doubleClicked(
const QModelIndex &index );
336 void txtExpressionString_textChanged();
337 void txtSearchEdit_textChanged();
338 void txtSearchEditValues_textChanged();
339 void lblPreview_linkActivated(
const QString &link );
340 void mValuesListView_doubleClicked(
const QModelIndex &index );
341 void txtPython_textChanged();
351 void expressionParsed(
bool isValid );
359 void evalErrorChanged();
367 void parserErrorChanged();
370 void showEvent( QShowEvent *e )
override;
373 int FUNCTION_MARKER_ID = 25;
374 void createErrorMarkers( QList<QgsExpression::ParserError> errors );
376 void clearFunctionMarkers();
378 void runPythonCode(
const QString &code );
379 void updateFunctionTree();
380 void fillFieldValues(
const QString &fieldName,
int countLimit );
383 QString helpStylesheet()
const;
385 void loadExpressionContext();
388 void loadRelations();
403 void registerItemForAllGroups(
const QStringList &groups,
const QString &label,
const QString &expressionText,
404 const QString &helpText = QString(),
406 bool highlightedItem =
false,
int sortOrder = 1 );
411 QString formatRelationHelp(
const QgsRelation &relation )
const;
416 QString formatLayerHelp(
const QgsMapLayer *layer )
const;
424 void setEvalError(
bool evalError );
432 void setParserError(
bool parserError );
434 bool mAutoSave =
true;
435 QString mFunctionsPath;
437 QStandardItemModel *mModel =
nullptr;
438 QStringListModel *mValuesModel =
nullptr;
439 QSortFilterProxyModel *mProxyValues =
nullptr;
441 QMap<QString, QgsExpressionItem *> mExpressionGroups;
443 bool mExpressionValid =
false;
446 QMap<QString, QStringList> mFieldValues;
448 QPointer< QgsProject > mProject;
449 bool mEvalError =
true;
450 bool mParserError =
true;
455 #endif // QGSEXPRESSIONBUILDER_H Base class for all map layer types.
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::ItemType getItemType() const
Gets the type of expression item, e.g., header, field, ExpressionNode.
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.
QString getExpressionText() const
QString getHelpText() const
Gets the help text that is associated with this expression item.
Represents a vector layer which manages a vector based data sets.
void setHelpText(const QString &helpText)
Set the help text for the current item.