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
- enum Attribute
- typedef [...] Attributes
Functions
- TableGridModel(const Value &table, TableGridModel::Attributes attr, bool find_keys, QObject *parent = [...])
- TableGridModel(const Value &table, int row_count, int col_count, TableGridModel::Attributes attr, QObject *parent = [...])
- ~TableGridModel()
- void add_column_key(const Value &k)
- void add_column_key(const String &k)
- void add_row_key(const Value &k)
- void add_row_key(const String &k)
- int columnCount(const QModelIndex &parent) const
- QVariant data(const QModelIndex &index, int role) const
- void fetch_all_column_keys()
- void fetch_all_row_keys()
- Qt::ItemFlags flags(const QModelIndex &index) const
- ValueRef get_value_ref(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)
- 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)
- void set_col_count(int c)
- void set_row_count(int c)
Protected function
- virtual Value new_row_table(State &st) const
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
No documentation available
Specifies TableGridModel behavior for a given lua table
Identifier | Value | Description |
---|---|---|
NumKeysCols | 0 | Columns use numeric keys |
NumKeysRows | 0 | Rows use numeric keys |
RowColSwap | 0 | Swap rows and columns in views |
UnquoteHeader | 0 | Strip double quote from string keys |
UnquoteValues | 0 | Strip double quote from string values |
Editable | 0 | Allow editing exposed tables using views. |
EditFixedType | 0 | Prevent value type change when editing. |
EditLuaEval | 0 | Evaluate user input as a lua expression. |
EditInsertRow | 0 | Allow insertion of new rows. |
EditInsertCol | 0 | Allow insertion of new columns. |
EditRemoveRow | 0 | Allow deletion of existing rows. |
EditRemoveCol | 0 | Allow 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
Find all column keys or find maximum row numeric key. Must be called with at least one available row
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
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
Switch to numeric column keys and set column count
Switch to numeric row keys and set row count