|
25 | 25 |
|
26 | 26 | #include "extensions/api/v1/ipluginapiv1.h" |
27 | 27 |
|
| 28 | +#include "global/api/apiutils.h" |
| 29 | + |
28 | 30 | #include "modularity/ioc.h" |
29 | 31 | #include "actions/iactionsdispatcher.h" |
30 | 32 | #include "context/iglobalcontext.h" |
|
36 | 38 | #include "cursor.h" |
37 | 39 | #include "enums.h" |
38 | 40 |
|
| 41 | +#include "log.h" |
| 42 | + |
39 | 43 | namespace mu::engraving { |
40 | 44 | class EngravingItem; |
41 | 45 | class Score; |
@@ -65,6 +69,14 @@ class Score; |
65 | 69 | return cppName; \ |
66 | 70 | } |
67 | 71 |
|
| 72 | +#define DECLARE_API_ENUM_JSVAL(qmlName, getterName, enumType) \ |
| 73 | +/** Accessed using qmlName.VALUE*/ \ |
| 74 | + Q_PROPERTY(QJSValue qmlName READ getterName CONSTANT) \ |
| 75 | + QJSValue getterName() const { \ |
| 76 | + static const QJSValue enval = makeEnum(qmlName); \ |
| 77 | + return enval; \ |
| 78 | + } |
| 79 | + |
68 | 80 | #define DECLARE_API_ENUM2(qmlName, cppName, enumName1, enumName2) \ |
69 | 81 | /** Accessed using qmlName.VALUE*/ \ |
70 | 82 | Q_PROPERTY(mu::engraving::apiv1::Enum * qmlName READ get_##cppName CONSTANT) \ |
@@ -139,7 +151,8 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV |
139 | 151 | public: |
140 | 152 | // Should be initialized in qmlpluginapi.cpp |
141 | 153 | /// Contains mu::engraving::ElementType enumeration values |
142 | | - DECLARE_API_ENUM(Element, elementTypeEnum, mu::engraving::apiv1::enums::ElementType) |
| 154 | + DECLARE_API_ENUM(Element, elementTypeEnum, mu::engraving::apiv1::enums::ElementType) |
| 155 | + //DECLARE_API_ENUM_JSVAL(Element, elementTypeEnum, mu::engraving::apiv1::enums::ElementType) |
143 | 156 | /// Contains mu::engraving::AccidentalType enumeration values |
144 | 157 | DECLARE_API_ENUM(Accidental, accidentalTypeEnum, mu::engraving::apiv1::enums::AccidentalType) |
145 | 158 | /// Contains mu::engraving::AccidentalBracket enumeration values |
@@ -591,6 +604,19 @@ class PluginAPI : public QQuickItem, public muse::extensions::apiv1::IPluginApiV |
591 | 604 | private: |
592 | 605 | mu::engraving::Score* currentScore() const; |
593 | 606 |
|
| 607 | + template<typename T> |
| 608 | + QJSValue makeEnum(const QString& name) const |
| 609 | + { |
| 610 | + IF_ASSERT_FAILED(m_engine) { |
| 611 | + return QJSValue(); |
| 612 | + } |
| 613 | + return muse::api::enumToJsValue(m_engine, |
| 614 | + QMetaEnum::fromType<T>(), |
| 615 | + muse::api::EnumType::Int, |
| 616 | + name); |
| 617 | + } |
| 618 | + |
| 619 | + muse::api::IApiEngine* m_engine = nullptr; |
594 | 620 | QString m_pluginType; |
595 | 621 | QString m_title; |
596 | 622 | QString m_version; |
|
0 commit comments