fix #39876: no undo of chord symbol edit
This commit is contained in:
parent
0a59df0a1f
commit
f603cff9bc
4 changed files with 44 additions and 11 deletions
|
@ -597,7 +597,6 @@ void Harmony::startEdit(MuseScoreView* view, const QPointF& p)
|
|||
if (!textList.isEmpty()) {
|
||||
QString s(harmonyName());
|
||||
setText(s);
|
||||
Text::createLayout(); // create TextBlocks from text
|
||||
}
|
||||
Text::startEdit(view, p);
|
||||
layout();
|
||||
|
@ -626,15 +625,16 @@ bool Harmony::edit(MuseScoreView* view, int grip, int key, Qt::KeyboardModifiers
|
|||
void Harmony::endEdit()
|
||||
{
|
||||
Text::endEdit();
|
||||
setHarmony(plainText(true));
|
||||
layout();
|
||||
if (links()) {
|
||||
foreach(Element* e, *links()) {
|
||||
if (e == this)
|
||||
continue;
|
||||
Harmony* h = static_cast<Harmony*>(e);
|
||||
h->setHarmony(text());
|
||||
// transpose if necessary
|
||||
// at this point chord will already have been rendered in same key as original
|
||||
// (as a result of Text::endEdit() calling setText() for linked elements)
|
||||
// we may now need to change the TPC's and the text, and re-render
|
||||
if (score()->styleB(StyleIdx::concertPitch) != h->score()->styleB(StyleIdx::concertPitch)) {
|
||||
Part* partDest = h->staff()->part();
|
||||
Interval interval = partDest->instr()->transpose();
|
||||
|
@ -643,12 +643,16 @@ void Harmony::endEdit()
|
|||
interval.flip();
|
||||
int rootTpc = transposeTpc(h->rootTpc(), interval, false);
|
||||
int baseTpc = transposeTpc(h->baseTpc(), interval, false);
|
||||
h->score()->undoTransposeHarmony(h, rootTpc, baseTpc);
|
||||
//score()->undoTransposeHarmony(h, rootTpc, baseTpc);
|
||||
h->setRootTpc(rootTpc);
|
||||
h->setBaseTpc(baseTpc);
|
||||
// this invokes textChanged(), which handles the rendering
|
||||
h->setText(h->harmonyName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
score()->setLayoutAll(true); // done in Text::endEdit() too, but no harm being sure
|
||||
score()->setLayoutAll(true);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
@ -889,6 +893,17 @@ bool Harmony::isEmpty() const
|
|||
return textList.isEmpty() && Text::isEmpty();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// textChanged
|
||||
// text may have changed
|
||||
//---------------------------------------------------------
|
||||
|
||||
void Harmony::textChanged()
|
||||
{
|
||||
Text::createLayout();
|
||||
setHarmony(plainText(true));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// layout
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -122,6 +122,7 @@ class Harmony : public Text {
|
|||
|
||||
void determineRootBaseSpelling(NoteSpellingType& rootSpelling, bool& rootLowerCase, NoteSpellingType& baseSpelling, bool& baseLowerCase);
|
||||
|
||||
virtual void textChanged() override;
|
||||
virtual void layout();
|
||||
|
||||
const QRectF& bboxtight() const { return _tbbox; }
|
||||
|
|
|
@ -1488,7 +1488,12 @@ void Text::endEdit()
|
|||
|
||||
genText();
|
||||
|
||||
if (_text != oldText) {
|
||||
if (_text != oldText || type() == Element::Type::HARMONY) {
|
||||
// avoid creating unnecessary state on undo stack if edit did not change anything
|
||||
// but go ahead and do this anyhow for chord symbols no matter what
|
||||
// the code to special case transposition relies on the fact
|
||||
// that we are setting all linked elements to same text here
|
||||
|
||||
for (Element* e : linkList()) {
|
||||
// this line was added in https://github.com/musescore/MuseScore/commit/dcf963b3d6140fa550c08af18d9fb6f6e59733a3
|
||||
// it replaced the commented-out call to undoPushProperty in startEdit() above
|
||||
|
@ -1499,15 +1504,21 @@ void Text::endEdit()
|
|||
// by also checking for empty old text, we avoid creating an unnecessary element on undo stack
|
||||
// that returns us to the initial empty text created upon startEdit()
|
||||
|
||||
if (!oldText.isEmpty())
|
||||
score()->undo()->push1(new ChangeProperty(e, P_ID::TEXT, oldText));
|
||||
if (!oldText.isEmpty()) {
|
||||
// oldText is good for original element
|
||||
// but use original text for each linked element
|
||||
// these can differ (eg, for chord symbols in transposing parts)
|
||||
|
||||
QString undoText = (e == this) ? oldText : static_cast<Text*>(e)->_text;
|
||||
score()->undo()->push1(new ChangeProperty(e, P_ID::TEXT, undoText));
|
||||
}
|
||||
|
||||
// because we are pushing each individual linked element's old text to the undo stack,
|
||||
// we don't actually need to call the undo version of change property here
|
||||
|
||||
e->setProperty(P_ID::TEXT, _text);
|
||||
|
||||
// the change mentioned above eliminated the following line, which is where the linked elements actually got their text set
|
||||
// the change mentioned previously eliminated the following line, which is where the linked elements actually got their text set
|
||||
// one would think this line alone would be enough to make undo work
|
||||
// but it is not, because by the time we get here, we've already overwritten _text for the current item
|
||||
// that is why formerly we skipped this call for "this"
|
||||
|
@ -1515,7 +1526,13 @@ void Text::endEdit()
|
|||
//if (e != this) e->undoChangeProperty(P_ID::TEXT, _text);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// only necessary in the case of _text == oldtext
|
||||
// because otherwise, setProperty() call above calls setText(), which calls textChanged()
|
||||
// yet we still need to consider this a change, since newly added palette texts end up here
|
||||
textChanged();
|
||||
}
|
||||
|
||||
// formerly we needed to setLayoutAll here to force the text to be laid out after editing
|
||||
// but now that we are calling setProperty for all elements - including "this"
|
||||
// it is no longer necessary
|
||||
|
|
|
@ -2247,7 +2247,7 @@ void TransposeHarmony::flip()
|
|||
int rootTpc1 = harmony->rootTpc();
|
||||
harmony->setBaseTpc(baseTpc);
|
||||
harmony->setRootTpc(rootTpc);
|
||||
harmony->render();
|
||||
harmony->setText(harmony->harmonyName());
|
||||
rootTpc = rootTpc1;
|
||||
baseTpc = baseTpc1;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue