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

Add VisibleItemModel #1845

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

Add VisibleItemModel #1845

wants to merge 2 commits into from

Conversation

blammit
Copy link
Contributor

@blammit blammit commented Jan 15, 2025

No description provided.

src/visibleitemmodel.h Outdated Show resolved Hide resolved
}
}
*/
class VisibleItemModel : public QQmlInstanceModel
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking - what's the general policy of using private APIs? e.g. when we bump from Qt 6.6.3 > Qt 6.8 what source compatibility are we relying on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally we want to use the more established kind of private APIs, so that the instability is kept to a minimum, and only using them where absolutely necessary.

Copy link
Contributor

@DanielMcInnes DanielMcInnes Jan 16, 2025

Choose a reason for hiding this comment

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

Is there a reason why we can't use a public qt base model? eg. QAbstractItemModel

src/visibleitemmodel.cpp Show resolved Hide resolved
src/visibleitemmodel.cpp Outdated Show resolved Hide resolved
This allows items with preferredVisible=false to be filtered out
from the model for a ListView. Otherwise, the view creates unused
delegates, which are redundant and also will be problematic when
key navigation is added as the user should not navigate through
non-visible items.

Part of #1732
VisibleItemModel automatically filters out non-visible items so that
they are not part of any view that uses the model.

This means that:
- views won't need to create unnecessary delegates
- when key navigation is added, it won't try to focus non-visible
delegates

VisibleItemModel does not currently support dynamic insertion/removal
so it cannot be used in cases like SwipePageModel or
NotificationLayer.

Part of #1732
@blammit blammit force-pushed the blam/visible-item-model branch from 3bc5d92 to 88d7521 Compare January 16, 2025 02:44
Q_OBJECT
Q_DECLARE_PRIVATE(VisibleItemModel)

Q_PROPERTY(QQmlListProperty<QObject> sourceModel READ sourceModel NOTIFY sourceModelChanged DESIGNABLE false FINAL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does 'design mode' work for you? As long as I can remember, the 'design mode' button has been greyed out for me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The DESIGNABLE probably isn't necessary, it came from a copy-paste.

}
}
*/
class VisibleItemModel : public QQmlInstanceModel
Copy link
Contributor

@DanielMcInnes DanielMcInnes Jan 16, 2025

Choose a reason for hiding this comment

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

Is there a reason why we can't use a public qt base model? eg. QAbstractItemModel

@blammit
Copy link
Contributor Author

blammit commented Jan 16, 2025

Is there a reason why we can't use a public qt base model? eg. QAbstractItemModel

It needs to be a QQmlInstanceModel so that it can provide instances directly, unlike QAbstractItemModel. The QtQuick views have built-in behaviour to treat instance models differently; it can fetch delegate instances directly from the model, whereas when it uses a QAbstractItemModel, it will instantiate delegate instances instead.

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.

3 participants