OSSIA
Open Scenario System for Interactive Application
qml_cond.hpp
1 #pragma once
2 #include <ossia/editor/expression/expression_generic.hpp>
4 
5 #include <QQmlExpression>
6 #include <QQmlListProperty>
7 #include <QQmlScriptString>
8 #include <QQuickItem>
9 
10 #include <verdigris>
11 namespace ossia
12 {
13 namespace qt
14 {
15 class qml_interval;
16 class qml_sync;
17 class qml_state;
18 class qml_expr final : public ossia::expressions::expression_generic_base
19 {
20 public:
21  qml_expr(QQmlExpression* e)
22  : m_expr{e}
23  {
24  }
25 
26  void update() override { }
27  bool evaluate() const override { return m_expr->evaluate().toBool(); }
28  void on_first_callback_added(expressions::expression_generic&) override { }
29  void on_removing_last_callback(expressions::expression_generic&) override { }
30 
31 private:
32  std::unique_ptr<QQmlExpression> m_expr;
33 };
34 
35 ossia::expression_ptr
36 make_expression(const QQmlScriptString& script, QObject* obj, expression_ptr deflt);
37 class qml_cond : public QQuickItem
38 {
39  W_OBJECT(qml_cond)
40 
41 public:
42  qml_cond(QQuickItem* parent = nullptr);
43 
44  ~qml_cond() override;
45 
46  QQmlScriptString expr() const;
47  qml_sync* sync() const;
48 
49  void setup();
50 
51  void registerState(qml_state*);
52  void unregisterState(qml_state*);
53 
54  std::shared_ptr<ossia::time_event> cond() const { return m_impl; }
55  void setCond(std::shared_ptr<ossia::time_event> c) { m_impl = c; }
56 
57 public:
58  void setExpr(QQmlScriptString expr);
59  W_SLOT(setExpr);
60  void setSync(qml_sync* sync);
61  W_SLOT(setSync);
62 
63 public:
64  void exprChanged(QQmlScriptString expr) E_SIGNAL(OSSIA_EXPORT, exprChanged, expr);
65  void syncChanged(qml_sync* sync) E_SIGNAL(OSSIA_EXPORT, syncChanged, sync);
66 
67 private:
68  void reset();
69  QQmlScriptString m_expr;
70  std::shared_ptr<ossia::time_event> m_impl;
71  qml_sync* m_sync{};
72 
73  W_PROPERTY(qml_sync*, sync READ sync WRITE setSync NOTIFY syncChanged)
74 
75  W_PROPERTY(QQmlScriptString, expr READ expr WRITE setExpr NOTIFY exprChanged)
76 };
77 }
78 }
Definition: git_info.h:7
Definition: expression_generic.hpp:13