TableGridModel class reference
[Model/View module]

Declaration  

#include <QtLua/TableGridModel>

namespace QtLua {
class TableGridModel;
};

This class is a member of the QtLua namespace.

Description  

This class can be used to expose 2 dimensionnal arrays stored as nested lua tables to QTableView widgets. Each row in the grid matches an entry in the provided lua table, and each column describe keys used to access nested tables.

Column and row keys can be independently handled as numerical indexes or as plain lua value. When in numerical key mode, all keys are assumed to be numbers, first key is 1 and keys order is preserved when inserting or deleting entries.

Exposed keys can be defined in several ways:

  • all lua values can be automatically fetched from tables keys, or

  • keys can be user specified, or

  • incremental numerical keys can be used.

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

Lua tables can be edited from Qt views using this model. The TableGridModel::Attribute flags can be used to finely 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. This is partially due to lack of lua mechanism to implement efficient table change event.

Usage example:

// code from examples/cpp/mvc/tablegridview.cc:31

state = new QtLua::State();

// 2 dimensions array using nested lua tables
QtLua::Value table(state->exec_statements(
"return { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }"
)[0]);

// Create a new model and expose lua table
model = new QtLua::TableGridModel(table, QtLua::TableGridModel::Editable, true);

// Create Qt view widget
tableview = new QTableView(0);
tableview->setModel(model);

setCentralWidget(tableview);

See also TableDialog class.

Members  

Types  

Functions  

Protected function  

Members detail  

TableGridModel(const Value &table, TableGridModel::Attributes attr, bool find_keys, QObject *parent = 0)  

Create a new lua grid table model.

This constructor will determine rows and columns keys by calling TableGridModel::fetch_all_row_keys and TableGridModel::fetch_all_column_keys if find_keys is true.

TableGridModel(const Value &table, int row_count, int col_count, TableGridModel::Attributes attr, QObject *parent = 0)  

Create a new lua grid table model and use numerical keys with given bounds

~TableGridModel()  

No documentation available

enum Attribute  

Specifies TableGridModel behavior for a given lua table

IdentifierValueDescription
NumKeysCols0Columns use numeric keys
NumKeysRows0Rows use numeric keys
RowColSwap0Swap rows and columns in views
UnquoteHeader0Strip double quote from string keys
UnquoteValues0Strip double quote from string values
Editable0Allow editing exposed tables using views.
EditFixedType0Prevent value type change when editing.
EditLuaEval0Evaluate user input as a lua expression.
EditInsertRow0Allow insertion of new rows.
EditInsertCol0Allow insertion of new columns.
EditRemoveRow0Allow deletion of existing rows.
EditRemoveCol0Allow deletion of existing columns.

See also TableGridModel::Attributes typedef.

typedef TableGridModel::Attribute Attributes  

No documentation available

void add_column_key(const Value &k)  

Switch to non-numeric column keys and Add a column key that must appear in the table

void add_column_key(const String &k)  

Switch to non-numeric column keys and Add a column key that must appear in the table

void add_row_key(const Value &k)  

Switch to non-numeric row keys and Add a row key that must appear in the table

void add_row_key(const String &k)  

Switch to non-numeric row keys and Add a row key that must appear in the table

int columnCount(const QModelIndex &parent) const  

No documentation available

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

No documentation available

void fetch_all_column_keys()  

Find all column keys or find maximum row numeric key. Must be called with at least one available row

void fetch_all_row_keys()  

Find all row keys or find maximum row numeric key

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

No documentation available

ValueRef get_value_ref(const QModelIndex &index) const  

Get ValueRef reference object to lua value at given QModelIndex

bool hasChildren(const QModelIndex &parent) const  

No documentation available

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

No documentation available

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

No documentation available

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

No documentation available

virtual Value new_row_table(State &st) const  

This member access is protected.

Return the empty table object to use for new row insertion. The default implementation returns a lua Value::TTable value.

QModelIndex parent(const QModelIndex &index) const  

No documentation available

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

No documentation available

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

No documentation available

int rowCount(const QModelIndex &parent) const  

No documentation available

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

No documentation available

bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)  

No documentation available

void set_col_count(int c)  

Switch to numeric column keys and set column count

void set_row_count(int c)  

Switch to numeric row keys and set row count

Valid XHTML 1.0 StrictGenerated by diaxen on Sun Jan 8 22:46:02 2012 using MkDoc