DocumentPluginCreator.hpp
1 #pragma once
2 #include <score/plugins/InterfaceList.hpp>
3 #include <score/plugins/documentdelegate/plugin/DocumentPlugin.hpp>
4 #include <score/tools/IdentifierGeneration.hpp>
5 
6 #include <core/document/Document.hpp>
7 #include <core/document/DocumentModel.hpp>
8 
9 namespace score
10 {
11 
12 template <typename DocPlugin>
13 auto& addDocumentPlugin(score::Document& doc)
14 {
15  auto& model = doc.model();
16  auto plug = new DocPlugin{doc.context(), &model};
17  model.addPluginModel(plug);
18  return *plug;
19 }
20 
24 class SCORE_LIB_BASE_EXPORT DocumentPluginFactory : public score::InterfaceBase
25 {
26  SCORE_INTERFACE(DocumentPluginFactory, "570faa0b-f100-4039-a2f0-b60347c4e581")
27 public:
28  virtual ~DocumentPluginFactory();
29 
30  virtual DocumentPlugin*
31  load(const VisitorVariant& var, score::DocumentContext& doc, QObject* parent)
32  = 0;
33 };
34 class SCORE_LIB_BASE_EXPORT DocumentPluginFactoryList final
35  : public score::InterfaceList<score::DocumentPluginFactory>
36 {
37 public:
40  object_type* loadMissing(
41  const VisitorVariant& vis, score::DocumentContext& doc, QObject* parent) const;
42 };
43 
44 template <typename T>
46 {
47 public:
48  T* load(
49  const VisitorVariant& var, score::DocumentContext& doc, QObject* parent) override
50  {
51  return deserialize_dyn(var, [&](auto&& deserializer) {
52  return new T{doc, deserializer, parent};
53  });
54  }
55 
56  static UuidKey<score::DocumentPluginFactory> static_concreteKey()
57  {
59  }
60 
61  UuidKey<score::DocumentPluginFactory> concreteKey() const noexcept final override
62  {
64  }
65 };
66 
67 }
Definition: UuidKey.hpp:343
The Document class is the central part of the software.
Definition: Document.hpp:51
Definition: DocumentPluginCreator.hpp:46
Reimplement to instantiate document plug-ins.
Definition: DocumentPluginCreator.hpp:25
Definition: DocumentPluginCreator.hpp:36
Extend a document with custom data and systems.
Definition: DocumentPluginBase.hpp:24
Base class for plug-in interfaces.
Definition: Interface.hpp:52
InterfaceList Default implementation of InterfaceListBase.
Definition: InterfaceList.hpp:80
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Static metadata implementation.
Definition: lib/score/tools/Metadata.hpp:36
The VisitorVariant struct.
Definition: VisitorInterface.hpp:26
Definition: DocumentContext.hpp:18