SimpleQueryDataModel

Since: BlackBerry 10.2.0

#include <bb/cascades/datamanager/SimpleQueryDataModel>

To link against this class, add the following line to your .pro file: LIBS += -lbbcascadesdatamanager

A simple data model that loads data from a DataQuery.

This data model provides a flat list and does not support hierarchical data.

This data model supports automatic update notifications, but in a very simplistic way: all updates force a full reload of the data, and notify listeners of a full init each time.

Here is a QML example showing the usage of an SimpleQueryDataModel:

import bb.cascades 1.2
import bb.cascades.datamanager 1.2
Page {
    content: Container {
        layout: StackLayout {}
        ListView {
            id: myListView
            dataModel: dm
            listItemComponents: [
                ListItemComponent {
                    StandardListItem {
                        title: ListItemData.firstname + " " + ListItemData.lastname
                        imageSource: ListItemData.image
                        description: ListItemData.title
                    }
                }
            ]
        }
        attachedObjects: [
            // an example to demonstrate how to use a SimpleQueryDataModel
            SimpleQueryDataModel {
                id: dm
                // can use any query that implements the DataQuery interface
                // SqlDataQuery is the default implementation provided with the library
                query: SqlDataQuery {
                    source: "sql/contacts1k.db"
                    query: "select id, firstname, lastname, title, image, active, revision_id " +
                           "from contact order by lastname, firstname"
                    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::SimpleQueryDataModel

QML properties

Only has inherited QML properties

query: bb::cascades::datamanager::DataQueryInherited

QML signals

Only has inherited QML signals

onItemAddedInherited: {}
onItemRemovedInherited: {}
onItemsChangedInherited: {}
onItemUpdatedInherited: {}
onLoadedInherited: {}
onQueryChangedInherited: {}

Properties Index

Only has inherited properties

bb::cascades::datamanager::DataQueryqueryInherited

Public Functions Index

SimpleQueryDataModel (QObject *parent=0)
virtual ~SimpleQueryDataModel ()
virtual Q_INVOKABLE intchildCount (const QVariantList &indexPath)
virtual Q_INVOKABLE QVariantdata (const QVariantList &indexPath)
virtual Q_INVOKABLE boolhasChildren (const QVariantList &indexPath)
virtual Q_INVOKABLE QStringitemType (const QVariantList &indexPath)
virtual Q_INVOKABLE voidload ()
virtual bb::cascades::datamanager::DataQuery *query ()
virtual voidsetQuery (bb::cascades::datamanager::DataQuery *query)
Q_INVOKABLE inttotalSize ()
DataModel (QObject *parent=0)Inherited
QueryDataModel (QObject *parent=0)Inherited

Signals Index

Only has inherited signals

voiditemAdded (QVariantList indexPath)Inherited
voiditemRemoved (QVariantList indexPath)Inherited
voiditemsChanged (bb::cascades::DataModelChangeType::Type eChangeType=bb::cascades::DataModelChangeType::Init, QSharedPointer< bb::cascades::DataModel::IndexMapper > indexMapper=QSharedPointer< bb::cascades::DataModel::IndexMapper >(0))Inherited
voiditemUpdated (QVariantList indexPath)Inherited
voidloaded ()Inherited
voidqueryChanged ()Inherited

Properties

(Only has inherited properties)

bb::cascades::datamanager::DataQuery queryInherited

The data query to use for obtaining data.

Note: Ownership of the query object will be taken over by this model.

Since:

BlackBerry 10.2.0

Public Functions

SimpleQueryDataModel (

Constructor.

Parameters
parent

The parent owner or 0. Optional and will default to 0 if not specified.

Since:

BlackBerry 10.2.0

virtual~SimpleQueryDataModel ()

Destructor.

Since:

BlackBerry 10.2.0

virtual Q_INVOKABLE int childCount (

Call the method childCount of the DataModel being decorated.

Parameters
indexPath

The path to the data item to get child count for.

Return:

The number of children. The return value for invalid index paths is undefined.

Since:

BlackBerry 10.2.0

virtual Q_INVOKABLE QVariant data (

Call the method data of the DataModel being decorated.

Parameters
indexPath

The path to the item in the model.

Return:

The data for this item.

Since:

BlackBerry 10.2.0

virtual Q_INVOKABLE bool hasChildren (

Call the method hasChildren of the DataModel being decorated.

Parameters
indexPath

The path to the data item to query for children.

Return:

true if the data item has one or more children, false otherwise.

Since:

BlackBerry 10.2.0

virtual Q_INVOKABLE QString itemType (

Call the method itemType of the DataModel being decorated.

Parameters
indexPath

The path to the item in the model.

Return:

a string identifying the type for this item.

Since:

BlackBerry 10.2.0

virtual Q_INVOKABLE void load ()

Loads data.

After setting the data query and other properties, call this method to load the data.

Since:

BlackBerry 10.2.0

virtualbb::cascades::datamanager::DataQuery * query ()

Get the data query for this model.

The data model owns this pointer and will destroy it when the data model is destroyed or the query is changed.

Return:

The data query to use with this data model.

Since:

BlackBerry 10.2.0

virtual void setQuery (

Set the data query that this model will use to load data.

Ownership of the query object will be taken over by this model.

Parameters
query

The data query to use with this data model.

Since:

BlackBerry 10.2.0

Q_INVOKABLE int totalSize ()

Return the total count of the data items in the model.

Return:

total count of items.

Since:

BlackBerry 10.2.0

DataModel (Inherited

Constructs a DataModel instance with the specified parent.

If the specified parent is not 0, the ownership of the constructed DataModel is transferred to the parent.

Parameters
parent

The data model owner, or 0. Optional and will default to 0 if not specified.

Since:

BlackBerry 10.0.0

QueryDataModel (Inherited

Constructor.

Parameters
parent

The parent owner or 0. Optional and will default to 0 if not specified.

Since:

BlackBerry 10.2.0

Signals

(Only has inherited signals)

void itemAdded (Inherited

Emitted when a data item has been added to this DataModel.

Parameters
indexPath

The index path to the new item.

Since:

BlackBerry 10.0.0

void itemRemoved (Inherited

Emitted when a data item has been removed from this DataModel.

Parameters
indexPath

The index path to the removed item.

Since:

BlackBerry 10.0.0

void itemsChanged (Inherited

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.

Since:

BlackBerry 10.0.0

void itemUpdated (Inherited

Emitted when a data item in this DataModel has been updated.

Parameters
indexPath

IndexPath to the updated item.

Since:

BlackBerry 10.0.0

void loaded ()Inherited

Emitted when the DataModel is first loaded after calling the load method.

The number of loaded signal may not equal to the number of load method call. But it is always guaranteed that a load method call results in a loaded signal being emitted. For example, two consecutive load method calls could results in only one loaded signal.

Since:

BlackBerry 10.2.0

void queryChanged ()Inherited

Emitted when the query has changed.

Since:

BlackBerry 10.2.0

Last modified: 2014-03-13

comments powered by Disqus