QIfPagingModelInterface Class
The QIfPagingModelInterface defines the interface for backends to the QIfPagingModel feature class. More...
Header: | #include <QIfPagingModelInterface> |
qmake: | QT += interfaceframework |
Inherits: | QIfFeatureInterface |
Inherited By: |
Public Functions
QIfPagingModelInterface(QObject *parent = nullptr) | |
virtual void | fetchData(const QUuid &identifier, int start, int count) = 0 |
virtual void | registerInstance(const QUuid &identifier) = 0 |
virtual void | unregisterInstance(const QUuid &identifier) = 0 |
Signals
void | countChanged(const QUuid &identifier = QUuid(), int count = -1) |
void | dataChanged(const QUuid &identifier, const QList<QVariant> &data, int start, int count) |
void | dataFetched(const QUuid &identifier, const QList<QVariant> &data, int start, bool moreAvailable) |
void | supportedCapabilitiesChanged(const QUuid &identifier, QtInterfaceFrameworkModule::ModelCapabilities capabilities) |
Detailed Description
The QIfPagingModelInterface is the interface used by QIfPagingModel
The interface is discovered by a QIfPagingModel object, which connects to it and sets it up.
QIfPagingModel registration
Every QIfPagingModel generates its own QUuid which is passed to the backend interface and can be used to identify a model instance. By using the QUuid of a specific instance in a signal, only this specific instance gets notified about the change. This can be useful for stateful backends, such as an addressbook with a filter function. Because of the filtering, the number of items inside the model will change. The notification and the filtering itself is only done for the specific instance which requested it. All other instances could still display the full set of model data. The QIfFilterAndBrowseModel is using this concept for filtering. To inform all feature instances of a change, a default constructed QUuid can be used instead.
The registerInstance and unregisterInstance functions are called respectively when a new QIfPagingModel instance connects to this backend or disconnects from it.
Capabilities
Depending on the data of the model and the underlying store the data is coming from, different features might be supported. The supportedCapabilitiesChanged signal informs the QIfPagingModel instance about the features supported by this backend. The ModelCapabilities type used in this signal hosts different features supported in the QIfPagingModel and the QIfFilterAndBrowseModel.
For a QIfPagingModel, the SupportsGetSize capability can be used to indicate that this backend knows the total size of the model and that it will inform about it using the countChanged() signal. In case the capabilities are not reported, or the SupportsGetSize capability is not set, the QIfPagingModel needs to use the FetchMore loading type.
Returning model data
Other than QIfFeatureInterface based backends, the initialize() function does not emit the complete state. Instead the actual model data is returned on request. This is done to support big models as well and save bandwidth when the data needs to be transferred over an IPC. Once a QIfPagingModel is used inside a View class, the model data is requested from the backend by calling fetchData(). The amount of data requested in one call can be controlled by the QIfPagingModel instance. Once the requested data is ready, the backend needs to inform about it using the dataFetched() signal. To inform the QIfPagingModel about an updated row, the dataChanged() signal can be used.
Example call order
- A QIfPagingModel instance is created and connects to this backend
- initialize() is called
- The backend initializes it's internal state and informs about all extra properties it has by emitting the respective change signals.
- The backend emits initializationDone()
- The QIfPagingModel instance calls registerInstance() with its own QUuid
- The backend informs about its capabilities and its size by emitting supportedCapabilitiesChanged() and countChanged().
- The QIfPagingModel fetches the first rows by calling fetchData()
- The backend emits dataFetched() once it is ready.
- The last two steps might repeat depending on the current state of the view
See also QIfPagingModel.
Member Function Documentation
[explicit]
QIfPagingModelInterface::QIfPagingModelInterface(QObject *parent = nullptr)
Constructs a backend interface.
The parent is sent to the QObject constructor.
[signal]
void QIfPagingModelInterface::countChanged(const QUuid &identifier = QUuid(), int count = -1)
This signal is emitted when the current number of items in the QIfPagingModel instance identified by identifier changed. The new number of items is returned as count.
This signal is expected to be emitted after the model instance has requested new data for the first time by calling fetchData() and should be emitted before the data is returned by emitting the dataFetched() signal.
Note: If a null QQuuid is used as a identifier, all model instances will be informed.
See also fetchData() and dataFetched().
[signal]
void QIfPagingModelInterface::dataChanged(const QUuid &identifier, const QList<QVariant> &data, int start, int count)
This signal is emitted whenever the data in the QIfPagingModel instance identified by identifier changed and the model needs to be updated. The new data is passed as data. The arguments start and count can be used to define the set of items which should be replaced with the new data.
For inserting a new item, the item is passed in data and start is used for where the item should be inserted, the count argument needs to be 0 as we don't want to replace existing data:
QList<ExampleItem> list; ExampleItem item = ExampleItem(); list.insert(index, item); QVariantList items = { QVariant::fromValue(item) }; emit dataChanged(items, index, 0);
Removing an item is very similar, start is used to indicate which item and count to indicate how much:
list.removeAt(index); emit dataChanged(identifier, QVariantList(), index, 1);
Note: If a null QQuuid is used as a identifier, all model instances will be informed.
[signal]
void QIfPagingModelInterface::dataFetched(const QUuid &identifier, const QList<QVariant> &data, int start, bool moreAvailable)
This signal is emitted as a result of a call to fetchData() and returns the requested data in the argument data to the QIfPagingModel instance identified by identifier. The arguments start holds the index where the data starts and moreAvailable holds whether there is more data available and a new fetchData() call can be used to retrieve this data.
Note: If a null QQuuid is used as a identifier, all model instances will be informed.
See also fetchData() and dataFetched().
[pure virtual]
void QIfPagingModelInterface::fetchData(const QUuid &identifier, int start, int count)
This function is called whenever new data needs to be retrieved by a QIfPagingModel identified by identifier.
The parameters start and count define the range of data which should be fetched. This method is expected to emit the dataFetched() signal once the new data is ready.
See also dataFetched().
[pure virtual]
void QIfPagingModelInterface::registerInstance(const QUuid &identifier)
Registers the instance of QIfPagingModel identified by identifier with this backend. This function will be called by QIfPagingModel and all its derived classes after the initialize() function, but before any data will be requested e.g. via fetchData().
See also unregisterInstance.
[signal]
void QIfPagingModelInterface::supportedCapabilitiesChanged(const QUuid &identifier, QtInterfaceFrameworkModule::ModelCapabilities capabilities)
Emitted when the capabilities of the model instance identified by identifier changed.
Note: If a null QQuuid is used as a identifier, all model instances will be informed.
[pure virtual]
void QIfPagingModelInterface::unregisterInstance(const QUuid &identifier)
Unregisters the instance of QIfPagingModel identified by identifier with this backend. This function will be called by QIfPagingModel and all its derived classes before the ServiceObject gets disconnected and can be used to cleanup all cached data for this identifier.
See also registerInstance.
© 2024 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.