Skip to content

Commit

Permalink
fix #251451 Crash when trying to add staff text to multimeasure rests
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Apr 18, 2018
1 parent 47dd401 commit 72950fc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libmscore/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static constexpr PropertyMetaData propertyList[] = {
{ Pid::SCALE, "scale", false, "scale", P_TYPE::SCALE },
{ Pid::LOCK_ASPECT_RATIO, "lock_aspect_ratio", false, "lockAspectRatio", P_TYPE::BOOL },
{ Pid::SIZE_IS_SPATIUM, "size_is_spatium", false, "sizeIsSpatium", P_TYPE::BOOL },
{ Pid::TEXT, "text", false, 0, P_TYPE::STRING },
{ Pid::TEXT, "text", true, 0, P_TYPE::STRING },
{ Pid::HTML_TEXT, "html_text", false, 0, P_TYPE::STRING },
{ Pid::USER_MODIFIED, "user_modified", false, 0, P_TYPE::BOOL },
{ Pid::BEAM_POS, "beam_pos", false, 0, P_TYPE::POINT },
Expand Down
7 changes: 4 additions & 3 deletions libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ Measure* Score::pos2measure(const QPointF& p, int* rst, int* pitch, Segment** se
System* s = m->system();
qreal y = p.y() - s->canvasPos().y();

int i;
for (i = 0; i < nstaves();) {
int i = 0;
for (; i < nstaves();) {
SysStaff* stff = s->staff(i);
if (!stff->show() || !staff(i)->show()) {
++i;
Expand Down Expand Up @@ -537,7 +537,8 @@ Measure* Score::pos2measure(const QPointF& p, int* rst, int* pitch, Segment** se
int strack = i * VOICES;
if (!staff(i))
return 0;
int etrack = staff(i)->part()->nstaves() * VOICES + strack;
// int etrack = staff(i)->part()->nstaves() * VOICES + strack;
int etrack = VOICES + strack;

SysStaff* sstaff = m->system()->staff(i);
SegmentType st = SegmentType::ChordRest;
Expand Down
2 changes: 2 additions & 0 deletions libmscore/stafftext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ QVariant StaffText::propertyDefault(Pid id) const
return int(SubStyleId::STAFF);
case Pid::PLACEMENT:
return int(Placement::ABOVE);
case Pid::FRAME:
return false;
default:
return TextBase::propertyDefault(id);
}
Expand Down
5 changes: 5 additions & 0 deletions libmscore/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2708,6 +2708,11 @@ QVariant TextBase::propertyDefault(Pid id) const
v = QString();
break;
default:
// to allow "uncomplete" substyles, fallback to default style
for (const StyledProperty& p : subStyle(SubStyleId::DEFAULT)) {
if (p.pid == id)
return score()->styleV(p.sid);
}
v = Element::propertyDefault(id);
break;
}
Expand Down
12 changes: 11 additions & 1 deletion mscore/editelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,19 @@ void ScoreView::endEdit()
figuredBassEndEdit();
else if (editData.element->isText()) {
Text* text = toText(editData.element);
if (text->links()) {
// TextEditData* ted = static_cast<TextEditData*>(ed.getData(text));
for (ScoreElement* se : *text->links()) {
Text* lt = toText(se);
if (lt != text) {
printf("update link");
lt->setXmlText(text->xmlText());
}
}
}
// remove text if empty
// dont do this for TBOX
if (text->empty() && text->parent() && text->parent()->type() != ElementType::TBOX)
if (text->empty() && text->parent() && !text->parent()->isTBox())
_score->undoRemoveElement(text);
}
#if 0
Expand Down
19 changes: 17 additions & 2 deletions mscore/scoreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,7 @@ void ScoreView::cmdAddText(TEXT type)
changeState(ViewState::NORMAL);

TextBase* s = 0;
TextBase* es = 0;
_score->startCmd();
switch(type) {
case TEXT::TITLE:
Expand Down Expand Up @@ -3733,8 +3734,21 @@ void ScoreView::cmdAddText(TEXT type)
if (!cr)
break;
s = new StaffText(SubStyleId::STAFF, _score);
Segment* parent = 0;
if (cr->segment()->measure()->isMMRest()) { // mm hack
printf("add to mmrest\n");
Measure* m = cr->segment()->measure()->mmRestFirst();
parent = m->findSegmentR(SegmentType::ChordRest, 0);
es = new StaffText(SubStyleId::STAFF, _score);
es->setTrack(cr->track());
es->setParent(cr->segment());
_score->addElement(es);
s->linkTo(es);
}
else
parent = cr->segment();
s->setTrack(cr->track());
s->setParent(cr->segment());
s->setParent(parent);
}
break;
case TEXT::SYSTEM:
Expand Down Expand Up @@ -3785,7 +3799,8 @@ void ScoreView::cmdAddText(TEXT type)
_score->undoAddElement(s);
_score->select(s, SelectType::SINGLE, 0);
_score->endCmd();
startEditMode(s);
s->layout();
startEditMode(es ? es : s);
}
else
_score->endCmd();
Expand Down

0 comments on commit 72950fc

Please sign in to comment.