TableTreeModel class reference
[Model/View module]

Declaration  

#include <QtLua/TableTreeModel>

namespace QtLua {
class TableTreeModel;
};

This class is a member of the QtLua namespace.

Description  

This class can be used to expose lua tables content to Qt view widgets in a flat or hierarchical manner.

Lua tables and UserData objects with valid table operations are handled.

Lua tables can be edited from Qt views using this model. The TableTreeModel::Attribute flags can be used to control which editing actions are allowed. User input may be evaluated as a lua expression when editing a table entry.

Lua tables change may not update the model on the fly and the TableTreeModel::update function must be called to refresh views on heavy modifications. This is partially due to lack of lua mechanism to implement efficient table change event. If you need to edit the underlying data from lua and have the views updated automatically, you might use the UserItemModel approach instead.

Usage example:

// code from examples/cpp/mvc/tabletreeview.cc:30

state = new QtLua::State();
state->openlib(QtLua::AllLibs);

// Create a new model and expose lua global table
model = new QtLua::TableTreeModel(state->at("_G"), QtLua::TableTreeModel::Recursive);

// Create Qt view widget
treeview = new QTreeView(0);
treeview->setModel(model);

setCentralWidget(treeview);

See also ItemViewDialog class.

Members  

Types  

Functions  

Protected functions  

  • QModelIndex buddy(const QModelIndex &index) const
  • int columnCount(const QModelIndex &parent) const
  • QVariant data(const QModelIndex &index, int role) const
  • Qt::ItemFlags flags(const QModelIndex &index) const
  • bool hasChildren(const QModelIndex &parent) const
  • QVariant headerData(int section, Qt::Orientation orientation, int role) const
  • bool insertRows(int row, int count, const QModelIndex &parent)
  • QModelIndex parent(const QModelIndex &index) const
  • 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)

Static functions  

  • static void table_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = [...])
  • static void tree_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = [...])

Signal  

Members detail  

TableTreeModel(const Value &root, TableTreeModel::Attributes attr, QObject *parent = 0)  

Create a new lua table model.

~TableTreeModel()  

No documentation available

enum Attribute  

Specifies TableTreeModel behavior for a given lua table

IdentifierValueDescription
Recursive0x00000001Expose nested tables too.
UserDataIter0x00000002Iterate over UserData objects too.
HideKey0x00000020Do not show key column.
HideValue0x00000040Do not show value column.
HideType0x00000004Do not show value type column.
UnquoteKeys0x00000008Strip double quotes from string keys
UnquoteValues0x00000010Strip double quotes from string values
Editable0x00001000Allow editing exposed lua tables.
EditFixedType0x00002000Prevent value type change when editing.
EditLuaEval0x00004000Evaluate user input as a lua expression.
EditInsert0x00008000Allow insertion of new entries.
EditRemove0x00010000Allow deletion of existing entries.
EditKey0x00020000Allow entry key update.
EditAll0x00039000Editable, EditInsert, EditRemove and EditKey allowed

See also TableTreeModel::Attributes typedef.

typedef TableTreeModel::Attribute Attributes  

No documentation available

QModelIndex buddy(const QModelIndex &index) const  

This member access is protected.

int columnCount(const QModelIndex &parent) const  

This member access is protected.

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

This member access is protected.

void edit_error(const QString &message)  

This member is a Qt signal.

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

This member access is protected.

TableTreeModel::Attributes get_attr(const QModelIndex &index) const  

Get supported operations for entry at given QModelIndex

Value get_value(const QModelIndex &index) const  

Get lua value at given model index

bool hasChildren(const QModelIndex &parent) const  

This member access is protected.

QVariant headerData(int section, Qt::Orientation orientation, int role) const  

This member access is protected.

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

This member access is protected.

QModelIndex parent(const QModelIndex &index) const  

This member access is protected.

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

This member access is protected.

int rowCount(const QModelIndex &parent) const  

This member access is protected.

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

This member access is protected.

static void table_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = Recursive)  

Shortcut function to display a modal lua table dialog.

Parameters list:

  • parent: parent widget
  • title: dialog window title
  • table: lua table to expose
  • attr: model attributes, control display and edit options

static void tree_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = Recursive)  

Shortcut function to display a modal lua table dialog.

Parameters list:

  • parent: parent widget
  • title: dialog window title
  • table: lua table to expose
  • attr: model attributes, control display and edit options

void update()  

Clear cached table content and reset model.

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 15:29:54 2013 using MkDoc