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 );
218 void registerItem(
const QString &group,
const QString &label,
const QString &expressionText,
219 const QString &helpText = QString(),
221 bool highlightedItem =
false,
int sortOrder = 1 );
223 bool isExpressionValid();
229 void saveToRecent(
const QString &collection =
"generic" );
235 void loadRecent(
const QString &collection =
"generic" );
240 void newFunctionFile(
const QString &fileName =
"scratch" );
245 void saveFunctionFile( QString fileName );
250 void loadCodeFromFile( QString path );
255 void loadFunctionCode(
const QString &code );
260 void updateFunctionFileList(
const QString &path );
267 QStandardItemModel *model();
290 bool evalError()
const;
298 bool parserError()
const;
305 void loadSampleValues();
310 void loadAllValues();
325 void indicatorClicked(
int line,
int index, Qt::KeyboardModifiers state );
326 void showContextMenu( QPoint );
327 void setExpressionState(
bool state );
328 void currentChanged(
const QModelIndex &index,
const QModelIndex & );
329 void operatorButtonClicked();
330 void btnRun_pressed();
331 void btnNewFile_pressed();
332 void cmbFileNames_currentItemChanged( QListWidgetItem *item, QListWidgetItem *lastitem );
333 void expressionTree_doubleClicked(
const QModelIndex &index );
334 void txtExpressionString_textChanged();
335 void txtSearchEdit_textChanged();
336 void txtSearchEditValues_textChanged();
337 void lblPreview_linkActivated(
const QString &link );
338 void mValuesListView_doubleClicked(
const QModelIndex &index );
339 void txtPython_textChanged();
349 void expressionParsed(
bool isValid );
357 void evalErrorChanged();
365 void parserErrorChanged();
368 void showEvent( QShowEvent *e )
override;
371 int FUNCTION_MARKER_ID = 25;
372 void createErrorMarkers( QList<QgsExpression::ParserError> errors );
374 void clearFunctionMarkers();
376 void runPythonCode(
const QString &code );
377 void updateFunctionTree();
378 void fillFieldValues(
const QString &fieldName,
int countLimit );
381 QString helpStylesheet()
const;
383 void loadExpressionContext();
386 void loadRelations();
401 void registerItemForAllGroups(
const QStringList &groups,
const QString &label,
const QString &expressionText,
402 const QString &helpText = QString(),
404 bool highlightedItem =
false,
int sortOrder = 1 );
409 QString formatRelationHelp(
const QgsRelation &relation )
const;
414 QString formatLayerHelp(
const QgsMapLayer *layer )
const;
422 void setEvalError(
bool evalError );
430 void setParserError(
bool parserError );
432 bool mAutoSave =
true;
433 QString mFunctionsPath;
435 QStandardItemModel *mModel =
nullptr;
436 QStringListModel *mValuesModel =
nullptr;
437 QSortFilterProxyModel *mProxyValues =
nullptr;
439 QMap<QString, QgsExpressionItem *> mExpressionGroups;
441 bool mExpressionValid =
false;
444 QMap<QString, QStringList> mFieldValues;
446 QPointer< QgsProject > mProject;
447 bool mEvalError =
true;
448 bool mParserError =
true;
453 #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.