reimplement firstVisibleSysStaff and lastVisibleSysStaff to return int
Previosly, these functions returned the SysStaff itself, but there is no way to get the numeric index from that. The functions now return the numeric index, and their callers are adjusted to derived the SysStaff from that (if necessary, in one case the index was the goal all along).
This commit is contained in:
parent
1d56d5564b
commit
10b3da92db
2 changed files with 20 additions and 18 deletions
|
@ -162,7 +162,6 @@ Box* System::vbox() const
|
|||
SysStaff* System::insertStaff(int idx)
|
||||
{
|
||||
SysStaff* staff = new SysStaff;
|
||||
staff->idx = idx;
|
||||
if (idx) {
|
||||
// HACK: guess position
|
||||
staff->bbox().setY(_staves[idx-1]->y() + 6 * spatium());
|
||||
|
@ -1286,28 +1285,30 @@ qreal System::bottomDistance(int staffIdx, const SkylineLine& s) const
|
|||
// firstVisibleSysStaff
|
||||
//---------------------------------------------------------
|
||||
|
||||
SysStaff* System::firstVisibleSysStaff() const
|
||||
int System::firstVisibleSysStaff() const
|
||||
{
|
||||
for (SysStaff* s : _staves) {
|
||||
if (s->show())
|
||||
return s;
|
||||
int nstaves = _staves.size();
|
||||
for (int i = 0; i < nstaves; ++i) {
|
||||
if (_staves[i]->show())
|
||||
return i;
|
||||
}
|
||||
qDebug("no sys staff");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// lastVisibleSysStaff
|
||||
//---------------------------------------------------------
|
||||
|
||||
SysStaff* System::lastVisibleSysStaff() const
|
||||
int System::lastVisibleSysStaff() const
|
||||
{
|
||||
for (int i = _staves.size() - 1; i >= 0; --i) {
|
||||
int nstaves = _staves.size();
|
||||
for (int i = nstaves - 1; i >= 0; --i) {
|
||||
if (_staves[i]->show())
|
||||
return _staves[i];
|
||||
return i;
|
||||
}
|
||||
qDebug("no sys staff");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
@ -1317,7 +1318,8 @@ SysStaff* System::lastVisibleSysStaff() const
|
|||
|
||||
qreal System::minTop() const
|
||||
{
|
||||
SysStaff* s = firstVisibleSysStaff();
|
||||
int si = firstVisibleSysStaff();
|
||||
SysStaff* s = si < 0 ? nullptr : staff(si);
|
||||
if (s)
|
||||
return -s->skyline().north().max();
|
||||
return 0.0;
|
||||
|
@ -1332,7 +1334,8 @@ qreal System::minBottom() const
|
|||
{
|
||||
if (vbox())
|
||||
return vbox()->bottomGap();
|
||||
SysStaff* s = lastVisibleSysStaff();
|
||||
int si = lastVisibleSysStaff();
|
||||
SysStaff* s = si < 0 ? nullptr : staff(si);
|
||||
if (s)
|
||||
return s->skyline().south().max() - s->bbox().height();
|
||||
return 0.0;
|
||||
|
@ -1345,11 +1348,10 @@ qreal System::minBottom() const
|
|||
|
||||
qreal System::spacerDistance(bool up) const
|
||||
{
|
||||
SysStaff* ss = up ? firstVisibleSysStaff() : lastVisibleSysStaff();
|
||||
if (!ss)
|
||||
int staff = up ? firstVisibleSysStaff() : lastVisibleSysStaff();
|
||||
if (staff < 0)
|
||||
return 0.0;
|
||||
qreal dist = 0.0;
|
||||
int staff = ss->idx;
|
||||
for (MeasureBase* mb : measures()) {
|
||||
if (mb->isMeasure()) {
|
||||
Measure* m = toMeasure(mb);
|
||||
|
|
|
@ -51,7 +51,7 @@ class SysStaff {
|
|||
bool _show { true }; // derived from Staff or false if empty
|
||||
// staff is hidden
|
||||
public:
|
||||
int idx { 0 };
|
||||
//int idx { 0 };
|
||||
QList<InstrumentName*> instrumentNames;
|
||||
|
||||
const QRectF& bbox() const { return _bbox; }
|
||||
|
@ -89,8 +89,8 @@ class System final : public Element {
|
|||
mutable bool fixedDownDistance { false };
|
||||
qreal _distance; // temp. variable used during layout
|
||||
|
||||
SysStaff* firstVisibleSysStaff() const;
|
||||
SysStaff* lastVisibleSysStaff() const;
|
||||
int firstVisibleSysStaff() const;
|
||||
int lastVisibleSysStaff() const;
|
||||
|
||||
int getBracketsColumnsCount();
|
||||
void setBracketsXPosition(const qreal xOffset);
|
||||
|
|
Loading…
Reference in a new issue