fix #107001: Adding measures can crash musescore
This commit is contained in:
parent
a8f4421ee2
commit
d789e2e691
3 changed files with 37 additions and 37 deletions
|
@ -1450,24 +1450,23 @@ qreal Score::cautionaryWidth(Measure* m, bool& hasCourtesy)
|
|||
|
||||
void Score::hideEmptyStaves(System* system, bool isFirstSystem)
|
||||
{
|
||||
//
|
||||
// hide empty staves
|
||||
//
|
||||
int staves = _staves.size();
|
||||
int staves = _staves.size();
|
||||
int staffIdx = 0;
|
||||
bool systemIsEmpty = true;
|
||||
|
||||
foreach (Staff* staff, _staves) {
|
||||
SysStaff* s = system->staff(staffIdx);
|
||||
bool oldShow = s->show();
|
||||
for (Staff* staff : _staves) {
|
||||
SysStaff* ss = system->staff(staffIdx);
|
||||
// bool oldShow = ss->show();
|
||||
|
||||
Staff::HideMode hideMode = staff->hideWhenEmpty();
|
||||
|
||||
if (hideMode == Staff::HideMode::ALWAYS
|
||||
|| (styleB(StyleIdx::hideEmptyStaves)
|
||||
&& (staves > 1)
|
||||
&& !(isFirstSystem && styleB(StyleIdx::dontHideStavesInFirstSystem))
|
||||
&& hideMode != Staff::HideMode::NEVER)) {
|
||||
bool hideStaff = true;
|
||||
foreach(MeasureBase* m, system->measures()) {
|
||||
for (MeasureBase* m : system->measures()) {
|
||||
if (!m->isMeasure())
|
||||
continue;
|
||||
Measure* measure = toMeasure(m);
|
||||
|
@ -1507,35 +1506,41 @@ void Score::hideEmptyStaves(System* system, bool isFirstSystem)
|
|||
break;
|
||||
}
|
||||
}
|
||||
s->setShow(hideStaff ? false : staff->show());
|
||||
if (s->show()) {
|
||||
ss->setShow(hideStaff ? false : staff->show());
|
||||
if (ss->show())
|
||||
systemIsEmpty = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
systemIsEmpty = false;
|
||||
s->setShow(true);
|
||||
ss->setShow(true);
|
||||
}
|
||||
|
||||
if (oldShow != s->show()) {
|
||||
#if 0
|
||||
if (oldShow != s->show()) {
|
||||
foreach (MeasureBase* mb, system->measures()) {
|
||||
if (!mb->isMeasure())
|
||||
continue;
|
||||
static_cast<Measure*>(mb)->createEndBarLines();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
++staffIdx;
|
||||
}
|
||||
if (systemIsEmpty) {
|
||||
foreach (Staff* staff, _staves) {
|
||||
SysStaff* s = system->staff(staff->idx());
|
||||
if (staff->showIfEmpty() && !s->show()) {
|
||||
s->setShow(true);
|
||||
for (Staff* staff : _staves) {
|
||||
SysStaff* ss = system->staff(staff->idx());
|
||||
if (staff->showIfEmpty() && !ss->show()) {
|
||||
ss->setShow(true);
|
||||
systemIsEmpty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// dont allow a complete empty system
|
||||
if (systemIsEmpty) {
|
||||
Staff* staff = _staves.front();
|
||||
SysStaff* ss = system->staff(staff->idx());
|
||||
ss->setShow(true);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -46,17 +46,6 @@
|
|||
|
||||
namespace Ms {
|
||||
|
||||
//---------------------------------------------------------
|
||||
// SysStaff
|
||||
//---------------------------------------------------------
|
||||
|
||||
SysStaff::SysStaff()
|
||||
{
|
||||
_yOff = 0.0;
|
||||
idx = 0;
|
||||
_show = true;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// ~SysStaff
|
||||
//---------------------------------------------------------
|
||||
|
@ -350,6 +339,7 @@ void System::layout2()
|
|||
for (int i = 0; i < _staves.size(); ++i) {
|
||||
Staff* s = score()->staff(i);
|
||||
SysStaff* ss = _staves[i];
|
||||
//DEBUG ss->setShow(true);
|
||||
if (s->show() && ss->show()) {
|
||||
visibleStaves.append(std::pair<int,SysStaff*>(i, ss));
|
||||
if (firstStaffIdx == -1)
|
||||
|
@ -362,8 +352,9 @@ void System::layout2()
|
|||
lastStaffInitialIdx = i;
|
||||
}
|
||||
}
|
||||
else
|
||||
else {
|
||||
ss->setbbox(QRectF()); // already done in layout() ?
|
||||
}
|
||||
}
|
||||
if (firstStaffIdx == -1)
|
||||
firstStaffIdx = 0;
|
||||
|
@ -376,7 +367,11 @@ void System::layout2()
|
|||
qreal staffDistance = score()->styleP(StyleIdx::staffDistance);
|
||||
qreal akkoladeDistance = score()->styleP(StyleIdx::akkoladeDistance);
|
||||
|
||||
Q_ASSERT(!visibleStaves.empty());
|
||||
if (visibleStaves.empty()) {
|
||||
printf("====no visible staves, staves %d, score staves %d\n", _staves.size(), score()->nstaves());
|
||||
}
|
||||
|
||||
// Q_ASSERT(!visibleStaves.empty());
|
||||
|
||||
for (auto i = visibleStaves.begin();; ++i) {
|
||||
SysStaff* ss = i->second;
|
||||
|
|
|
@ -44,12 +44,12 @@ class BarLine;
|
|||
//---------------------------------------------------------
|
||||
|
||||
class SysStaff {
|
||||
QRectF _bbox; ///< Bbox of StaffLines.
|
||||
qreal _yOff { 0 }; ///< offset of top staff line within bbox
|
||||
bool _show { true }; ///< derived from Staff or false if empty
|
||||
///< staff is hidden
|
||||
QRectF _bbox; // Bbox of StaffLines.
|
||||
qreal _yOff { 0 }; // offset of top staff line within bbox
|
||||
bool _show { true }; // derived from Staff or false if empty
|
||||
// staff is hidden
|
||||
public:
|
||||
int idx;
|
||||
int idx { 0 };
|
||||
QList<InstrumentName*> instrumentNames;
|
||||
|
||||
const QRectF& bbox() const { return _bbox; }
|
||||
|
@ -61,7 +61,7 @@ class SysStaff {
|
|||
bool show() const { return _show; }
|
||||
void setShow(bool v) { _show = v; }
|
||||
|
||||
SysStaff();
|
||||
SysStaff() {}
|
||||
~SysStaff();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue