16#ifndef QGSVARIABLEEDITORWIDGET_H
17#define QGSVARIABLEEDITORWIDGET_H
22#include <QItemDelegate>
30class QgsVariableEditorTree;
31class VariableEditorDelegate;
45 Q_PROPERTY( QString settingGroup READ settingGroup WRITE setSettingGroup )
79 void setEditableScopeIndex(
int scopeIndex );
111 QVariantMap variablesInActiveScope()
const;
120 void reloadContext();
130 void showEvent( QShowEvent *event )
override;
133 std::unique_ptr<QgsExpressionContext> mContext;
134 int mEditableScopeIndex = -1;
135 QgsVariableEditorTree *mTreeWidget =
nullptr;
136 QPushButton *mAddButton =
nullptr;
137 QPushButton *mRemoveButton =
nullptr;
138 QString mSettingGroup;
141 QString saveKey()
const;
145 void mAddButton_clicked();
146 void mRemoveButton_clicked();
147 void selectionChanged();
159class QgsVariableEditorTree :
public QTreeWidget
166 ContextIndex = Qt::UserRole,
170 explicit QgsVariableEditorTree( QWidget *parent =
nullptr );
172 QTreeWidgetItem *indexToItem(
const QModelIndex &index )
const {
return itemFromIndex( index ); }
173 QModelIndex itemToIndex( QTreeWidgetItem *item )
const {
return indexFromItem( item ); }
174 QString variableNameFromItem( QTreeWidgetItem *item )
const {
return item ? item->text( 0 ) : QString(); }
175 QString variableNameFromIndex(
const QModelIndex &index )
const {
return variableNameFromItem( itemFromIndex( index ) ); }
178 void setEditableScopeIndex(
int scopeIndex ) { mEditableScopeIndex = scopeIndex; }
182 void removeItem( QTreeWidgetItem *item );
183 void renameItem( QTreeWidgetItem *item,
const QString &name );
192 void keyPressEvent( QKeyEvent *event )
override;
193 void mousePressEvent( QMouseEvent *event )
override;
194 void drawRow( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
195 QColor rowColor(
int index )
const;
196 void toggleContextExpanded( QTreeWidgetItem *item );
197 void editNext(
const QModelIndex &index );
199 QModelIndex moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers )
override;
204 VariableEditorDelegate *mEditorDelegate =
nullptr;
205 int mEditableScopeIndex = -1;
207 QMap<QPair<int, QString>, QTreeWidgetItem *> mVariableToItem;
208 QMap<int, QTreeWidgetItem *> mScopeToItem;
215class VariableEditorDelegate :
public QItemDelegate
220 VariableEditorDelegate( QObject *parent =
nullptr, QgsVariableEditorTree *tree =
nullptr )
221 : QItemDelegate( parent )
222 , mParentTree( tree )
225 QWidget *createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
226 void updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
227 QSize sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
228 void setModelData( QWidget *widget, QAbstractItemModel *model,
const QModelIndex &index )
const override;
229 void setEditorData( QWidget *,
const QModelIndex & )
const override {}
232 QgsVariableEditorTree *mParentTree =
nullptr;
Single scope for storing variables and functions for use within a QgsExpressionContext.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...