Skip to content

Commit

Permalink
Fix #293837: Plugin: WIP: Add ability to compare sameness of MuseScor…
Browse files Browse the repository at this point in the history
…e QML elements.

A property named 'elementId' has been added to all score elements
so that QML scripting can compare two different QML elements to see
if they are accessing the same MuseScore object beneath the plugin
wrappers. This is needed because there may be more than one wrapper
for an object at the scripting layer depending how the script
obtained the element object.
  • Loading branch information
DLLarson committed Aug 27, 2019
1 parent b101167 commit 91f3114
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions mscore/plugin/api/scoreelement.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@ class ScoreElement : public QObject {
* element name suitable for usage in a user interface.
*/
Q_PROPERTY(QString name READ name)
/**
* Unique element identifier for comparing MuseScore object equality.
*
* elementId is available for all elements so that QML scripting can
* compare two different QML elements to see if they are accessing the
* same MuseScore object beneath the plugin wrappers. This is needed
* because there may be more than one wrapper object for the same
* MuseScore object because that are provided in many different ways.
*
* \code{.js}
* var note = cursor.element.notes[0];
* if (note.elementId == note.firstTiedNote.elementId)
* console.log("Both wrappers point to the same Note object.")
* else
* console.log("Both wrappers point to different Note objects.")
* \endcode
*
* \since MuseScore 3.3
*/
Q_PROPERTY(qint64 elementId READ elementId)

Ownership _ownership;

Expand All @@ -75,6 +95,9 @@ class ScoreElement : public QObject {
QString name() const;
int type() const;

qint64 elementId() const { return qint64((void*)e); }


QVariant get(Ms::Pid pid) const;
void set(Ms::Pid pid, QVariant val);
/// \endcond
Expand Down

0 comments on commit 91f3114

Please sign in to comment.