Skip to content

Instantly share code, notes, and snippets.

@oKcerG

oKcerG/readme.md Secret

Created December 22, 2017 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oKcerG/eeea734bdacc51b3ae58650de5f05943 to your computer and use it in GitHub Desktop.
Save oKcerG/eeea734bdacc51b3ae58650de5f05943 to your computer and use it in GitHub Desktop.

QmlModelHelper

Access your models from QML without views or delegates

Installation

  1. clone or download this repository
  2. add include (<path/to/QmlModelHelper>/QmlModelHelper.pri) in your .pro
  3. import ModelHelper 0.1 to use this library in your QML files

Documentation

To use the ModelHelper, use it as an attached object of a model (it must be a subclass of a QAbstractItemModel, meaning it can originate from c++ or be a ListModel from QML).

Attached properties:

rowCount : int

This property holds the number of rows in the model.

count : int

This property holds the number of rows in the model. Alias for rowCount.

columnCount : int

This property holds the number of columns in the model.

roles : array

This property holds an array of objects describing the roles of the model. Each object has 2 properties: role, the number of the role; and roleName, the name of the role.

Attached methods:

object map(int row, int column = 0, QModelIndex parent = {})
int roleForName(string roleName)

Returns the role number for the given roleName. If no role is found for this name, -1 is returned.

var data(int row)

Return the item at row in the model as a map of all its roles.

var data(int row, string roleName)

Return the data for the given roleName of the item at row in the model.

License

This library is licensed under the MIT License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment