MuseScore Plugins  3.5
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 
42  protected:
44  Ms::Excerpt* const e;
46 
47  public:
49  Excerpt(Ms::Excerpt* _e = nullptr)
50  : QObject(), e(_e) {}
51  Excerpt(const Excerpt&) = delete;
52  Excerpt& operator=(const Excerpt&) = delete;
53  virtual ~Excerpt() {}
54 
55  Score* partScore();
56  QString title() { return e->title(); }
58 
60  Q_INVOKABLE bool is(Ms::PluginAPI::Excerpt* other) { return other && e == other->e; }
61 };
62 
63 //---------------------------------------------------------
64 // wrap
67 //---------------------------------------------------------
68 
69 template <class Wrapper, class T>
70 Wrapper* excerptWrap(T* t)
71  {
72  Wrapper* w = t ? new Wrapper(t) : nullptr;
73  // All wrapper objects should belong to JavaScript code.
74  QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
75  return w;
76  }
77 
78 extern Excerpt* excerptWrap(Ms::Excerpt* e);
79 
80 //---------------------------------------------------------
81 // qml access to containers of Excerpt
82 //
83 // QmlExcerptsListAccess provides a convenience interface
84 // for QQmlListProperty providing read-only access to
85 // plugins for Excerpts containers.
86 //
87 // based on QmlListAccess in scoreelement.h
88 //---------------------------------------------------------
89 
90 template <typename T, class Container>
91 class QmlExcerptsListAccess : public QQmlListProperty<T> {
92 public:
93  QmlExcerptsListAccess(QObject* obj, Container& container)
94  : QQmlListProperty<T>(obj, &container, &count, &at) {};
95 
96  static int count(QQmlListProperty<T>* l) { return int(static_cast<Container*>(l->data)->size()); }
97  static T* at(QQmlListProperty<T>* l, int i) { return excerptWrap<T>(static_cast<Container*>(l->data)->at(i)); }
98  };
99 
101 template<typename T, class Container>
102 QmlExcerptsListAccess<T, Container> wrapExcerptsContainerProperty(QObject* obj, Container& c)
103  {
105  }
106 
107 } // namespace PluginAPI
108 } // namespace Ms
109 #endif
Q_INVOKABLE bool is(Ms::PluginAPI::Excerpt *other)
Checks whether two variables represent the same object.
Definition: excerpt.h:60
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:41
Definition: cursor.cpp:30
Definition: excerpt.h:91