TableGridModel class reference
[Model/View module]

Declaration  

#include <QtLua/TableGridModel>

namespace QtLua {
class TableGridModel;
};

This class is a member of the QtLua namespace.

This class is declared in QtLua/qtluatablegridmodel.hh source file, line 79.

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)
  • QModelIndex index(int row, int column, const QModelIndex &parent) const

Private functions  

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  

Private fields  

Members detail  

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

This constructor is declared in QtLua/qtluatablegridmodel.hh source file, line 114.

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)  

This constructor is declared in QtLua/qtluatablegridmodel.hh source file, line 119.

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

~TableGridModel()  

This destructor is declared in QtLua/qtluatablegridmodel.hh source file, line 121.

enum Attribute  

This enum is declared in QtLua/qtluatablegridmodel.hh source file, line 88.

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  

This typedef is declared in QtLua/qtluatablegridmodel.hh source file, line 104.

TableGridModel::Attributes _attr  

This variable is declared in QtLua/qtluatablegridmodel.hh source file, line 227.

This member access is private.

QList<Value> _col_keys  

This variable is declared in QtLua/qtluatablegridmodel.hh source file, line 231.

This member access is private.

int _num_col_count  

This variable is declared in QtLua/qtluatablegridmodel.hh source file, line 232.

This member access is private.

int _num_row_count  

This variable is declared in QtLua/qtluatablegridmodel.hh source file, line 230.

This member access is private.

QList<Value> _row_keys  

This variable is declared in QtLua/qtluatablegridmodel.hh source file, line 229.

This member access is private.

This variable is declared in QtLua/qtluatablegridmodel.hh source file, line 226.

This member access is private.

Value _table  

This variable is declared in QtLua/qtluatablegridmodel.hh source file, line 228.

This member access is private.

void add_column_key(const Value &k)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 136.

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

void add_column_key(const String &k)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 139.

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

void add_row_key(const Value &k)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 130.

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

void add_row_key(const String &k)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 133.

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

void check_state() const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 215.

This member access is private.

int columnCount(const QModelIndex &parent) const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 202.

This member access is protected.

int column_count() const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 218.

This member access is private.

const QList<Value> & column_keys() const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 151.

Return current non-numeric column keys

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 203.

This member access is protected.

void edit_error(const QString &message)  

This Qt signal is declared in QtLua/qtluatablegridmodel.hh source file, line 174.

This member is a Qt signal.

void fetch_all_column_keys()  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 145.

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

void fetch_all_row_keys()  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 142.

Find all row keys or find maximum row numeric key

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 207.

This member access is protected.

ValueRef get_value_ref(const QModelIndex &index) const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 154.

Get ValueRef reference object to lua value at given QModelIndex

bool hasChildren(const QModelIndex &parent) const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 201.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 205.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 211.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 209.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 222.

This member access is private.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 220.

This member access is private.

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

This virtual function is declared in QtLua/qtluatablegridmodel.hh source file, line 180.

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 virtual function is declared in QtLua/qtluatablegridmodel.hh source file, line 195.

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 virtual function is declared in QtLua/qtluatablegridmodel.hh source file, line 190.

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 virtual function is declared in QtLua/qtluatablegridmodel.hh source file, line 185.

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 function is declared in QtLua/qtluatablegridmodel.hh source file, line 199.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 210.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 208.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 221.

This member access is private.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 219.

This member access is private.

int rowCount(const QModelIndex &parent) const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 200.

This member access is protected.

int row_count() const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 217.

This member access is private.

const QList<Value> & row_keys() const  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 148.

Return current non-numeric row keys

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 204.

This member access is protected.

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

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 206.

This member access is protected.

void set_col_count(int c)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 126.

Switch to numeric column keys and set column count

void set_row_count(int c)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 124.

Switch to numeric row keys and set row count

bool set_value_ref(const ValueRef &ref, const QByteArray &input)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 224.

This member access is private.

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)  

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 170.

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.

QModelIndex index(int row, int column, const QModelIndex &parent) const  

This function is for internal use only.

This function is declared in QtLua/qtluatablegridmodel.hh source file, line 198.

This member access is protected.

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 16:23:03 2013 using MkDoc