1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
Origin: upstream, commit:216188f7ed8d652066ee9a6a6034d4cfcc099b81
Author: Dale Larson <dlarson42@gmail.com>
Description: Fix #291708: Expose Score.selection object to access to GUI selected elements.
This commit exposes the Score.selection.elements list
enabling QML scripts to manipulate on user selected score elements.
The expectation is that additional selection information will be
provided on this object in the future.
--- a/mscore/CMakeLists.txt
+++ b/mscore/CMakeLists.txt
@@ -58,6 +58,7 @@ if (SCRIPT_INTERFACE)
plugin/api/fraction.h
plugin/api/excerpt.h
plugin/api/util.h
+ plugin/api/selection.h
plugin/api/enums.cpp
plugin/mscorePlugins.cpp plugin/pluginCreator.cpp plugin/pluginManager.cpp plugin/qmledit.cpp
@@ -66,6 +67,7 @@ if (SCRIPT_INTERFACE)
plugin/api/score.cpp
plugin/api/excerpt.cpp
plugin/api/util.cpp
+ plugin/api/selection.cpp
)
set (SCRIPT_UI
--- a/mscore/plugin/api/qmlpluginapi.cpp
+++ b/mscore/plugin/api/qmlpluginapi.cpp
@@ -17,6 +17,8 @@
#include "score.h"
#include "part.h"
#include "util.h"
+#include "selection.h"
+
#ifndef TESTROOT
#include "shortcut.h"
#endif
@@ -343,6 +345,7 @@ void PluginAPI::registerQmlTypes()
qmlRegisterType<Measure>();
qmlRegisterType<Part>();
qmlRegisterType<Excerpt>();
+ qmlRegisterType<Selection>();
//qmlRegisterType<Hook>();
//qmlRegisterType<Stem>();
//qmlRegisterType<StemSlash>();
--- a/mscore/plugin/api/score.h
+++ b/mscore/plugin/api/score.h
@@ -24,6 +24,10 @@ namespace PluginAPI {
class Cursor;
class Segment;
class Measure;
+class Selection;
+class Score;
+
+extern Selection* selectionWrap(Ms::Selection* select);
//---------------------------------------------------------
// Score
@@ -80,6 +84,8 @@ class Score : public Ms::PluginAPI::Scor
Q_PROPERTY(QString mscoreVersion READ mscoreVersion)
/** MuseScore revision the score has been last saved with (includes autosave) (read only) */
Q_PROPERTY(QString mscoreRevision READ mscoreRevision)
+ /** Current selections for the score. \since MuseScore 3.3 */
+ Q_PROPERTY(Ms::PluginAPI::Selection* selection READ selection)
public:
/// \cond MS_INTERNAL
@@ -98,6 +104,8 @@ class Score : public Ms::PluginAPI::Scor
int lyricCount() { return score()->lyricCount(); }
QString lyricist() { return score()->metaTag("lyricist"); } // not the meanwhile obsolete "poet"
QString title() { return score()->metaTag("workTitle"); }
+ Ms::PluginAPI::Selection* selection() { return selectionWrap(&score()->selection()); }
+
/// \endcond
/// Returns as a string the metatag named \p tag
--- a/mscore/plugin/api/scoreelement.h
+++ b/mscore/plugin/api/scoreelement.h
@@ -114,7 +114,16 @@ public:
: QQmlListProperty<T>(obj, const_cast<void*>(static_cast<const void*>(&container)), &count, &at) {};
static int count(QQmlListProperty<T>* l) { return int(static_cast<Container*>(l->data)->size()); }
- static T* at(QQmlListProperty<T>* l, int i) { return wrap<T>(static_cast<Container*>(l->data)->at(i), Ownership::SCORE); }
+ static T* at(QQmlListProperty<T>* l, int i)
+ {
+ auto el = static_cast<Container*>(l->data)->at(i);
+ // If a polymorphic wrap() function is available
+ // for the requested type, use it for wrapping.
+ if (std::is_same<T*, decltype(wrap(el, Ownership::SCORE))>::value)
+ return static_cast<T*>(wrap(el, Ownership::SCORE));
+ // Otherwise, wrap directly to the requested wrapper type.
+ return wrap<T>(el, Ownership::SCORE);
+ }
/// \endcond
};
--- /dev/null
+++ b/mscore/plugin/api/selection.cpp
@@ -0,0 +1,32 @@
+//=============================================================================
+// MuseScore
+// Music Composition & Notation
+//
+// Copyright (C) 2019 Werner Schweer and others
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2
+// as published by the Free Software Foundation and appearing in
+// the file LICENCE.GPL
+//=============================================================================
+
+#include "selection.h"
+#include "score.h"
+
+namespace Ms {
+namespace PluginAPI {
+
+//---------------------------------------------------------
+// QmlPlayEventsListAccess::append
+//---------------------------------------------------------
+
+Selection* selectionWrap(Ms::Selection* select)
+ {
+ Selection* w = new Selection(select);
+ // All wrapper objects should belong to JavaScript code.
+ QQmlEngine::setObjectOwnership(w, QQmlEngine::JavaScriptOwnership);
+ return w;
+ }
+
+}
+}
--- /dev/null
+++ b/mscore/plugin/api/selection.h
@@ -0,0 +1,54 @@
+//=============================================================================
+// MuseScore
+// Music Composition & Notation
+//
+// Copyright (C) 2019 Werner Schweer and others
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2
+// as published by the Free Software Foundation and appearing in
+// the file LICENCE.GPL
+//=============================================================================
+
+#ifndef __PLUGIN_API_SELECTION_H__
+#define __PLUGIN_API_SELECTION_H__
+
+#include "elements.h"
+#include "score.h"
+
+namespace Ms {
+namespace PluginAPI {
+
+//---------------------------------------------------------
+// Selection
+// Wrapper class for internal Ms::Selection
+/// \since MuseScore 3.3
+//---------------------------------------------------------
+
+class Selection : public QObject {
+ Q_OBJECT
+ /// Current GUI selections for the score.
+ /// \since MuseScore 3.3
+ Q_PROPERTY(QQmlListProperty<Ms::PluginAPI::Element> elements READ elements)
+
+ /// \cond MS_INTERNAL
+
+ protected:
+ Ms::Selection* _select;
+
+ public:
+
+ Selection(Ms::Selection* select) : QObject(), _select(select) {}
+ virtual ~Selection() { }
+
+ QQmlListProperty<Element> elements()
+ { return wrapContainerProperty<Element>(this, _select->elements()); }
+
+ /// \endcond
+};
+
+extern Selection* selectionWrap(Ms::Selection* select);
+
+} // namespace PluginAPI
+} // namespace Ms
+#endif
--- a/mtest/CMakeLists.txt
+++ b/mtest/CMakeLists.txt
@@ -106,6 +106,7 @@ set (SOURCE_LIB
${PROJECT_SOURCE_DIR}/mscore/plugin/api/part.h
${PROJECT_SOURCE_DIR}/mscore/plugin/api/excerpt.cpp
${PROJECT_SOURCE_DIR}/mscore/plugin/api/util.cpp
+ ${PROJECT_SOURCE_DIR}/mscore/plugin/api/selection.cpp
${PROJECT_SOURCE_DIR}/mscore/preferences.cpp
${PROJECT_SOURCE_DIR}/mscore/shortcut.cpp
${PROJECT_SOURCE_DIR}/mscore/stringutils.cpp
|