|
28 | 28 | #include "dom/measure.h" |
29 | 29 | #include "dom/score.h" |
30 | 30 | #include "dom/segment.h" |
| 31 | +#include "dom/spanner.h" |
| 32 | +#include "dom/spannermap.h" |
31 | 33 | #include "dom/text.h" |
32 | 34 | #include "editing/editsystemlocks.h" |
33 | 35 | #include "types/typesconv.h" |
|
39 | 41 |
|
40 | 42 | using namespace mu::engraving::apiv1; |
41 | 43 |
|
| 44 | +qsizetype Score::spannerListCount(QQmlListProperty<Spanner>* list) |
| 45 | +{ |
| 46 | + auto* scoreWrapper = static_cast<Score*>(list->data); |
| 47 | + if (!scoreWrapper) { |
| 48 | + return 0; |
| 49 | + } |
| 50 | + |
| 51 | + mu::engraving::Score* nativeScore = scoreWrapper->score(); |
| 52 | + if (!nativeScore) { |
| 53 | + return 0; |
| 54 | + } |
| 55 | + |
| 56 | + return static_cast<qsizetype>(nativeScore->spannerMap().map().size()); |
| 57 | +} |
| 58 | + |
| 59 | +Spanner* Score::spannerListAt(QQmlListProperty<Spanner>* list, qsizetype index) |
| 60 | +{ |
| 61 | + auto* scoreWrapper = static_cast<Score*>(list->data); |
| 62 | + if (!scoreWrapper || index < 0) { |
| 63 | + return nullptr; |
| 64 | + } |
| 65 | + |
| 66 | + mu::engraving::Score* nativeScore = scoreWrapper->score(); |
| 67 | + if (!nativeScore) { |
| 68 | + return nullptr; |
| 69 | + } |
| 70 | + |
| 71 | + const auto& spanMap = nativeScore->spannerMap().map(); |
| 72 | + qsizetype current = 0; |
| 73 | + for (const auto& [tick, spanner] : spanMap) { |
| 74 | + UNUSED(tick); |
| 75 | + if (!spanner) { |
| 76 | + continue; |
| 77 | + } |
| 78 | + |
| 79 | + if (current == index) { |
| 80 | + return qobject_cast<Spanner*>(wrap(spanner, Ownership::SCORE)); |
| 81 | + } |
| 82 | + |
| 83 | + ++current; |
| 84 | + } |
| 85 | + |
| 86 | + return nullptr; |
| 87 | +} |
| 88 | + |
42 | 89 | Cursor* Score::newCursor() |
43 | 90 | { |
44 | 91 | return new Cursor(score()); |
@@ -262,6 +309,15 @@ QQmlListProperty<System> Score::systems() |
262 | 309 | return wrapContainerProperty<System>(this, score()->systems()); |
263 | 310 | } |
264 | 311 |
|
| 312 | +//--------------------------------------------------------- |
| 313 | +// Score::spanners |
| 314 | +//--------------------------------------------------------- |
| 315 | + |
| 316 | +QQmlListProperty<Spanner> Score::spanners() |
| 317 | +{ |
| 318 | + return QQmlListProperty<Spanner>(this, this, &Score::spannerListCount, &Score::spannerListAt); |
| 319 | +} |
| 320 | + |
265 | 321 | //--------------------------------------------------------- |
266 | 322 | // Score::startCmd |
267 | 323 | //--------------------------------------------------------- |
|
0 commit comments