diff --git a/libmscore/layout.cpp b/libmscore/layout.cpp index 8c5d90cebb5ac..c2201849b96c2 100644 --- a/libmscore/layout.cpp +++ b/libmscore/layout.cpp @@ -3448,8 +3448,15 @@ System* Score::collectSystem(LayoutContext& lc) for (Element* e : s->annotations()) { if (e->isStaffText() || e->isSystemText() || e->isInstrumentChange()) e->layout(); - if (e->isHarmony()) + if (e->isHarmony()) { + Harmony* h = toHarmony(e); + // Layout of harmony seems to be bound currently + // to ChordRest (see ChordRest::shape). But harmony + // can exist without chord or rest too. + if (h->isLayoutInvalid()) + h->layout(); toHarmony(e)->autoplaceSegmentElement(styleP(Sid::minHarmonyDistance)); + } } } diff --git a/libmscore/textbase.cpp b/libmscore/textbase.cpp index 1fffb1d6f403d..83f26e842bf0f 100644 --- a/libmscore/textbase.cpp +++ b/libmscore/textbase.cpp @@ -1879,10 +1879,17 @@ QString TextBase::plainText() const { QString s; - if (layoutInvalid) - ((Text*)(this))->createLayout(); // ugh! + const TextBase* text = this; + std::unique_ptr tmpText; + if (layoutInvalid) { + // Create temporary text object to avoid side effects + // of createLayout() call. + tmpText.reset(toTextBase(this->clone())); + tmpText->createLayout(); + text = tmpText.get(); + } - for (const TextBlock& block : _layout) { + for (const TextBlock& block : text->_layout) { for (const TextFragment& f : block.fragments()) s += f.text; if (block.eol()) @@ -1897,9 +1904,16 @@ QString TextBase::plainText() const QString TextBase::xmlText() const { - if (textInvalid) - ((Text*)(this))->genText(); // ugh! - return _text; + const TextBase* text = this; + std::unique_ptr tmpText; + if (textInvalid) { + // Create temporary text object to avoid side effects + // of genText() call. + tmpText.reset(toTextBase(this->clone())); + tmpText->genText(); + text = tmpText.get(); + } + return text->_text; } //--------------------------------------------------------- diff --git a/mtest/libmscore/layout_elements/layout_elements.mscx b/mtest/libmscore/layout_elements/layout_elements.mscx index c99ecbc099adb..76ff6cf781450 100644 --- a/mtest/libmscore/layout_elements/layout_elements.mscx +++ b/mtest/libmscore/layout_elements/layout_elements.mscx @@ -12,7 +12,7 @@ 6 13 1.14 - 0 + 1.564 1 @@ -827,7 +827,6 @@ 14 - hord whole @@ -844,6 +843,15 @@ 18 + + -5/8 + + + 16 + + + 5/8 + half