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 table 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 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 ItemViewDialog class.

Members  

Types  

Functions  

Protected functions  

  • 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 insertColumns(int column, int count, const QModelIndex &parent)
  • bool insertRows(int row, int count, const QModelIndex &parent)
  • virtual Value new_cell_value(State *st, int row, int col) const
  • virtual Value new_column_key(State *st, int col) const
  • virtual Value new_row_key(State *st, int row) const
  • virtual Value new_row_table(State *st, int row) const
  • QModelIndex parent(const QModelIndex &index) const
  • bool removeColumns(int column, 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)
  • bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)

Static function  

  • static void table_dialog(QWidget *parent, const QString &title, const Value &table, TableGridModel::Attributes attr = [...], const ValueBase::List *colkeys = [...], const ValueBase::List *rowkeys = [...])

Signal  

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
NumKeysCols0x00000001Columns use numeric keys
NumKeysRows0x00000002Rows use numeric keys
RowColSwap0x00000004Swap rows and columns in views
UnquoteHeader0x00000008Strip double quote from string keys
UnquoteValues0x00000010Strip double quote from string values
Editable0x00001000Allow editing exposed tables using views.
EditFixedType0x00002000Prevent value type change when editing.
EditLuaEval0x00004000Evaluate user input as a lua expression.
EditInsertRow0x00008000Allow insertion of new rows.
EditInsertCol0x00010000Allow insertion of new columns.
EditRemoveRow0x00020000Allow deletion of existing rows.
EditRemoveCol0x00040000Allow 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  

This member access is protected.

const QList<Value> & column_keys() const  

Return current non-numeric column keys

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.

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  

This member access is protected.

ValueRef get_value_ref(const QModelIndex &index) const  

Get ValueRef reference object to lua value at given QModelIndex

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 insertColumns(int column, int count, const QModelIndex &parent)  

This member access is protected.

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

This member access is protected.

virtual Value new_cell_value(State *st, int row, int col) const  

This member access is protected.

Return the initial value used when inserting new columns for cell at given position. The default implementation returns a nil value.

virtual Value new_column_key(State *st, int col) const  

This member access is protected.

Return a column key suitable for given column. This function is called when inserting a new column in non-numeric column key mode. The new key must no appear in the current list of column keys.

virtual Value new_row_key(State *st, int row) const  

This member access is protected.

Return a row key suitable for given row. This function is called when inserting a new row in non-numeric row key mode. The new key must no appear in the current list of row keys.

virtual Value new_row_table(State *st, int row) const  

This member access is protected.

Return the a new table for new row insertion. The default implementation returns a lua Value::TTable value filled with values provided by the TableGridModel::new_cell_value function.

QModelIndex parent(const QModelIndex &index) const  

This member access is protected.

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

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.

const QList<Value> & row_keys() const  

Return current non-numeric row keys

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

This member access is protected.

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

This member access is protected.

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

static void table_dialog(QWidget *parent, const QString &title, const Value &table, TableGridModel::Attributes attr = TableGridModel::Attributes(), const ValueBase::List *colkeys = 0, const ValueBase::List *rowkeys = 0)  

Convenience 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
  • colkeys: list of lua value to use as column keys, use TableGridModel::fetch_all_column_keys if NULL.
  • rowkeys: list of lua value to use as row keys, use TableGridModel::fetch_all_row_keys if NULL.

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