SimpleExpressionEditorWidget.hpp
1 #pragma once
2 
3 #include <State/Expression.hpp>
4 
5 #include <Scenario/Inspector/ExpressionValidator.hpp>
6 
7 #include <QString>
8 #include <QWidget>
9 
10 #include <verdigris>
11 
12 namespace score
13 {
14 struct DocumentContext;
15 }
16 class QComboBox;
17 class QLabel;
18 class QLineEdit;
19 class QToolButton;
20 class QMenu;
21 namespace Device
22 {
23 class AddressAccessorEditWidget;
24 }
25 
26 namespace Scenario
27 {
28 
29 enum ExpressionEditorComparator
30 {
31  // Same as in Relation
32  Equal,
33  Different,
34  Greater,
35  Lower,
36  GreaterEqual,
37  LowerEqual,
38  Contains,
39 
40  // Additional ones
41  Pulse,
42  AlwaysTrue,
43  AlwaysFalse
44 };
45 
46 class SimpleExpressionEditorWidget final : public QWidget
47 {
49 public:
51  const score::DocumentContext&, int64_t index, QWidget* parent = nullptr,
52  QMenu* menu = nullptr);
53 
54  State::Expression relation();
55  std::optional<State::BinaryOperator> binOperator();
56 
57  int64_t id = -1;
58 
59  void setRelation(const State::Relation& r);
60  void setPulse(const State::Pulse& r);
61  void setOperator(State::BinaryOperator o);
62  void setOperator(State::UnaryOperator u);
63 
64  QString currentRelation();
65  QString currentOperator();
66 
67  void enableRemoveButton(bool);
68  void enableAddButton(bool);
69  void enableMenuButton(bool);
70 
71  void decreaseId();
72 
73 public:
74  void editingFinished() W_SIGNAL(editingFinished);
75  void addTerm() W_SIGNAL(addTerm);
76  void removeTerm(int index) W_SIGNAL(removeTerm, index);
77 
78 private:
79  void on_editFinished();
80  void on_comparatorChanged(int i);
81  // TODO on_modelChanged() -> done in parent inspector (i.e. event), no ?
82 
83  QLabel* m_ok{};
84 
86  QComboBox* m_comparator{};
87  QLineEdit* m_value{};
88  QComboBox* m_binOperator{};
89  QToolButton* m_rmBtn{};
90  QToolButton* m_addBtn{};
91  QToolButton* m_menuBtn{};
92 
94  QString m_relation{};
95  QString m_op{};
96 };
97 }
98 
99 Q_DECLARE_METATYPE(Scenario::ExpressionEditorComparator)
100 W_REGISTER_ARGTYPE(Scenario::ExpressionEditorComparator)
Definition: AddressAccessorEditWidget.hpp:26
Definition: ExpressionValidator.hpp:10
Definition: SimpleExpressionEditorWidget.hpp:47
SimpleExpressionEditorWidget(const score::DocumentContext &, int64_t index, QWidget *parent=nullptr, QMenu *menu=nullptr)
Definition: SimpleExpressionEditorWidget.cpp:78
Manipulation of Devices from Qt.
Definition: AddressSettings.cpp:14
Main plug-in of score.
Definition: score-plugin-dataflow/Dataflow/PortItem.hpp:14
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: Relation.hpp:71
Definition: Relation.hpp:19
Definition: DocumentContext.hpp:18