EnginioModel

Makes accessing collections of objects easy More...

Import Statement: import Enginio .

Properties

Methods

  • EnginioReply append(QJSValue value)
  • EnginioReply remove(int row)
  • EnginioReply setProperty(int row, string propertyName, QVariant value)

Detailed Description

import Enginio 1.0

The query property of the model takes a JSON object.

To get a model of each object of type "objects.city" use:

EnginioModel {
    id: enginioModel
    client: client
    query: { "objectType": "objects.city" }
}

It is then possible to use a regular Qt Quick ListView to display the list of cities that the backend contains.

ListView {
    anchors.fill: parent
    model: enginioModel
    delegate: Text {
        text: name + ": " + population
    }
}

Note that the properties of the objects can be directly accessed. In this example, we have the type "objects.city" in the backend with two properties: "name" and "population".

The model supports several function to modify the data, for example append(), remove(), setProperty()

The QML version of EnginioModel supports the same functionality as the C++ version. EnginioModel C++

Property Documentation

client : EnginioClient

The instance of EnginioClient used for this model.


operation : Enginio::Operation

The operation used for the query.


query : QJSValue

The query used to populate the model with data.


Method Documentation

EnginioReply append(QJSValue value)

Add a new object to the model and database.

To add a "city" object to the model by appending it:

function addCity() {
    var berlin = {
        "objectType": "objects.city",
        "name": "Berlin",
        "population": 3300000
    }
    enginioModel.append(berlin)
}

The append will be reflected by the model immediately and will be propagated to the server asynchronously.

The returned EnginioReply can be used to react to a finished object creation.


EnginioReply remove(int row)

removes the object at row


EnginioReply setProperty(int row, string propertyName, QVariant value)

Change a property of an object in the model

The property propertyName of the object at row will be set to value. The model will locally reflect the change immediately and propagage the change to the server in the background.