AsyncHeaderDataModel
Since: BlackBerry 10.2.0
#include <bb/cascades/datamanager/AsyncHeaderDataModel>
To link against this class, add the following line to your .pro file: LIBS += -lbbcascadesdatamanager
A data model that supports index paths with length of two.
This class is designed to use a HeaderDataQuery to retrieve top-level header items and a DataQuery to retrieve detailed-level items.
The header data is cached in full by the parent AsyncHierarchicalDataModel and the detailed items are partially cached up to a specified cache size (default 200).
Here is a QML example showing the usage of an AsyncHeaderDataModel:
import bb.cascades 1.2 import bb.cascades.datamanager 1.2 Page { content: Container { layout: StackLayout { } ListView { property string imagePath: app.imagePath layout: StackListLayout { headerMode: ListHeaderMode.Sticky } id: myListView dataModel: dm listItemComponents: [ ListItemComponent { type: "header" Header { title: ListItemData.header } }, ListItemComponent { type: "" StandardListItem { title: ListItemData.firstname + " " + ListItemData.lastname imageSource: ListItemData.image description: ListItemData.title } } ] } attachedObjects: [ // an example to demonstrate how to use an AsyncHeaderDataModel AsyncHeaderDataModel { id: dm cacheSize: 200 // can use any query that implements the HeaderDataQuery interface // SqlHeaderDataQuery is the default implementation provided with the library query: SqlHeaderDataQuery { source: "sql/contacts1k.db" query: "select id, firstname, lastname, title, image, active, revision_id " + "from contact order by lastname, firstname" headerQuery: "select substr(lastname, 1, 1) as header, count(*) " + "from contact group by header" countQuery: "select count(*) from contact" keyColumn: "id" revisionColumn: "revision_id" revisionQuery: "select revision_id from revision" onError: console.log("SQL query error: " + code + ", " + message) } onLoaded: console.log("initial model data is loaded") } ] } onCreationCompleted: { dm.load(); } }
Overview
Inheritance
bb::cascades::DataModel | |||||
bb::cascades::datamanager::QueryDataModel | |||||
bb::cascades::datamanager::AsyncDataModel | |||||
bb::cascades::datamanager::AsyncHierarchicalDataModel | |||||
bb::cascades::datamanager::AsyncHeaderDataModel |
QML properties
QML signals
Only has inherited QML signals
onCacheSizeChanged | ![]() |
onItemAdded | ![]() |
onItemMoved | ![]() |
onItemRemoved | ![]() |
onItemsChanged | ![]() |
onItemUpdated | ![]() |
onLoaded | ![]() |
onQueryChanged | ![]() |
Properties Index
Only has inherited properties
int | cacheSize![]() |
bb::cascades::datamanager::DataQuery | query![]() |
Public Functions Index
AsyncHeaderDataModel (QObject *parent=0) | |
virtual | ~AsyncHeaderDataModel () |
virtual QSharedPointer< AsyncHierarchicalDataModel::HeaderDescriptor > | headerDescriptor () const |
AsyncDataModel (QObject *parent=0)![]() | |
AsyncHierarchicalDataModel (QObject *parent=0)![]() | |
int | cacheSize () const ![]() |
virtual Q_INVOKABLE int | childCount (const QVariantList &indexPath)![]() |
virtual Q_INVOKABLE QVariant | data (const QVariantList &indexPath)![]() |
DataModel (QObject *parent=0)![]() | |
virtual Q_INVOKABLE bool | hasChildren (const QVariantList &indexPath)![]() |
virtual Q_INVOKABLE QString | itemType (const QVariantList &indexPath)![]() |
virtual Q_INVOKABLE void | load ()![]() |
virtual bb::cascades::datamanager::DataQuery * | query ()![]() |
QueryDataModel (QObject *parent=0)![]() | |
void | setCacheSize (int cacheSize)![]() |
virtual void | setQuery (bb::cascades::datamanager::DataQuery *query)![]() |
Signals Index
Only has inherited signals
void | cacheSizeChanged (int cacheSize)![]() |
void | itemAdded (QVariantList indexPath)![]() |
void | itemMoved (QVariantList fromIndexPath, QVariantList toIndexPath)![]() |
void | itemRemoved (QVariantList indexPath)![]() |
void | itemsChanged (bb::cascades::DataModelChangeType::Type eChangeType=bb::cascades::DataModelChangeType::Init, QSharedPointer< bb::cascades::DataModel::IndexMapper > indexMapper=QSharedPointer< bb::cascades::DataModel::IndexMapper >(0))![]() |
void | itemUpdated (QVariantList indexPath)![]() |
void | loaded ()![]() |
void | queryChanged ()![]() |
Properties
(Only has inherited properties)
int
The maximum count of data items maintained in the cache.
BlackBerry 10.2.0
bb::cascades::datamanager::DataQuery
The data query to use for obtaining data.
Ownership of the query object is taken over by this model.
BlackBerry 10.2.0
Public Functions
Constructs an AsyncHeaderDataModel.
Parameters | |
---|---|
parent |
The parent owner or 0. Optional and defaults to 0 if not specified. |
BlackBerry 10.2.0
virtual
Destructor.
BlackBerry 10.2.0
virtualQSharedPointer< AsyncHierarchicalDataModel::HeaderDescriptor >
Returns the descriptor for the current header data.
The header descriptor.
BlackBerry 10.2.0
Constructs an AsyncDataModel.
Parameters | |
---|---|
parent |
The parent owner or 0. Optional and defaults to 0 if not specified. |
BlackBerry 10.2.0
Constructs a AsyncHierarchicalDataModel.
Parameters | |
---|---|
parent |
The parent owner or 0. Optional and defaults to 0 if not specified. |
BlackBerry 10.2.0
int 
Return the current capacity for the data cache for this model.
The default capacity is 200 data items.
The current data cache capacity.
BlackBerry 10.2.0
virtual Q_INVOKABLE int 
Returns the number of children for the data item specified by indexPath.
The root item is represented by an empty index path. This example shows how to get the number of top level items (items having the root item as parent):
int numberOfHeaders = model->childCount(QVariantList());
Parameters | |
---|---|
indexPath |
The path to the data item to get the child count for. |
The number of children. The return value for invalid index paths is undefined.
BlackBerry 10.2.0
virtual Q_INVOKABLE QVariant 
Returns the data associated with the specified item.
This method does not transfer any ownership, any returned QObject is still owned by its parent. A QObject returned by this function always has a parent. The ListView will pass on the data as a parameter to ListItemProvider::updateItem().
Parameters | |
---|---|
indexPath |
The path to the item in the model. |
A QVariantMap wrapped in a QVariant.
BlackBerry 10.2.0
Constructs a DataModel instance with the specified parent.
Parameters | |
---|---|
parent |
The data model owner, or 0. Optional and will default to 0 if not specified. |
BlackBerry 10.0.0
virtual Q_INVOKABLE bool 
Indicates whether the data item specified by indexPath has children.
Parameters | |
---|---|
indexPath |
The path to the data item to query for children. |
True if the data item has one or more children, false otherwise. ListView never calls this function for its root node (but does call childCount() for the root node), therefore the return value for an empty index path is undefined.
BlackBerry 10.2.0
virtual Q_INVOKABLE QString 
Returns the type for the specified item.
Parameters | |
---|---|
indexPath |
The path to the item in the model. |
A string identifying the type for this item.
BlackBerry 10.2.0
virtual Q_INVOKABLE void 
Load the initial cache of data.
After setting the data query and other properties, call this method to load the data.
BlackBerry 10.2.0
virtualbb::cascades::datamanager::DataQuery * 
Return the data query for this model.
The data query to use with this data model.
BlackBerry 10.2.0
Constructs a QueryDataModel.
Parameters | |
---|---|
parent |
The parent owner or 0. Optional and defaults to 0 if not specified. |
BlackBerry 10.2.0
void 
Set the capacity for the data cache for this model.
The default capacity is 200 data items.
Parameters | |
---|---|
cacheSize |
The new data cache capacity. |
BlackBerry 10.2.0
virtual void 
Set the data query that this model uses to load data.
Ownership of the query is taken over by the model and the query is executed in a secondary thread.
Parameters | |
---|---|
query |
The data query to use with this data model. |
BlackBerry 10.2.0
Signals
(Only has inherited signals)
void 
Emitted when the cache capacity for this data model has changed.
Parameters | |
---|---|
cacheSize |
The new cache capacity. |
BlackBerry 10.2.0
void 
Emitted when a data item has been added to this DataModel.
Parameters | |
---|---|
indexPath |
The index path to the new item. |
BlackBerry 10.0.0
void 
Emitted when a data item has been moved within the DataModel.
A moved item will retain its visual appearance and data on the server.
Parameters | |
---|---|
fromIndexPath |
The original index path of the moved item. |
toIndexPath |
The new index path of the moved item. |
BlackBerry 10.3.0
void 
Emitted when a data item has been removed from this DataModel.
Parameters | |
---|---|
indexPath |
The index path to the removed item. |
BlackBerry 10.0.0
void 
Emitted when the model has changed in a way that would be inefficient to describe with single instances of the other signals.
No other signals (DataModel::itemAdded, DataModel::itemUpdated, or DataModel::itemRemoved) are emitted if this signal is emitted when a change occurs in this DataModel.
Typical examples of when this signal is emitted: data has been sorted (so that many items have changed places), the DataModel has been cleared (all items have been removed), or a batch of items has been added.
If eChangeType is DataModelChangeType::Init, or if eChangeType is DataModelChangeType::AddRemove and indexMapper is 0, a ListView reacts to this signal by releasing all of the items in its cache.
If eChangeType is AddRemove and an IndexMapper is provided, the ListView instead calls IndexMapper::newIndexPath() for each item in its cache.
If eChangeType is DataModelChangeType::Update, a ListView reacts to this signal by calling DataModel::data() again for every item in its cache.
Parameters | |
---|---|
eChangeType |
The type of change. |
indexMapper |
An index mapper that contains update information. |
BlackBerry 10.0.0
void 
Emitted when a data item in this DataModel has been updated.
Parameters | |
---|---|
indexPath |
IndexPath to the updated item. |
BlackBerry 10.0.0
void 
void 
Emitted when the query has changed.
BlackBerry 10.2.0