add debug menu option to hightlight corrupted measures

This commit is contained in:
lasconic 2016-06-03 18:26:51 +02:00
parent 2f9658090f
commit ea736ea364
10 changed files with 92 additions and 29 deletions

View file

@ -178,6 +178,9 @@ bool Score::sanityCheck(const QString& name)
for (int staffIdx = 0; staffIdx < endStaff; ++staffIdx) {
Rest* fmrest0 = 0; // full measure rest in voice 0
Fraction voices[VOICES] = {};
#ifndef NDEBUG
m->mstaff(staffIdx)->_corrupted = false;
#endif
for (Segment* s = m->first(Segment::Type::ChordRest); s; s = s->next(Segment::Type::ChordRest)) {
for (int v = 0; v < VOICES; ++v) {
ChordRest* cr = toChordRest(s->element(staffIdx * VOICES + v));
@ -196,6 +199,9 @@ bool Score::sanityCheck(const QString& name)
QString msg = tr("Measure %1 Staff %2 incomplete. Expected: %3; Found: %4").arg(mNumber).arg( staffIdx+1).arg(mLen.print()).arg(voices[0].print());
qDebug() << msg;
error += QString("%1\n").arg(msg);
#ifndef NDEBUG
m->mstaff(staffIdx)->_corrupted = true;
#endif
result = false;
// try to fix a bad full measure rest
if (fmrest0) {
@ -210,6 +216,9 @@ bool Score::sanityCheck(const QString& name)
QString msg = tr("Measure %1, staff %2, voice %3 too long. Expected: %4; Found: %5").arg( mNumber).arg(staffIdx + 1).arg(v+1).arg(mLen.print()).arg(voices[v].print());
qDebug() << msg;
error += QString("%1\n").arg(msg);
#ifndef NDEBUG
m->mstaff(staffIdx)->_corrupted = true;
#endif
result = false;
}
}

View file

@ -3539,6 +3539,10 @@ void Score::doLayout()
// _mscVersion is used during read and first layout
// but then it's used for drag and drop and should be set to new version
_mscVersion = MSCVERSION; // for later drag & drop usage
#ifndef NDEBUG
if (MScore::showCorruptedMeasures)
sanityCheck();
#endif
}
//---------------------------------------------------------

View file

@ -100,6 +100,9 @@ MStaff::MStaff(const MStaff& m)
_vspacerDown = 0;
_visible = m._visible;
_slashStyle = m._slashStyle;
#ifndef NDEBUG
_corrupted = m._corrupted;
#endif
}
//---------------------------------------------------------

View file

@ -57,7 +57,9 @@ struct MStaff {
///< this changes some layout rules
bool _visible { true };
bool _slashStyle { false };
#ifndef NDEBUG
bool _corrupted { false };
#endif
MStaff() {}
~MStaff();
MStaff(const MStaff&);

View file

@ -68,6 +68,7 @@ bool MScore::showMeasureShapes = false;
bool MScore::noHorizontalStretch = false;
bool MScore::noVerticalStretch = false;
bool MScore::showBoundingRect = false;
bool MScore::showCorruptedMeasures = true;
// #endif
bool MScore::saveTemplateMode = false;

View file

@ -491,6 +491,7 @@ class MScore : public QObject {
static bool showSegmentShapes;
static bool showMeasureShapes;
static bool showBoundingRect;
static bool showCorruptedMeasures;
// #endif
static bool debugMode;
static bool testMode;

View file

@ -1070,7 +1070,7 @@ class Score : public QObject, public ScoreElement {
//@ ??
Q_INVOKABLE void cropPage(qreal margins);
bool sanityCheck(const QString& name);
bool sanityCheck(const QString& name = QString());
bool checkKeys();
bool checkClefs();

View file

@ -1093,6 +1093,10 @@ MuseScore::MuseScore()
a = getAction("show-bounding-rect");
a->setCheckable(true);
menuDebug->addAction(a);
a = getAction("show-corrupted-measures");
a->setCheckable(true);
a->setChecked(true);
menuDebug->addAction(a);
#endif
//---------------------
@ -4695,6 +4699,13 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
cs->update();
}
}
else if (cmd == "show-corrupted-measures") {
MScore::showCorruptedMeasures = a->isChecked();
if (cs) {
cs->setLayoutAll();
cs->update();
}
}
#endif
else {
if (cv) {

View file

@ -1929,40 +1929,62 @@ void ScoreView::paint(const QRect& r, QPainter& p)
drawElements(p, ell);
#ifndef NDEBUG
if (MScore::showSegmentShapes) {
for (const System* system : page->systems()) {
for (const MeasureBase* mb : system->measures()) {
if (mb->type() == Element::Type::MEASURE) {
const Measure* m = static_cast<const Measure*>(mb);
p.setBrush(Qt::NoBrush);
p.setPen(QPen(QBrush(Qt::darkYellow), 0.5));
for (const Segment* s = m->first(); s; s = s->next()) {
for (int i = 0; i < score()->nstaves(); ++i) {
QPointF pt(s->pos().x() + m->pos().x() + system->pos().x(),
system->staffYpage(i));
if (!score()->printing()) {
if (MScore::showSegmentShapes) {
for (const System* system : page->systems()) {
for (const MeasureBase* mb : system->measures()) {
if (mb->type() == Element::Type::MEASURE) {
const Measure* m = static_cast<const Measure*>(mb);
p.setBrush(Qt::NoBrush);
p.setPen(QPen(QBrush(Qt::darkYellow), 0.5));
for (const Segment* s = m->first(); s; s = s->next()) {
for (int i = 0; i < score()->nstaves(); ++i) {
QPointF pt(s->pos().x() + m->pos().x() + system->pos().x(),
system->staffYpage(i));
p.translate(pt);
s->shapes().at(i).draw(&p);
p.translate(-pt);
}
}
}
}
}
}
if (MScore::showMeasureShapes) {
for (const System* system : page->systems()) {
for (const MeasureBase* mb : system->measures()) {
if (mb->type() == Element::Type::MEASURE) {
const Measure* m = static_cast<const Measure*>(mb);
p.setPen(Qt::NoPen);
p.setBrush(QBrush(QColor(0, 0, 255, 60)));
for (int staffIdx = 0; staffIdx < score()->nstaves(); ++staffIdx) {
const MStaff* ms = m->mstaff(staffIdx);
QPointF pt(m->pos().x() + system->pos().x(), 0);
p.translate(pt);
s->shapes().at(i).draw(&p);
QPointF o(0.0, m->system()->staffYpage(staffIdx));
ms->shape().translated(o).draw(&p);
p.translate(-pt);
}
}
}
}
}
}
if (MScore::showMeasureShapes) {
for (const System* system : page->systems()) {
for (const MeasureBase* mb : system->measures()) {
if (mb->type() == Element::Type::MEASURE) {
const Measure* m = static_cast<const Measure*>(mb);
p.setPen(Qt::NoPen);
p.setBrush(QBrush(QColor(0, 0, 255, 60)));
for (int staffIdx = 0; staffIdx < score()->nstaves(); ++staffIdx) {
const MStaff* ms = m->mstaff(staffIdx);
QPointF pt(m->pos().x() + system->pos().x(), 0);
p.translate(pt);
QPointF o(0.0, m->system()->staffYpage(staffIdx));
ms->shape().translated(o).draw(&p);
p.translate(-pt);
if (MScore::showCorruptedMeasures) {
double _spatium = score()->spatium();
QPen pen;
pen.setColor(Qt::red);
pen.setWidthF(1);
pen.setStyle(Qt::SolidLine);
p.setPen(pen);
for (const System* system : page->systems()) {
for (const MeasureBase* mb : system->measures()) {
if (mb->type() == Element::Type::MEASURE) {
const Measure* m = static_cast<const Measure*>(mb);
for (int staffIdx = 0; staffIdx < _score->nstaves(); staffIdx++) {
if (m->mstaff(staffIdx)->_corrupted) {
p.drawRect(m->staffabbox(staffIdx).adjusted(0, -_spatium, 0, _spatium));
}
}
}
}
}

View file

@ -3408,6 +3408,16 @@ Shortcut Shortcut::_sc[] = {
0,
Icons::Invalid_ICON,
Qt::ApplicationShortcut
},
{
MsWidget::MAIN_WINDOW,
STATE_ALL,
"show-corrupted-measures",
QT_TRANSLATE_NOOP("action","Show Corrupted Measures"),
QT_TRANSLATE_NOOP("action","Show corrupted measures"),
0,
Icons::Invalid_ICON,
Qt::ApplicationShortcut
}
#endif
};