QueryDataModel
Since: BlackBerry 10.2.0
#include <bb/cascades/datamanager/QueryDataModel>
To link against this class, add the following line to your .pro file: LIBS += -lbbcascadesdatamanager
A data model that loads its data from a DataQuery.
The QueryDataModel class is the base class for data models which can use a DataQuery to allow them to query and load data.
Overview
Inheritance
bb::cascades::DataModel | ||
bb::cascades::datamanager::QueryDataModel | ||
bb::cascades::datamanager::AsyncDataModel | ||
bb::cascades::datamanager::SimpleQueryDataModel |
QML properties
query | : bb::cascades::datamanager::DataQuery |
QML signals
onLoaded | : {} |
onQueryChanged | : {} |
onItemAdded | ![]() |
onItemMoved | ![]() |
onItemRemoved | ![]() |
onItemsChanged | ![]() |
onItemUpdated | ![]() |
Properties Index
Public Functions Index
QueryDataModel (QObject *parent=0) | |
virtual | ~QueryDataModel () |
Q_INVOKABLE void | load ()=0 |
bb::cascades::datamanager::DataQuery * | query ()=0 |
void | setQuery (bb::cascades::datamanager::DataQuery *query)=0 |
Q_INVOKABLE int | childCount (const QVariantList &indexPath)=0![]() |
Q_INVOKABLE QVariant | data (const QVariantList &indexPath)=0![]() |
DataModel (QObject *parent=0)![]() | |
Q_INVOKABLE bool | hasChildren (const QVariantList &indexPath)=0![]() |
virtual Q_INVOKABLE QString | itemType (const QVariantList &indexPath)![]() |
Signals Index
void | loaded () |
void | queryChanged () |
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)![]() |
Properties
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 a QueryDataModel.
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
Q_INVOKABLE void
Loads data.
After setting the data query and other properties, call this method to load the data.
BlackBerry 10.2.0
bb::cascades::datamanager::DataQuery *
Get the data query for this model.
The data model owns this pointer and destroys it when the data model is destroyed or the query is changed.
The data query to use with this data model.
BlackBerry 10.2.0
void
Set the data query that this model uses to load data.
Ownership of the query object is taken over by this model.
Parameters | |
---|---|
query |
The data query to use with this data model. |
BlackBerry 10.2.0
Q_INVOKABLE int 
Returns the number of children to the data item specified by indexPath.
Parameters | |
---|---|
indexPath |
The index path to the data item to get child count for. |
The number of children.
BlackBerry 10.0.0
Q_INVOKABLE QVariant 
Returns the data item that is associated with indexPath.
This function transfers ownership for QObject objects, if the returned object doesn't have any parent.
The ListView will pass the data item as a parameter to ListItemProvider::updateItem(). If item visuals are created by using ListItemComponent in QML, ListView makes the data returned from this function available in the item visuals as the context property ListItemData, and also as the property ListItem.data attached to the item visual root node.
Parameters | |
---|---|
indexPath |
The index path to the data item. |
The data item associated with the indexPath. The caller must take ownership of any returned QObject objects, if the returned object doesn't already have a parent.
BlackBerry 10.0.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
Q_INVOKABLE bool 
Indicates whether the data item specified by indexPath has children.
ListView never calls this function for its root node (but does call childCount(QVariantList) for the root node), so if this DataModel only contains one level of items (no child items), this function can always return false.
Here's an example of how to override hasChildren().
bool SmartViewModel::hasChildren(const QVariantList &indexPath) { // Checks whether the indexPath is an empty array. // An empty array indicates the the index path is for the // root element. if(indexPath.empty()) return true; // The root node always has children // ...Check for other index paths... }
Parameters | |
---|---|
indexPath |
The index path to the data item to query for children. |
true if the data item has one or more children, false otherwise.
BlackBerry 10.0.0
virtual Q_INVOKABLE QString 
Returns the item type for the data item at indexPath.
The item type will then be used when the ListView requests items from its ListItemProvider. It will also be used when the DataModel has indicated that items have been updated using the signals DataModel::itemUpdated or DataModel::itemsChanged with DataModelChangeType::Update.
If a ListItemTypeMapper has been provided to a ListView, the ListView calls ListItemTypeMapper::itemType() instead of DataModel::itemType().
Parameters | |
---|---|
indexPath |
The index path to the data item. |
A string representing the user-defined type of the item. The default implementation returns an empty string.
BlackBerry 10.0.0
Signals
void
void
Emitted when the query has changed.
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