Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mike-spa
Copy link
Contributor

@mike-spa mike-spa commented Nov 6, 2025

Prompted from this consideration, I took a closer look at the functions in scoretree.cpp, namely scanParent and scanChildren. As far as I could see, they were introduced for some score tree visualization feature back in version 3, but as far as I'm aware that feature doesn't exist in version 4. Everything about this is quite weird, because the parent and child relationships sometimes don't follow the true hierarchy of our model (ChordRests collect spanners among their children, Spanner collect SpannerSegment even though the parent of a SpannerSegment is always the System, scanParent sometimes returns an item that isn't the parent...). Most of these functions are either stale or are a copy of the corresponding scanElements method. The "source of truth" is obviously scanElements, cause that's what we use to determine what is drawn on screen.

This PR:

  • Removes all the scanParent and scanChildren functions, moving all the relevant functionality to scanElements
  • Introduces EngravingObject::getChildren, which collects the list of children using scanElements
  • Refactors scanElements using std::function instead of the old C-style function pointers. This makes everything nicer, especially avoiding all the void* pointers.
  • Removes from scanElements all the logic that had to do with showing or not showing the item on screen. The whole point of something like scanElement is that it doesn't know what func will do, so putting that logic in scanElement is an antipattern. Deciding whether or not to collect an element should be decided inside func itself.

@mike-spa mike-spa force-pushed the cleanupScanParentAndScanChildren branch from bd9297a to 84175c0 Compare November 6, 2025 16:59
--level;
}

void EngravingElementsProvider::dumpTreeTree(const mu::engraving::EngravingObject* obj, int& level)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's either delete these methods or fix them


if (r) {
assert(mode != Asyncable::Mode::SetOnce && "callback is already set");
//assert(mode != Asyncable::Mode::SetOnce && "callback is already set");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should perhaps not have been committed


std::vector<EngravingItem*> NotationElements::filterElements(const FilterElementsOptions* elementsOptions) const
{
ElementPattern* pattern = constructElementPattern(elementsOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it now also doesn't have to be a pointer anymore (that's leaked at the end of the function...)

}

return children;
EngravingItem::scanElements(func);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe StaffTextBase instead of EngravingItem, just to prevent surprises in the future

//---------------------------------------------------------

void Score::scanElementsInRange(void* data, void (* func)(void*, EngravingItem*), bool all)
void Score::scanElementsInRange(std::function<void(EngravingItem*)> func, bool includeInvisible)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning about includeInvisible being unused

#include "mscore.h"
#include "score.h"
#include "staff.h"
#include "stafflines.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these used?

}

static void findTextByType(void* data, mu::engraving::EngravingItem* element)
static void findTextByType(std::pair<TextStyleType, QStringList*>* typeStringsData, mu::engraving::EngravingItem* element)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static void findTextByType(std::pair<TextStyleType, QStringList*>* typeStringsData, mu::engraving::EngravingItem* element)
static void findTextByType(TextStyleType textStyleType, QStringList& strings, mu::engraving::EngravingItem* element)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants