16 #ifndef QGSVARIABLEEDITORWIDGET_H
17 #define QGSVARIABLEEDITORWIDGET_H
21 #include <QTreeWidget>
22 #include <QItemDelegate>
30 class QgsVariableEditorTree;
31 class VariableEditorDelegate;
46 Q_PROPERTY( QString settingGroup READ settingGroup WRITE setSettingGroup )
81 void setEditableScopeIndex(
int scopeIndex );
113 QVariantMap variablesInActiveScope()
const;
122 void reloadContext();
133 void showEvent( QShowEvent *event )
override;
137 std::unique_ptr<QgsExpressionContext> mContext;
138 int mEditableScopeIndex = -1;
139 QgsVariableEditorTree *mTreeWidget =
nullptr;
140 QPushButton *mAddButton =
nullptr;
141 QPushButton *mRemoveButton =
nullptr;
142 QString mSettingGroup;
145 QString saveKey()
const;
149 void mAddButton_clicked();
150 void mRemoveButton_clicked();
151 void selectionChanged();
164 class QgsVariableEditorTree :
public QTreeWidget
172 ContextIndex = Qt::UserRole,
176 explicit QgsVariableEditorTree( QWidget *parent =
nullptr );
178 QTreeWidgetItem *indexToItem(
const QModelIndex &index )
const {
return itemFromIndex( index ); }
179 QModelIndex itemToIndex( QTreeWidgetItem *item )
const {
return indexFromItem( item ); }
180 QString variableNameFromItem( QTreeWidgetItem *item )
const {
return item ? item->text( 0 ) : QString(); }
181 QString variableNameFromIndex(
const QModelIndex &index )
const {
return variableNameFromItem( itemFromIndex( index ) ); }
184 void setEditableScopeIndex(
int scopeIndex ) { mEditableScopeIndex = scopeIndex; }
188 void removeItem( QTreeWidgetItem *item );
189 void renameItem( QTreeWidgetItem *item,
const QString &name );
198 void keyPressEvent( QKeyEvent *event )
override;
199 void mousePressEvent( QMouseEvent *event )
override;
200 void drawRow( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
201 QColor rowColor(
int index )
const;
202 void toggleContextExpanded( QTreeWidgetItem *item );
203 void editNext(
const QModelIndex &index );
205 QModelIndex moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers )
override;
211 VariableEditorDelegate *mEditorDelegate =
nullptr;
212 int mEditableScopeIndex = -1;
214 QMap< QPair<int, QString>, QTreeWidgetItem * > mVariableToItem;
215 QMap< int, QTreeWidgetItem * > mScopeToItem;
222 class VariableEditorDelegate :
public QItemDelegate
227 VariableEditorDelegate( QObject *parent =
nullptr, QgsVariableEditorTree *tree =
nullptr )
228 : QItemDelegate( parent )
229 , mParentTree( tree )
232 QWidget *createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
233 const QModelIndex &index )
const override;
234 void updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
235 const QModelIndex &index )
const override;
236 QSize sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
237 void setModelData( QWidget *widget, QAbstractItemModel *model,
238 const QModelIndex &index )
const override;
239 void setEditorData( QWidget *,
const QModelIndex & )
const override {}
242 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...