Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid rebuilding models for ListQuantityGroup and ListTextGroup #1903

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

blammit
Copy link
Contributor

@blammit blammit commented Feb 13, 2025

No description provided.

QuantityObject provides QObject-based access to a quantity value.
QuantityObjectModel provides a model of QuantityObject values, and
is able to filter out items that do not have valid values.

This allows ListQuantityGroup and its derived types to specify their
models without creating a JavaScript array that directly refers each
quantity value. Otherwise, whenever a quantity value is updated, the
entire array is rebuilt, which in turn causes the QuantityRow repeater
to rebuild its delegates.

Part of #1338
@blammit blammit force-pushed the blam/1338-avoid-rebuilding-models-for-listquantitygroup-and-listtextgroup branch from 0f77dbd to fd51a61 Compare February 13, 2025 04:17
id: busOffCounters
}
content.children: [
ColumnLayout {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't normally reach for a layout - did you mean to use ColumnLayout deliberately over Column? Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, the ColumnLayout was from WIP code so I've reverted it to a Column, as there aren't any particular benefits here from using the layout.


int main(int argc, char **argv) \
{
qmlRegisterType<Victron::VenusOS::QuantityObject>("Victron.VenusOS", 2, 0, "QuantityObject");
Copy link
Contributor

Choose a reason for hiding this comment

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

These (and in other tests) would not be needed if the test executable was correctly linked to the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would be worth cleaning that up, as a separate task

import Victron.VenusOS
import QtQuick.Window

TestCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

does the test cover the append/remove cases or are they not applicable because of the usage of QQmlListProperty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, not applicable as you said. We can have add/remove support in QuantityObjectModel in the future if needed.

Change QuantityRow's model type to QuantityObjectModel, so that the
model cannot be specified as an array of real values, and update the
codebase accordingly so that it always uses QuantityObject with
QuantityObjectModel instead of an array-based model in all cases where
multiple quantities are displayed.

This greatly improves the performance of QuantityRow in updating its
values, as the Repeater no longer rebuilds its delegates whenever a
single quantity changes in the model.

Also, since QuantityObjectModel is able to filter out invalid values,
it is not necessary to create and show separate models depending on
whether particular values are valid.

The updates affect the following types and their uses:
- QuantityRow
- ListQuantityGroup
- ListQuantityGroupNavigation

Also remove ListTextGroup and replace its uses with ListQuantityGroup,
as ListTextGroup was being used to show text alongside number values,
and that can now easily be done with ListQuantityGroup as a
QuantityObject value can be a string if the unit is Units_None.

Part of #1338
@blammit blammit force-pushed the blam/1338-avoid-rebuilding-models-for-listquantitygroup-and-listtextgroup branch from fd51a61 to 777b93f Compare February 14, 2025 01:08
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.

Avoid rebuilding models for ListQuantityGroup and ListTextGroup
2 participants