AddressItemModel.hpp
1 #pragma once
2 #include <State/Widgets/Values/TypeComboBox.hpp>
3 
4 #include <Device/Address/AddressSettings.hpp>
5 
6 #include <Explorer/Explorer/DeviceExplorerModel.hpp>
7 
8 #include <QAbstractItemModel>
9 #include <QStyledItemDelegate>
10 
11 #include <verdigris>
12 
13 namespace Explorer
14 {
15 class DeviceExplorerModel;
33 class AddressItemModel final : public QAbstractItemModel
34 {
35  W_OBJECT(AddressItemModel)
36 public:
37  AddressItemModel(QObject* parent);
38  enum Rows
39  {
40  Name,
41  Address,
42  Value,
43  Type,
44  Min,
45  Max,
46  Values,
47  Unit,
48  Access,
49  Bounding,
50  Repetition,
51  Count
52  };
53 
54  void setState(
55  DeviceExplorerModel* model, Device::NodePath nodepath,
57  void clear();
58 
59  const Device::FullAddressSettings& settings() const { return m_settings; }
60 
61  bool setData(const QModelIndex& index, const QVariant& value, int role) override;
62  Qt::ItemFlags flags(const QModelIndex& index) const override;
63  QModelIndex index(int row, int column, const QModelIndex& parent) const override;
64  QModelIndex parent(const QModelIndex& child) const override;
65  int rowCount(const QModelIndex& parent) const override;
66  int columnCount(const QModelIndex& parent) const override;
67  QVariant valueColumnData(const State::Value& val, int role) const;
68  QVariant data(const QModelIndex& index, int role) const override;
69 
70 private:
71  int extendedCount() const noexcept;
72  QPointer<DeviceExplorerModel> m_model;
73  Device::NodePath m_path;
74  Device::FullAddressSettings m_settings;
75 };
76 
77 class AddressItemDelegate final : public QStyledItemDelegate
78 {
79 public:
80  explicit AddressItemDelegate(QObject* parent = 0);
82 
83 private:
84  void paint(
85  QPainter* painter, const QStyleOptionViewItem& option,
86  const QModelIndex& index) const override;
87  QWidget* createEditor(
88  QWidget* parent, const QStyleOptionViewItem& option,
89  const QModelIndex& index) const override;
90  void setEditorData(QWidget* editor, const QModelIndex& index) const override;
91  void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index)
92  const override;
93 };
94 
95 class AddressValueWidget : public QWidget
96 {
97  W_OBJECT(AddressValueWidget)
98 public:
99  using QWidget::QWidget;
100  virtual ossia::value get() const = 0;
101  virtual void set(ossia::value t) = 0;
102 
103 public:
104  void changed(ossia::value arg_1) W_SIGNAL(changed, arg_1);
105 };
106 }
Definition: AddressItemModel.hpp:78
Displays an address.
Definition: AddressItemModel.hpp:34
Definition: AddressItemModel.hpp:96
Definition: DeviceExplorerModel.hpp:67
Path in a tree of QAbstractItemModel objects.
Definition: TreePath.hpp:34
Definition: AddressSettings.hpp:62