Skip to content

Commit

Permalink
fix #25250 new staff flag showIfSystemEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Aug 6, 2014
1 parent c9283f7 commit 567dc89
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 24 deletions.
15 changes: 14 additions & 1 deletion libmscore/layout.cpp
Expand Up @@ -10,7 +10,6 @@
// the file LICENCE.GPL
//=============================================================================

// #include <fenv.h>
#include "page.h"
#include "sig.h"
#include "key.h"
Expand Down Expand Up @@ -2069,6 +2068,8 @@ void Score::hideEmptyStaves(System* system, bool isFirstSystem)
//
int staves = _staves.size();
int staffIdx = 0;
bool systemIsEmpty = true;

foreach (Staff* staff, _staves) {
SysStaff* s = system->staff(staffIdx);
bool oldShow = s->show();
Expand Down Expand Up @@ -2119,8 +2120,12 @@ void Score::hideEmptyStaves(System* system, bool isFirstSystem)
}
}
s->setShow(hideStaff ? false : staff->show());
if (s->show()) {
systemIsEmpty = false;
}
}
else {
systemIsEmpty = false;
s->setShow(true);
}

Expand All @@ -2133,6 +2138,14 @@ void Score::hideEmptyStaves(System* system, bool isFirstSystem)
}
++staffIdx;
}
if (systemIsEmpty) {
foreach (Staff* staff, _staves) {
SysStaff* s = system->staff(staff->idx());
if (staff->showIfEmpty() && !s->show()) {
s->setShow(true);
}
}
}
}

//---------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions libmscore/staff.cpp
Expand Up @@ -428,6 +428,8 @@ void Staff::write(Xml& xml) const
xml.tag("invisible", invisible());
if (neverHide())
xml.tag("neverHide", neverHide());
if (showIfEmpty())
xml.tag("showIfSystemEmpty", showIfEmpty());

foreach(const BracketItem& i, _brackets)
xml.tagE("bracket type=\"%d\" span=\"%d\"", i._bracket, i._bracketSpan);
Expand Down Expand Up @@ -489,6 +491,8 @@ void Staff::read(XmlReader& e)
setInvisible(e.readInt());
else if (tag == "neverHide")
setNeverHide(e.readInt());
else if (tag == "showIfSystemEmpty")
setShowIfEmpty(e.readInt());
else if (tag == "keylist")
_keys.read(e, _score);
else if (tag == "bracket") {
Expand Down
5 changes: 4 additions & 1 deletion libmscore/staff.h
Expand Up @@ -101,7 +101,8 @@ class Staff : public QObject {
int _barLineTo; ///< line of end staff to draw the bar line to (0= staff top line, ...)
bool _small { false };
bool _invisible { false };
bool _neverHide { false };
bool _neverHide { false }; ///< always show this staff, even if empty and hideEmptyStaves is true
bool _showIfEmpty { false }; ///< show this staff if system is empty and hideEmptyStaves is true
QColor _color { MScore::defaultColor };
qreal _userDist { 0.0 }; ///< user edited extra distance

Expand Down Expand Up @@ -174,6 +175,8 @@ class Staff : public QObject {
void setInvisible(bool val) { _invisible = val; }
bool neverHide() const { return _neverHide; }
void setNeverHide(bool val) { _neverHide = val; }
bool showIfEmpty() const { return _showIfEmpty; }
void setShowIfEmpty(bool val) { _showIfEmpty = val; }

void setSlashStyle(bool val);
int lines() const;
Expand Down
40 changes: 22 additions & 18 deletions libmscore/undo.cpp
Expand Up @@ -2326,14 +2326,15 @@ void ChangePageFormat::flip()
//---------------------------------------------------------

ChangeStaff::ChangeStaff(Staff* _staff, bool _small, bool _invisible,
qreal _userDist, QColor _color, bool _neverHide)
qreal _userDist, QColor _color, bool _neverHide, bool _showIfEmpty)
{
staff = _staff;
small = _small;
invisible = _invisible;
userDist = _userDist;
color = _color;
neverHide = _neverHide;
staff = _staff;
small = _small;
invisible = _invisible;
userDist = _userDist;
color = _color;
neverHide = _neverHide;
showIfEmpty = _showIfEmpty;
}

//---------------------------------------------------------
Expand All @@ -2355,23 +2356,26 @@ void ChangeStaff::flip()
{
bool invisibleChanged = staff->invisible() != invisible;

int oldSmall = staff->small();
bool oldInvisible = staff->invisible();
qreal oldUserDist = staff->userDist();
QColor oldColor = staff->color();
bool oldNeverHide = staff->neverHide();
int oldSmall = staff->small();
bool oldInvisible = staff->invisible();
qreal oldUserDist = staff->userDist();
QColor oldColor = staff->color();
bool oldNeverHide = staff->neverHide();
bool oldShowIfEmpty = staff->showIfEmpty();

staff->setSmall(small);
staff->setInvisible(invisible);
staff->setUserDist(userDist);
staff->setColor(color);
staff->setNeverHide(neverHide);

small = oldSmall;
invisible = oldInvisible;
userDist = oldUserDist;
color = oldColor;
neverHide = oldNeverHide;
staff->setShowIfEmpty(showIfEmpty);

small = oldSmall;
invisible = oldInvisible;
userDist = oldUserDist;
color = oldColor;
neverHide = oldNeverHide;
showIfEmpty = oldShowIfEmpty;

Score* score = staff->score();
if (invisibleChanged) {
Expand Down
3 changes: 2 additions & 1 deletion libmscore/undo.h
Expand Up @@ -722,11 +722,12 @@ class ChangeStaff : public UndoCommand {
qreal userDist;
QColor color;
bool neverHide;
bool showIfEmpty;

void flip();

public:
ChangeStaff(Staff*, bool small, bool invisible, qreal userDist, QColor _color, bool _neverHide);
ChangeStaff(Staff*, bool small, bool invisible, qreal userDist, QColor _color, bool _neverHide, bool _showIfEmpty);
UNDO_NAME("ChangeStaff")
};

Expand Down
9 changes: 7 additions & 2 deletions mscore/editstaff.cpp
Expand Up @@ -62,6 +62,7 @@ EditStaff::EditStaff(Staff* s, QWidget* parent)
staff->setStaffType(orgStaff->staffType());
staff->setPart(part);
staff->setNeverHide(orgStaff->neverHide());
staff->setShowIfEmpty(orgStaff->showIfEmpty());

// hide string data controls if instrument has no strings
stringDataFrame->setVisible(instrument.stringData() && instrument.stringData()->strings() > 0);
Expand All @@ -72,6 +73,7 @@ EditStaff::EditStaff(Staff* s, QWidget* parent)
color->setColor(s->color());
partName->setText(part->partName());
neverHide->setChecked(staff->neverHide());
showIfEmpty->setChecked(staff->showIfEmpty());

updateStaffType();
updateInstrument();
Expand Down Expand Up @@ -235,6 +237,7 @@ void EditStaff::apply()
qreal userDist = spinExtraDistance->value();
QColor col = color->color();
bool nhide = neverHide->isChecked();
bool ifEmpty = showIfEmpty->isChecked();

if (!(instrument == *part->instr()) || part->partName() != partName->text()) {
Interval v1 = instrument.transpose();
Expand All @@ -252,8 +255,10 @@ void EditStaff::apply()
|| userDist != staff->userDist()
|| col != staff->color()
|| nhide != staff->neverHide()
)
score->undo(new ChangeStaff(orgStaff, s, inv, userDist * score->spatium(), col, nhide));
|| ifEmpty != staff->showIfEmpty()
) {
score->undo(new ChangeStaff(orgStaff, s, inv, userDist * score->spatium(), col, nhide, ifEmpty));
}

if ( !(*orgStaff->staffType() == *staff->staffType()) ) {
// updateNeeded |= (orgStaff->staffGroup() == StaffGroup::TAB || staff->staffGroup() == StaffGroup::TAB);
Expand Down
9 changes: 8 additions & 1 deletion mscore/editstaff.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>893</width>
<height>583</height>
<height>603</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -826,6 +826,13 @@
</item>
</layout>
</item>
<item row="0" column="2">
<widget class="QCheckBox" name="showIfEmpty">
<property name="text">
<string>Do not hide if system is empty</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit 567dc89

Please sign in to comment.