QIviPagingModel Class

The QIviPagingModel is a generic model to load its data using the "Paging" aproach. More...

Header: #include <QIviPagingModel>
qmake: QT += ivicore
Instantiated By: PagingModel
Inherits: QIviAbstractFeatureListModel
Inherited By:

QIviSearchAndBrowseModel

Public Types

enum LoadingType { FetchMore, DataChanged }
enum Roles { NameRole, TypeRole, ItemRole }

Properties

Public Functions

QIviPagingModel(QObject *parent = nullptr)
T at(int i) const
QtIviCoreModule::ModelCapabilities capabilities() const
int chunkSize() const
int fetchMoreThreshold() const
QVariant get(int i) const
QIviPagingModel::LoadingType loadingType() const
void reload()
void setChunkSize(int chunkSize)
void setFetchMoreThreshold(int fetchMoreThreshold)
void setLoadingType(QIviPagingModel::LoadingType loadingType)

Reimplemented Public Functions

virtual bool canFetchMore(const QModelIndex &parent) const override
virtual QVariant data(const QModelIndex &index, int role) const override
virtual void fetchMore(const QModelIndex &parent) override
virtual QHash<int, QByteArray> roleNames() const override
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override

Signals

void capabilitiesChanged(QtIviCoreModule::ModelCapabilities capabilities)
void chunkSizeChanged(int chunkSize)
void countChanged()
void fetchMoreThresholdChanged(int fetchMoreThreshold)
void fetchMoreThresholdReached() const
void loadingTypeChanged(QIviPagingModel::LoadingType loadingType)

Reimplemented Protected Functions

virtual void clearServiceObject() override
virtual void connectToServiceObject(QIviServiceObject *serviceObject) override
virtual void disconnectFromServiceObject(QIviServiceObject *serviceObject) override

Detailed Description

The QIviPagingModel should be used directly or as a base class whenever a lot of data needs to be presented in a ListView.

The model only fetches the data it really needs and can it can be configured how this can be done using the loadingType property.

The backend filling the model with data needs to implement the QIviPagingModelInterface class.

Setting it up

The QIviPagingModel is using QtIviCore's Dynamic Backend System and is derived from QIviAbstractFeatureListModel. Other than most "QtIvi Feature classes", the QIviPagingModel doesn't automatically connect to available backends.

The easiest approach to set it up, is to connect to the same backend used by another feature. E.g. for connecting to the media backend, use the instance from the mediaplayer feature:

QIviMediaPlayer *player = new QIviMediaPlayer();
player->startAutoDiscovery();
QIviPagingModel *model = new QIviPagingModel();
model->setServiceObject(player->serviceObject());

Loading Types

Multiple loading types are supported, as the QIviPagingModel is made to work with asynchronous requests to fetch its data. The FetchMore loading type is the default and is using the canFetchMore()/fetchMore() functions of QAbstractItemModel to fetch new data once the view hits the end of the currently available data. As fetching can take some time, there is the fetchMoreThreshold property which controls how much in advance a new fetch should be started.

The other loading type is DataChanged. In contrast to FetchMore, the complete model is pre-populated with empty rows and the actual data for a specific row is fetched the first time the data() function is called. Once the data is available, the dataChanged() signal will be triggered for this row and the view will start to render the new data.

Please see the documentation of LoadingType for more details on how the modes work and when they are suitable to use.

See the Models section for more information about all models in QtIvi.

Member Type Documentation

enum QIviPagingModel::LoadingType

ConstantValueDescription
QIviPagingModel::FetchMore0This is the default and can be used if you don't know the final size of the list (e.g. a infinite list). The list will detect that it is near the end (fetchMoreThreshold) and then fetch the next chunk of data using canFetchMore and fetchMore. The drawback of this method is that you can't display a dynamic scroll-bar indicator which is resized depending on the content of the list, because the final size of the data is not known. The other problem could be fast scrolling, as the data might not arrive in-time and scrolling stops. This can be tweaked by the fetchMoreThreshold property.
QIviPagingModel::DataChanged1For this loading type you need to know how many items are in the list, as dummy items are created and the user can already start scrolling even though the data is not yet ready to be displayed. Similar to FetchMore, the data is also loaded in chunks. You can safely use a scroll indicator here. The delegate needs to support this approach, as it doesn't have content when it's first created.

enum QIviPagingModel::Roles

ConstantValueDescription
QIviPagingModel::NameRoleQt::DisplayRoleThe name of the item. E.g. The name of a contact in a addressbook, or the artist-name in a list of artists.
QIviPagingModel::TypeRoleQt::UserRoleThe type of the item. E.g. "artist", "track", "contact".
QIviPagingModel::ItemRoleQt::UserRole + 1The item itself. This provides access to the properties which are type specific. E.g. the address of a contact.

Property Documentation

capabilities : const QtIviCoreModule::ModelCapabilities

Holds the capabilities of the backend for the current content of the model.

The capabilities controls what the current contentType supports. e.g. filtering or sorting.

Access functions:

QtIviCoreModule::ModelCapabilities capabilities() const

Notifier signal:

void capabilitiesChanged(QtIviCoreModule::ModelCapabilities capabilities)

chunkSize : int

Holds the number of rows which are requested from the backend interface.

This property can be used to fine tune the loading performance.

Bigger chunks means less calls to the backend and to a potential IPC underneath, but more data to be transferred and probably longer waiting time until the request was finished.

Access functions:

int chunkSize() const
void setChunkSize(int chunkSize)

Notifier signal:

void chunkSizeChanged(int chunkSize)

count : const int

Holds the current number of rows in this model.

Access functions:

virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override

Notifier signal:

void countChanged()

fetchMoreThreshold : int

Holds the row delta to the end before the next chunk is loaded

This property can be used to fine tune the loading performance. When the threshold is reached the next chunk of rows are requested from the backend. How many rows are fetched can be defined by using the chunkSize property.

The threshold defines the number of rows before the cached rows ends.

Note: This property is only used when loadingType is set to FetchMore.

Access functions:

int fetchMoreThreshold() const
void setFetchMoreThreshold(int fetchMoreThreshold)

Notifier signal:

void fetchMoreThresholdChanged(int fetchMoreThreshold)

loadingType : QIviPagingModel::LoadingType

Holds the currently used loading type used for loading the data.

Note: When changing this property the content will be reset.

Access functions:

QIviPagingModel::LoadingType loadingType() const
void setLoadingType(QIviPagingModel::LoadingType loadingType)

Notifier signal:

void loadingTypeChanged(QIviPagingModel::LoadingType loadingType)

Member Function Documentation

QIviPagingModel::QIviPagingModel(QObject *parent = nullptr)

Constructs a QIviPagingModel.

The parent argument is passed on to the QIviAbstractFeatureListModel base class.

[signal] void QIviPagingModel::fetchMoreThresholdReached() const

This signal is emitted whenever the fetchMoreThreshold is reached and new data is requested from the backend.

template <typename T> T QIviPagingModel::at(int i) const

Returns the item at index i converted to the template type T.

[override virtual] bool QIviPagingModel::canFetchMore(const QModelIndex &parent) const

Reimplements: QAbstractItemModel::canFetchMore(const QModelIndex &parent) const.

[override virtual protected] void QIviPagingModel::clearServiceObject()

Reimplements: QIviAbstractFeatureListModel::clearServiceObject().

[override virtual protected] void QIviPagingModel::connectToServiceObject(QIviServiceObject *serviceObject)

Reimplements: QIviAbstractFeatureListModel::connectToServiceObject(QIviServiceObject *serviceObject).

[override virtual] QVariant QIviPagingModel::data(const QModelIndex &index, int role) const

Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.

[override virtual protected] void QIviPagingModel::disconnectFromServiceObject(QIviServiceObject *serviceObject)

Reimplements: QIviAbstractFeatureListModel::disconnectFromServiceObject(QIviServiceObject *serviceObject).

[override virtual] void QIviPagingModel::fetchMore(const QModelIndex &parent)

Reimplements: QAbstractItemModel::fetchMore(const QModelIndex &parent).

QVariant QIviPagingModel::get(int i) const

Returns the item at index i as QVariant.

This function is intended to be used from QML. For C++ please use the at() instead.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

void QIviPagingModel::reload()

Resets the model and starts fetching the content again.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[override virtual] QHash<int, QByteArray> QIviPagingModel::roleNames() const

Reimplements: QAbstractItemModel::roleNames() const.

© 2020 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.