16#ifndef QGSVARIABLEEDITORWIDGET_H
17#define QGSVARIABLEEDITORWIDGET_H
22#include <QItemDelegate>
30class QgsVariableEditorTree;
31class VariableEditorDelegate;
45 Q_PROPERTY( QString settingGroup READ settingGroup WRITE setSettingGroup )
80 void setEditableScopeIndex(
int scopeIndex );
112 QVariantMap variablesInActiveScope()
const;
121 void reloadContext();
132 void showEvent( QShowEvent *event )
override;
136 std::unique_ptr<QgsExpressionContext> mContext;
137 int mEditableScopeIndex = -1;
138 QgsVariableEditorTree *mTreeWidget =
nullptr;
139 QPushButton *mAddButton =
nullptr;
140 QPushButton *mRemoveButton =
nullptr;
141 QString mSettingGroup;
144 QString saveKey()
const;
148 void mAddButton_clicked();
149 void mRemoveButton_clicked();
150 void selectionChanged();
163class QgsVariableEditorTree :
public QTreeWidget
171 ContextIndex = Qt::UserRole,
175 explicit QgsVariableEditorTree( QWidget *parent =
nullptr );
177 QTreeWidgetItem *indexToItem(
const QModelIndex &index )
const {
return itemFromIndex( index ); }
178 QModelIndex itemToIndex( QTreeWidgetItem *item )
const {
return indexFromItem( item ); }
179 QString variableNameFromItem( QTreeWidgetItem *item )
const {
return item ? item->text( 0 ) : QString(); }
180 QString variableNameFromIndex(
const QModelIndex &index )
const {
return variableNameFromItem( itemFromIndex( index ) ); }
183 void setEditableScopeIndex(
int scopeIndex ) { mEditableScopeIndex = scopeIndex; }
187 void removeItem( QTreeWidgetItem *item );
188 void renameItem( QTreeWidgetItem *item,
const QString &name );
197 void keyPressEvent( QKeyEvent *event )
override;
198 void mousePressEvent( QMouseEvent *event )
override;
199 void drawRow( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
200 QColor rowColor(
int index )
const;
201 void toggleContextExpanded( QTreeWidgetItem *item );
202 void editNext(
const QModelIndex &index );
204 QModelIndex moveCursor( CursorAction cursorAction, Qt::KeyboardModifiers modifiers )
override;
210 VariableEditorDelegate *mEditorDelegate =
nullptr;
211 int mEditableScopeIndex = -1;
213 QMap< QPair<int, QString>, QTreeWidgetItem * > mVariableToItem;
214 QMap< int, QTreeWidgetItem * > mScopeToItem;
221class VariableEditorDelegate :
public QItemDelegate
226 VariableEditorDelegate( QObject *parent =
nullptr, QgsVariableEditorTree *tree =
nullptr )
227 : QItemDelegate( parent )
228 , mParentTree( tree )
231 QWidget *createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
232 const QModelIndex &index )
const override;
233 void updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
234 const QModelIndex &index )
const override;
235 QSize sizeHint(
const QStyleOptionViewItem &option,
const QModelIndex &index )
const override;
236 void setModelData( QWidget *widget, QAbstractItemModel *model,
237 const QModelIndex &index )
const override;
238 void setEditorData( QWidget *,
const QModelIndex & )
const override {}
241 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...