Skip to content

Commit

Permalink
Merge pull request #6274 from Kartikay26/gsoc-2020-scanElements-refactor
Browse files Browse the repository at this point in the history
GSoC 2020: scanElements refactoring based on tree model [vtests]
  • Loading branch information
igorkorsukov authored Aug 11, 2020
2 parents 0638509 + a0ecbba commit b7007f3
Show file tree
Hide file tree
Showing 52 changed files with 431 additions and 408 deletions.
10 changes: 3 additions & 7 deletions libmscore/ambitus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,11 @@ void Ambitus::draw(QPainter* p) const
// scanElements
//---------------------------------------------------------

void Ambitus::scanElements(void* data, void (* func)(void*, Element*), bool /*all*/)
void Ambitus::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
Q_UNUSED(all);
ScoreElement::scanElements(data, func, all);
func(data, this);
if (_topAccid.accidentalType() != AccidentalType::NONE) {
func(data, &_topAccid);
}
if (_bottomAccid.accidentalType() != AccidentalType::NONE) {
func(data, &_bottomAccid);
}
}

//---------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions libmscore/barline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,10 +1519,8 @@ void BarLine::scanElements(void* data, void (* func)(void*, Element*), bool all)
if (width() == 0.0 && !all) {
return;
}
ScoreElement::scanElements(data, func, all);
func(data, this);
for (Element* e : _el) {
e->scanElements(data, func, all);
}
}

//---------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions libmscore/beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2708,4 +2708,17 @@ void Beam::startDrag(EditData& editData)
{
initBeamEditData(editData);
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void Beam::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
ChordRest* cr = toChordRest(treeParent());
if (!all && cr->measure()->stemless(cr->staffIdx())) {
return;
}
Element::scanElements(data, func, all);
}
}
2 changes: 2 additions & 0 deletions libmscore/beam.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class Beam final : public Element
ScoreElement* treeChild(int idx) const override;
int treeChildCount() const override;

void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

Beam* clone() const override { return new Beam(*this); }
ElementType type() const override { return ElementType::BEAM; }
QPointF pagePos() const override; ///< position in page coordinates
Expand Down
12 changes: 12 additions & 0 deletions libmscore/box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ void Box::layout()
}
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void Box::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
ScoreElement::scanElements(data, func, all);
if (all || visible() || score()->showInvisible()) {
func(data, this);
}
}

//---------------------------------------------------------
// computeMinWidth
//---------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions libmscore/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class Box : public MeasureBase

public:
Box(Score*);

void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

virtual void draw(QPainter*) const override;
virtual bool isEditable() const override { return true; }

Expand Down
12 changes: 0 additions & 12 deletions libmscore/bsymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,6 @@ void BSymbol::remove(Element* e)
}
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void BSymbol::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
func(data, this);
foreach (Element* e, _leafs) {
e->scanElements(data, func, all);
}
}

//---------------------------------------------------------
// acceptDrop
//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion libmscore/bsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class BSymbol : public Element

virtual void add(Element*) override;
virtual void remove(Element*) override;
virtual void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;
virtual bool acceptDrop(EditData&) const override;
virtual Element* drop(EditData&) override;
virtual void layout() override;
Expand Down
43 changes: 0 additions & 43 deletions libmscore/chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,49 +1229,6 @@ qreal Chord::centerX() const
return x;
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void Chord::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
for (Articulation* a : _articulations) {
func(data, a);
}
if (_hook) {
func(data, _hook);
}
if (_stem) {
func(data, _stem);
}
if (_stemSlash) {
func(data, _stemSlash);
}
if (_arpeggio) {
func(data, _arpeggio);
}
if (_tremolo && (tremoloChordType() != TremoloChordType::TremoloSecondNote)) {
func(data, _tremolo);
}
const Staff* st = staff();
if ((st && st->showLedgerLines(tick())) || !st) { // also for palette
for (LedgerLine* ll = _ledgerLines; ll; ll = ll->next()) {
func(data, ll);
}
}
size_t n = _notes.size();
for (size_t i = 0; i < n; ++i) {
_notes.at(i)->scanElements(data, func, all);
}
for (Chord* chord : _graceNotes) {
chord->scanElements(data, func, all);
}
for (Element* e : el()) {
e->scanElements(data, func, all);
}
ChordRest::scanElements(data, func, all);
}

//---------------------------------------------------------
// processSiblings
//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion libmscore/chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ class Chord final : public ChordRest
void setNoteType(NoteType t) { _noteType = t; }
bool isGrace() const { return _noteType != NoteType::NORMAL; }
void toGraceAfter();
void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

void setTrack(int val) override;

Expand Down
23 changes: 0 additions & 23 deletions libmscore/chordrest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,29 +119,6 @@ ChordRest::~ChordRest()
}
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void ChordRest::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
if (_beam && (_beam->elements().front() == this)
&& !measure()->stemless(staffIdx())) {
_beam->scanElements(data, func, all);
}
for (Lyrics* l : _lyrics) {
l->scanElements(data, func, all);
}
DurationElement* de = this;
while (de->tuplet() && de->tuplet()->elements().front() == de) {
de->tuplet()->scanElements(data, func, all);
de = de->tuplet();
}
if (_tabDur) {
func(data, _tabDur);
}
}

//---------------------------------------------------------
// writeProperties
//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion libmscore/chordrest.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class ChordRest : public DurationElement
virtual void writeProperties(XmlWriter& xml) const;
virtual bool readProperties(XmlReader&);
virtual void readAddConnector(ConnectorInfoReader* info, bool pasteMode) override;
virtual void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

void setBeamMode(Beam::Mode m) { _beamMode = m; }
void undoSetBeamMode(Beam::Mode m);
Expand Down
12 changes: 10 additions & 2 deletions libmscore/element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,20 @@ void Element::deleteLater()

//---------------------------------------------------------
// scanElements
/// If leaf node, apply `func` on this element (after checking if it is visible).
/// Otherwise, recurse over all children (see ScoreElement::scanElements).
/// Note: This function is overridden in some classes to skip certain children,
/// or to apply `func` even to non-leaf nodes.
//---------------------------------------------------------

void Element::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
if (all || visible() || score()->showInvisible()) {
func(data, this);
if (treeChildCount() == 0) {
if (all || visible() || score()->showInvisible()) {
func(data, this);
}
} else {
ScoreElement::scanElements(data, func, all);
}
}

Expand Down
2 changes: 1 addition & 1 deletion libmscore/element.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class Element : public ScoreElement

mutable bool itemDiscovered { false }; ///< helper flag for bsp

virtual void scanElements(void* data, void (* func)(void*, Element*), bool all=true);
void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

virtual void reset() override; // reset all properties & position to default

Expand Down
5 changes: 1 addition & 4 deletions libmscore/fret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,11 +1283,8 @@ Element* FretDiagram::drop(EditData& data)
void FretDiagram::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
Q_UNUSED(all);
ScoreElement::scanElements(data, func, all);
func(data, this);
// don't display harmony in palette
if (_harmony && !!parent()) {
func(data, _harmony);
}
}

//---------------------------------------------------------
Expand Down
15 changes: 0 additions & 15 deletions libmscore/glissando.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,6 @@ LineSegment* Glissando::createLineSegment()
return seg;
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void Glissando::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
func(data, this);
// don't scan segments belonging to systems; the systems themselves will scan them
for (SpannerSegment* seg : spannerSegments()) {
if (!seg->parent() || !seg->parent()->isSystem()) {
seg->scanElements(data, func, all);
}
}
}

//---------------------------------------------------------
// layout
//---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion libmscore/glissando.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Glissando final : public SLine
Glissando* clone() const override { return new Glissando(*this); }
ElementType type() const override { return ElementType::GLISSANDO; }
LineSegment* createLineSegment() override;
void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

void layout() override;
void write(XmlWriter&) const override;
void read(XmlReader&) override;
Expand Down
13 changes: 13 additions & 0 deletions libmscore/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2299,4 +2299,17 @@ Sid Harmony::getPropertyStyle(Pid pid) const
}
return TextBase::getPropertyStyle(pid);
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void Harmony::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
// don't display harmony in palette
if (!parent()) {
return;
}
func(data, this);
}
}
2 changes: 2 additions & 0 deletions libmscore/harmony.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class Harmony final : public TextBase
void setLeftParen(bool leftParen) { _leftParen = leftParen; }
void setRightParen(bool rightParen) { _rightParen = rightParen; }

void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

Harmony* findNext() const;
Harmony* findPrev() const;
Fraction ticksTilNext(bool stopAtMeasureEnd = false) const;
Expand Down
11 changes: 11 additions & 0 deletions libmscore/iname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,15 @@ QVariant InstrumentName::propertyDefault(Pid id) const
return TextBase::propertyDefault(id);
}
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void InstrumentName::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
if (all || sysStaff()->show()) {
func(data, this);
}
}
}
7 changes: 7 additions & 0 deletions libmscore/iname.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class InstrumentNameType : char {
};

class System;
class SysStaff;

//---------------------------------------------------------
// InstrumentName
Expand All @@ -30,6 +31,7 @@ class InstrumentName final : public TextBase
{
InstrumentNameType _instrumentNameType;
int _layoutPos { 0 };
SysStaff* _sysStaff { nullptr };

public:
InstrumentName(Score*);
Expand All @@ -47,6 +49,11 @@ class InstrumentName final : public TextBase

System* system() const { return toSystem(parent()); }

SysStaff* sysStaff() const { return _sysStaff; }
void setSysStaff(SysStaff* s) { _sysStaff = s; }

void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

Fraction playTick() const override;
bool isEditable() const override { return false; }
QVariant getProperty(Pid propertyId) const override;
Expand Down
13 changes: 13 additions & 0 deletions libmscore/ledgerline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ bool LedgerLine::readProperties(XmlReader& e)
}
return true;
}

//---------------------------------------------------------
// scanElements
//---------------------------------------------------------

void LedgerLine::scanElements(void* data, void (* func)(void*, Element*), bool all)
{
Staff* st = chord()->staff();
if (st && !st->showLedgerLines(tick())) {
return;
}
Element::scanElements(data, func, all);
}
}
2 changes: 2 additions & 0 deletions libmscore/ledgerline.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class LedgerLine final : public Element
QPointF pagePos() const override; ///< position in page coordinates
Chord* chord() const { return toChord(parent()); }

void scanElements(void* data, void (* func)(void*, Element*), bool all=true) override;

qreal len() const { return _len; }
qreal lineWidth() const { return _width; }
void setLen(qreal v) { _len = v; }
Expand Down
Loading

0 comments on commit b7007f3

Please sign in to comment.