13 #ifndef __PLUGIN_API_SCOREELEMENT_H__ 14 #define __PLUGIN_API_SCOREELEMENT_H__ 16 #include "libmscore/property.h" 32 enum class Ownership {
48 Q_PROPERTY(
int type READ type)
54 Q_PROPERTY(QString name READ name)
58 qreal spatium() const;
68 : QObject(), _ownership(own), e(_e) {}
73 Ownership ownership()
const {
return _ownership; }
74 void setOwnership(Ownership o) { _ownership = o; }
76 Ms::ScoreElement* element() {
return e; };
77 const Ms::ScoreElement* element()
const {
return e; };
82 QVariant
get(Ms::Pid pid)
const;
83 void set(Ms::Pid pid, QVariant val);
86 Q_INVOKABLE QString userName()
const;
98 template <
class Wrapper,
class T>
99 Wrapper* wrap(T* t, Ownership own = Ownership::SCORE)
101 Wrapper* w = t ?
new Wrapper(t, own) :
nullptr;
103 QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
107 extern ScoreElement* wrap(Ms::ScoreElement* se, Ownership own = Ownership::SCORE);
118 template <
class Wrapper,
class T,
typename... Args>
119 Wrapper* customWrap(T* t, Args... args)
121 Wrapper* w = t ?
new Wrapper(t, std::forward<Args>(args)...) :
nullptr;
123 QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
133 template <
typename T,
class Container>
138 : QQmlListProperty<T>(obj,
const_cast<void*
>(
static_cast<const void*
>(&container)), &count, &at) {};
140 static int count(QQmlListProperty<T>* l) {
return int(static_cast<Container*>(l->data)->size()); }
141 static T* at(QQmlListProperty<T>* l,
int i)
143 auto el =
static_cast<Container*
>(l->data)->at(i);
146 if (std::is_same<T*, decltype(wrap(el, Ownership::SCORE))>::value)
147 return static_cast<T*>(wrap(el, Ownership::SCORE));
149 return wrap<T>(el, Ownership::SCORE);
155 template<
typename T,
class Container>
Base class for most of object wrappers exposed to QML.
Definition: scoreelement.h:42
QML access to containers.
Definition: scoreelement.h:134
Q_INVOKABLE bool is(Ms::PluginAPI::ScoreElement *other)
Checks whether two variables represent the same object.
Definition: scoreelement.h:88
Definition: cursor.cpp:30