LuaModel class reference
[Model/View module]

Declaration  

#include <QtLua/UserItemModel>

namespace QtLua {
class LuaModel;
};

This class is a member of the QtLua namespace.

This class is declared in QtLua/qtlualuamodel.hh source file, line 141.

Description  

This class allows defining a Qt model using lua code. Lua functions must be provided to the C++ model wrapper in order to implement the model.

The qt.mvc.new_lua_model lua function can be used to create such a model from lua script.

read-only lua model  

At least one lua function must be provided to implement a read-only model. This mandatory function is responsible for exposing the model layout and data:

function get(role, item_id, child_row, child_col)

The get function may be first called multiple times by the wrapper with a nil value in the role parameter. In this case, the lua code must expose the data layout:

  • role is a nil value.

  • item_id is the numerical id of the queried item. 0 is reserved for root.

  • child_row and child_col are the row and column of a child item under the queried item, starting at 1.

The lua code must then return at least 3 values. This is enough if the queried item has no parent:

return (item_rows, item_cols, child_id, parent_id, item_row, item_col, flags)
  • item_rows and item_cols are the number of rows and columns under the item specified by item_id.

  • child_id is a numerical id for the child item at position specified by child_row and child_col under the queried item. A positive id must provided by the lua code and will be used to refer to this item later.

  • parent_id is the numerical id of the parent of the item specified by item_id. nil or 0 can be returned for root.

  • item_row and item_col give the position of the item specified by item_id in its parent, starting at 1. This is not used if parent_id is nil or 0.

  • flags is the Qt::ItemFlag value to use for the queried item. A default value is used if nil.

If the role parameter is not a nil value, the get function must instead return the data associated with the specified the display role:

return (item_data, data_type)

If the lua code returns two values, the second value is a numeric Qt type handle which is used to perform the type conversion from the lua the value (see qt.meta_type). The simple ValueBase::to_qvariant function is used to perform conversion when this hint is not present.

editable lua model  

Five other functions may be provided to implement an editable model.

The set function is responsible for updating the data of an item; it must return true if the update was successful:

function set(role, item_id, value)

Four more function can be provided to support insertion and removal of items in the model:

function insert_rows(check, parent_id, pos, count)
function insert_cols(check, parent_id, pos, count)
function remove_rows(check, parent_id, pos, count)
function remove_cols(check, parent_id, pos, count)

When the check parameter value is true, the model must return a boolean value to indicate if the insert action is allowed. The insertion will takes place on the next call if the first call returns true.

Examples  

Some examples of lua list model and tree model are available in the QtLua tree.

Members  

Type  

Function  

  • LuaModel(const Value &get_func, const Value &set_func = [...], const Value &insert_rows_func = [...], const Value &remove_rows_func = [...], const Value &insert_cols_func = [...], const Value &remove_cols_func = [...], QObject *parent = [...])

Private functions  

  • void cached_get(intptr_t item_id, int child_row, int child_col) const
  • int columnCount(const QModelIndex &parent) const
  • QVariant data(const QModelIndex &index, int role) const
  • void error(const String &err) const
  • Qt::ItemFlags flags(const QModelIndex &index) const
  • QModelIndex index(int row, int column, const QModelIndex &parent) const
  • bool insertColumns(int col, int count, const QModelIndex &parent)
  • bool insertRows(int row, int count, const QModelIndex &parent)
  • QModelIndex parent(const QModelIndex &index) const
  • bool removeColumns(int col, int count, const QModelIndex &parent)
  • bool removeRows(int row, int count, const QModelIndex &parent)
  • int rowCount(const QModelIndex &parent) const
  • bool setData(const QModelIndex &index, const QVariant &value, int role)

Private fields  

Members detail  

LuaModel(const Value &get_func, const Value &set_func = Value(), const Value &insert_rows_func = Value(), const Value &remove_rows_func = Value(), const Value &insert_cols_func = Value(), const Value &remove_cols_func = Value(), QObject *parent = 0)  

This constructor is declared in QtLua/qtlualuamodel.hh source file, line 153.

enum ItemDataRole  

This enum is declared in QtLua/qtlualuamodel.hh source file, line 156.

IdentifierValueDescription
DisplayRole::Qt::DisplayRole
DecorationRole::Qt::DecorationRole
EditRole::Qt::EditRole
ToolTipRole::Qt::ToolTipRole
StatusTipRole::Qt::StatusTipRole
WhatsThisRole::Qt::WhatsThisRole
FontRole::Qt::FontRole
TextAlignmentRole::Qt::TextAlignmentRole
BackgroundColorRole::Qt::BackgroundColorRole
BackgroundRole::Qt::BackgroundRole
TextColorRole::Qt::TextColorRole
ForegroundRole::Qt::ForegroundRole
CheckStateRole::Qt::CheckStateRole
AccessibleTextRole::Qt::AccessibleTextRole
AccessibleDescriptionRole::Qt::AccessibleDescriptionRole
SizeHintRole::Qt::SizeHintRole
InitialSortOrderRole::Qt::InitialSortOrderRole
UserRole::Qt::UserRole

int _child_col  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 202.

This member access is private.

int _child_row  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 202.

This member access is private.

This variable is declared in QtLua/qtlualuamodel.hh source file, line 207.

This member access is private.

Value _insert_cols  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 211.

This member access is private.

Value _insert_rows  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 209.

This member access is private.

intptr_t _item_id  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 201.

This member access is private.

Value _remove_cols  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 212.

This member access is private.

Value _remove_rows  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 210.

This member access is private.

intptr_t _res[7]  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 205.

This member access is private.

int _rsize  

This variable is declared in QtLua/qtlualuamodel.hh source file, line 202.

This member access is private.

This variable is declared in QtLua/qtlualuamodel.hh source file, line 208.

This member access is private.

void cached_get(intptr_t item_id, int child_row, int child_col) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 199.

This member access is private.

int columnCount(const QModelIndex &parent) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 189.

This member access is private.

QVariant data(const QModelIndex &index, int role) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 190.

This member access is private.

void error(const String &err) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 197.

This member access is private.

Qt::ItemFlags flags(const QModelIndex &index) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 191.

This member access is private.

QModelIndex index(int row, int column, const QModelIndex &parent) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 186.

This member access is private.

bool insertColumns(int col, int count, const QModelIndex &parent)  

This function is declared in QtLua/qtlualuamodel.hh source file, line 195.

This member access is private.

bool insertRows(int row, int count, const QModelIndex &parent)  

This function is declared in QtLua/qtlualuamodel.hh source file, line 193.

This member access is private.

QModelIndex parent(const QModelIndex &index) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 187.

This member access is private.

bool removeColumns(int col, int count, const QModelIndex &parent)  

This function is declared in QtLua/qtlualuamodel.hh source file, line 196.

This member access is private.

bool removeRows(int row, int count, const QModelIndex &parent)  

This function is declared in QtLua/qtlualuamodel.hh source file, line 194.

This member access is private.

int rowCount(const QModelIndex &parent) const  

This function is declared in QtLua/qtlualuamodel.hh source file, line 188.

This member access is private.

bool setData(const QModelIndex &index, const QVariant &value, int role)  

This function is declared in QtLua/qtlualuamodel.hh source file, line 192.

This member access is private.

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 16:23:03 2013 using MkDoc