Skip to content

Commit 9c1788a

Browse files
MarcSabatellaJojo-Schmitz
authored andcommitted
fix #317163: properties lost on save/reload
Resolves: https://musescore.org/en/node/317163 Backport of musescore#7597, resp. duplicated from musescore#7453 The recent changes to style handling result in an extra styleChanged() call on load, which is not a problem in itself but exposes some existing problems in various read() functions. If styled properties were not marked as unstyled during the read, they get reset by this styleChanged() call, meaning any custom settings are lost on load. In fact, they would mostly have been lost after a *second* save/reload even in older versions, since the properties are not marked as unstyled and thus won't get written. But now they are lost immediately upon the first save/reload. The fix is to to be sure we mark the property unstyled on read, which basically means inserting calls to readStyledProperty() in the read() or readProperties() functions of various element types. This was originally reported for volta line style, and I quickly discovered it also appplies to line width, and to pedal line width. I then scanned the code looking for read() functions that did not handle styledProperties. I can't guarantee I found them all, but I did find the mmrest number offset and tuplet number text. The latter actually *seemed* to be handling the styled properties, but only for the tuplet itself, not the number. The font property flags needed to be copied to the number.
1 parent aa7f5cc commit 9c1788a

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

libmscore/pedal.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ void Pedal::read(XmlReader& e)
107107
if (score()->mscVersion() < 301)
108108
e.addSpanner(e.intAttribute("id", -1), this);
109109
while (e.readNextStartElement()) {
110-
if (!TextLineBase::readProperties(e))
110+
const QStringRef& tag(e.name());
111+
if (readStyledProperty(e, tag))
112+
;
113+
else if (!TextLineBase::readProperties(e))
111114
e.unknown();
112115
}
113116
}

libmscore/rest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ void Rest::write(XmlWriter& xml) const
968968
return;
969969
writeBeam(xml);
970970
xml.stag(this);
971+
writeStyledProperties(xml);
971972
ChordRest::writeProperties(xml);
972973
el().write(xml);
973974
bool write_dots = false;
@@ -1011,6 +1012,8 @@ void Rest::read(XmlReader& e)
10111012
dot->read(e);
10121013
add(dot);
10131014
}
1015+
else if (readStyledProperty(e, tag))
1016+
;
10141017
else if (ChordRest::readProperties(e))
10151018
;
10161019
else

libmscore/tuplet.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ void Tuplet::layout()
188188
_number->setVisible(visible());
189189
resetNumberProperty();
190190
}
191+
// tuplet properties are propagated to number automatically by setProperty()
192+
// but we need to make sure flags are as well
193+
_number->setPropertyFlags(Pid::FONT_FACE, propertyFlags(Pid::FONT_FACE));
194+
_number->setPropertyFlags(Pid::FONT_SIZE, propertyFlags(Pid::FONT_SIZE));
195+
_number->setPropertyFlags(Pid::FONT_STYLE, propertyFlags(Pid::FONT_STYLE));
196+
_number->setPropertyFlags(Pid::ALIGN, propertyFlags(Pid::ALIGN));
191197
if (_numberType == TupletNumberType::SHOW_NUMBER)
192198
_number->setXmlText(QString("%1").arg(_ratio.numerator()));
193199
else
@@ -783,7 +789,8 @@ void Tuplet::write(XmlWriter& xml) const
783789

784790
if (_number) {
785791
xml.stag("Number", _number);
786-
_number->writeProperties(xml);
792+
_number->writeProperty(xml, Pid::SUB_STYLE);
793+
_number->writeProperty(xml, Pid::TEXT);
787794
xml.etag();
788795
}
789796

@@ -821,19 +828,22 @@ bool Tuplet::readProperties(XmlReader& e)
821828
;
822829
else if (tag == "bold") { //important that these properties are read after number is created
823830
bool val = e.readInt();
824-
_number->setBold(val);
831+
if (_number)
832+
_number->setBold(val);
825833
if (isStyled(Pid::FONT_STYLE))
826834
setPropertyFlags(Pid::FONT_STYLE, PropertyFlags::UNSTYLED);
827835
}
828836
else if (tag == "italic") {
829837
bool val = e.readInt();
830-
_number->setItalic(val);
838+
if (_number)
839+
_number->setItalic(val);
831840
if (isStyled(Pid::FONT_STYLE))
832841
setPropertyFlags(Pid::FONT_STYLE, PropertyFlags::UNSTYLED);
833842
}
834843
else if (tag == "underline") {
835844
bool val = e.readInt();
836-
_number->setUnderline(val);
845+
if (_number)
846+
_number->setUnderline(val);
837847
if (isStyled(Pid::FONT_STYLE))
838848
setPropertyFlags(Pid::FONT_STYLE, PropertyFlags::UNSTYLED);
839849
}

libmscore/volta.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ void Volta::read(XmlReader& e)
149149
_endings.append(i);
150150
}
151151
}
152+
else if (readStyledProperty(e, tag))
153+
;
152154
else if (!readProperties(e))
153155
e.unknown();
154156
}

0 commit comments

Comments
 (0)