JSProcessModel.hpp
1 #pragma once
2 #include <Process/Process.hpp>
3 #include <Process/Script/ScriptProcess.hpp>
4 
5 #include <JS/JSProcessMetadata.hpp>
6 #include <JS/Qml/QmlObjects.hpp>
7 
8 #include <QFileSystemWatcher>
9 #include <QQmlComponent>
10 #include <QQmlEngine>
11 
12 #include <score_plugin_js_export.h>
13 
14 #include <memory>
15 #include <verdigris>
16 namespace JS
17 {
18 class Script;
19 class ProcessModel;
20 
21 void setupEngineImportPaths(QQmlEngine& engine) noexcept;
22 
24 {
25 public:
26  JS::Script*
27  get(const JS::ProcessModel& process, const QByteArray& str, bool isFile) noexcept;
28  JS::Script* tryGet(const QByteArray& str, bool isFile) const noexcept;
30  ~ComponentCache();
31 
32 private:
33  struct Cache
34  {
35  QByteArray key;
36  std::unique_ptr<QQmlComponent> component{};
37  std::unique_ptr<JS::Script> object{};
38  };
39  std::vector<Cache> m_map;
40 };
41 
42 class SCORE_PLUGIN_JS_EXPORT ProcessModel final : public Process::ProcessModel
43 {
44  SCORE_SERIALIZE_FRIENDS
45  PROCESS_METADATA_IMPL(JS::ProcessModel)
46  W_OBJECT(ProcessModel)
47 public:
48  static constexpr bool hasExternalUI() noexcept { return true; }
49 
50  explicit ProcessModel(
51  const TimeVal& duration, const QString& data, const Id<Process::ProcessModel>& id,
52  QObject* parent);
53 
54  template <typename Impl>
55  explicit ProcessModel(Impl& vis, QObject* parent)
56  : Process::ProcessModel{vis, parent}
57  {
58  vis.writeTo(*this);
59  }
60 
61  [[nodiscard]] Process::ScriptChangeResult setScript(const QString& script);
62  const QString& script() const noexcept { return m_script; }
63 
64  const QByteArray& qmlData() const noexcept { return m_qmlData; }
65 
66  JS::Script* currentObject() const noexcept;
67  bool isGpu() const noexcept;
68 
69  ~ProcessModel() override;
70 
71  bool validate(const QString& str) const noexcept;
72  void errorMessage(int arg_1, const QString& arg_2) const
73  W_SIGNAL(errorMessage, arg_1, arg_2);
74  void scriptOk() W_SIGNAL(scriptOk);
75  void scriptChanged(const QString& arg_1) W_SIGNAL(scriptChanged, arg_1);
76  void programChanged() W_SIGNAL(programChanged);
77 
78  PROPERTY(QString, script READ script WRITE setScript NOTIFY scriptChanged)
79 private:
80  QString effect() const noexcept override;
81  void loadPreset(const Process::Preset& preset) override;
82  Process::Preset savePreset() const noexcept override;
83  Process::ScriptChangeResult setQmlData(const QByteArray&, bool isFile);
84 
85  QString m_script;
86  QByteArray m_qmlData;
87  mutable ComponentCache m_cache;
88  //std::unique_ptr<QFileSystemWatcher> m_watch;
89  bool m_isFile{};
90 };
91 }
Definition: JSProcessModel.hpp:43
The Process class.
Definition: score-lib-process/Process/Process.hpp:61
Definition: QmlObjects.hpp:556
The id_base_t class.
Definition: Identifier.hpp:57
Definition: JSProcessModel.hpp:24
Definition: Preset.hpp:32
Definition: ScriptProcess.hpp:14
Definition: TimeValue.hpp:21