core/qsmenu!: improve menu layout change UX

Exposes QsMenuOpener.children as an ObjectModel instead of a list to
allow smoother layout change handling in custom menu renderers.

Fixes QsMenuAnchor/platform menus closing whenever menu content changes.
This commit is contained in:
outfoxxed 2024-12-13 01:30:11 -08:00
parent 3fc1c914c7
commit a053373d57
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
7 changed files with 61 additions and 67 deletions

View file

@ -71,6 +71,22 @@ bool UntypedObjectModel::removeObject(const QObject* object) {
return true;
}
void UntypedObjectModel::diffUpdate(const QVector<QObject*>& newValues) {
for (qsizetype i = 0; i < this->valuesList.length();) {
if (newValues.contains(this->valuesList.at(i))) i++;
else this->removeAt(i);
}
qsizetype oi = 0;
for (auto* object: newValues) {
if (this->valuesList.length() == oi || this->valuesList.at(oi) != object) {
this->insertObject(object, oi);
}
oi++;
}
}
qsizetype UntypedObjectModel::indexOf(QObject* object) { return this->valuesList.indexOf(object); }
UntypedObjectModel* UntypedObjectModel::emptyInstance() {