MuseScore Plugins  3.2.3
Plugins API for MuseScore
excerpt.h
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2019 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __PLUGIN_API_EXCERPT_H__
14 #define __PLUGIN_API_EXCERPT_H__
15 
16 #include "libmscore/excerpt.h"
17 
18 namespace Ms {
19 
20 namespace PluginAPI {
21 
22 class Score;
23 
24 //---------------------------------------------------------
25 // Excerpt
26 // Wrapper class for Excerpt
27 //
28 // This is based on the wrapper in scoreelement.h, which
29 // we cannot use here, because Ms::Excerpt is not derived
30 // from Ms::ScoreElement.
31 // Since a plugin should never need to create an Excerpt
32 // instance by itself, we don't care for Ownership here.
33 //---------------------------------------------------------
34 
35 class Excerpt : public QObject {
36  Q_OBJECT
40  Q_PROPERTY(QString title READ title)
41 
43  protected:
44  Ms::Excerpt* const e;
45 
46  public:
47  Excerpt(Ms::Excerpt* _e = nullptr)
48  : QObject(), e(_e) {}
49  Excerpt(const Excerpt&) = delete;
50  Excerpt& operator=(const Excerpt&) = delete;
51  virtual ~Excerpt() {}
52 
53  Score* partScore();
54  QString title() { return e->title(); }
56 };
57 
58 //---------------------------------------------------------
59 // wrap
62 //---------------------------------------------------------
63 
64 template <class Wrapper, class T>
65 Wrapper* excerptWrap(T* t)
66  {
67  Wrapper* w = t ? new Wrapper(t) : nullptr;
68  // All wrapper objects should belong to JavaScript code.
69  QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
70  return w;
71  }
72 
73 extern Excerpt* excerptWrap(Ms::Excerpt* e);
74 
75 //---------------------------------------------------------
76 // qml access to containers of Excerpt
77 //
78 // QmlExcerptsListAccess provides a convenience interface
79 // for QQmlListProperty providing read-only access to
80 // plugins for Excerpts containers.
81 //
82 // based on QmlListAccess in scoreelement.h
83 //---------------------------------------------------------
84 
85 template <typename T, class Container>
86 class QmlExcerptsListAccess : public QQmlListProperty<T> {
87 public:
88  QmlExcerptsListAccess(QObject* obj, Container& container)
89  : QQmlListProperty<T>(obj, &container, &count, &at) {};
90 
91  static int count(QQmlListProperty<T>* l) { return int(static_cast<Container*>(l->data)->size()); }
92  static T* at(QQmlListProperty<T>* l, int i) { return excerptWrap<T>(static_cast<Container*>(l->data)->at(i)); }
93  };
94 
96 template<typename T, class Container>
97 QmlExcerptsListAccess<T, Container> wrapExcerptsContainerProperty(QObject* obj, Container& c)
98  {
100  }
101 
102 } // namespace PluginAPI
103 } // namespace Ms
104 #endif
QString title
The title of this part.
Definition: excerpt.h:40
Definition: excerpt.h:35
Ms::PluginAPI::Score partScore
The score object for this part.
Definition: excerpt.h:38
Definition: score.h:32
Definition: cursor.cpp:29
Definition: excerpt.h:86