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
- 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)
- const QList<Value> & column_keys() const
- void fetch_all_column_keys()
- void fetch_all_row_keys()
- ValueRef get_value_ref(const QModelIndex &index) const
- const QList<Value> & row_keys() const
- void set_col_count(int c)
- void set_row_count(int c)
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
- void edit_error(const QString &message)
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 | 0x00000001 | Columns use numeric keys |
NumKeysRows | 0x00000002 | Rows use numeric keys |
RowColSwap | 0x00000004 | Swap rows and columns in views |
UnquoteHeader | 0x00000008 | Strip double quote from string keys |
UnquoteValues | 0x00000010 | Strip double quote from string values |
Editable | 0x00001000 | Allow editing exposed tables using views. |
EditFixedType | 0x00002000 | Prevent value type change when editing. |
EditLuaEval | 0x00004000 | Evaluate user input as a lua expression. |
EditInsertRow | 0x00008000 | Allow insertion of new rows. |
EditInsertCol | 0x00010000 | Allow insertion of new columns. |
EditRemoveRow | 0x00020000 | Allow deletion of existing rows. |
EditRemoveCol | 0x00040000 | 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
This member access is protected.
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.
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
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.
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.
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.
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.
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.
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.
Switch to numeric column keys and set column count
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.