expressionvariablemodel.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /***************************************************************************
  2. expressionvariablemodel.h - ExpressionVariableModel
  3. ---------------------
  4. begin : 29.9.2016
  5. copyright : (C) 2016 by Matthias Kuhn
  6. email : matthias@opengis.ch
  7. ***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #ifndef EXPRESSIONVARIABLEMODEL_H
  16. #define EXPRESSIONVARIABLEMODEL_H
  17. #include <QStandardItemModel>
  18. class ExpressionVariableModel : public QStandardItemModel
  19. {
  20. Q_OBJECT
  21. public:
  22. enum Roles
  23. {
  24. VariableName = Qt::UserRole,
  25. VariableValue
  26. };
  27. explicit ExpressionVariableModel( QObject *parent = nullptr );
  28. bool setData( const QModelIndex &index, const QVariant &value, int role ) override;
  29. Q_INVOKABLE void addCustomVariable( const QString &varName, const QString &varVal );
  30. Q_INVOKABLE void removeCustomVariable( int row );
  31. Q_INVOKABLE void save();
  32. Q_INVOKABLE void reloadVariables();
  33. Q_INVOKABLE bool isEditable( int row );
  34. Q_INVOKABLE void setName( int row, const QString &name );
  35. Q_INVOKABLE void setValue( int row, const QString &value );
  36. QHash<int, QByteArray> roleNames() const override;
  37. private slots:
  38. void onDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles );
  39. };
  40. #endif // EXPRESSIONVARIABLEMODEL_H