TableTreeModel class reference
[Model/View module]
Declaration
#include <QtLua/TableTreeModel>
namespace QtLua {
class TableTreeModel;
};
This class is a member of the QtLua namespace.
This class is declared in QtLua/qtluatabletreemodel.hh source file, line 68.
Description
This class can be used to expose lua tables content to Qt view widgets in a flat or hierarchical manner.
Lua tables and UserData objects with valid table operations are handled.
Lua tables can be edited from Qt views using this model. The TableTreeModel::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 and the TableTreeModel::update function must be called to refresh views on heavy modifications. This is partially due to lack of lua mechanism to implement efficient table change event. If you need to edit the underlying data from lua and have the views updated automatically, you might use the UserItemModel approach instead.
Usage example:
// code from examples/cpp/mvc/tabletreeview.cc:30
state = new QtLua::State();
state->openlib(QtLua::AllLibs);
// Create a new model and expose lua global table
model = new QtLua::TableTreeModel(state->at("_G"), QtLua::TableTreeModel::Recursive);
// Create Qt view widget
treeview = new QTreeView(0);
treeview->setModel(model);
setCentralWidget(treeview);
See also ItemViewDialog class.
Members
Types
- enum Attribute
- typedef [...] Attributes
- enum ColumnId
Functions
- TableTreeModel(const Value &root, TableTreeModel::Attributes attr, QObject *parent = [...])
- ~TableTreeModel()
- TableTreeModel::Attributes get_attr(const QModelIndex &index) const
- Value get_value(const QModelIndex &index) const
- void update()
Protected functions
- QModelIndex buddy(const QModelIndex &index) const
- 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 insertRows(int row, int count, const QModelIndex &parent)
- QModelIndex parent(const QModelIndex &index) const
- 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)
- QModelIndex index(int row, int column, const QModelIndex &parent) const
Private functions
- void check_state() const
- TableTreeModel::ColumnId get_column_id(int col, TableTreeModel::Attributes attr) const
- TableTreeKeys * table_from_index(const QModelIndex &index) const
Static functions
- static void table_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = [...])
- static void tree_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = [...])
Signal
- void edit_error(const QString &message)
Private fields
Members detail
TableTreeModel(const Value &root, TableTreeModel::Attributes attr, QObject *parent = 0)
This constructor is declared in QtLua/qtluatabletreemodel.hh source file, line 98.
Create a new lua table model.
This destructor is declared in QtLua/qtluatabletreemodel.hh source file, line 100.
This enum is declared in QtLua/qtluatabletreemodel.hh source file, line 77.
Specifies TableTreeModel behavior for a given lua table
Identifier | Value | Description |
---|---|---|
Recursive | 0x00000001 | Expose nested tables too. |
UserDataIter | 0x00000002 | Iterate over UserData objects too. |
HideKey | 0x00000020 | Do not show key column. |
HideValue | 0x00000040 | Do not show value column. |
HideType | 0x00000004 | Do not show value type column. |
UnquoteKeys | 0x00000008 | Strip double quotes from string keys |
UnquoteValues | 0x00000010 | Strip double quotes from string values |
Editable | 0x00001000 | Allow editing exposed lua tables. |
EditFixedType | 0x00002000 | Prevent value type change when editing. |
EditLuaEval | 0x00004000 | Evaluate user input as a lua expression. |
EditInsert | 0x00008000 | Allow insertion of new entries. |
EditRemove | 0x00010000 | Allow deletion of existing entries. |
EditKey | 0x00020000 | Allow entry key update. |
EditAll | 0x00039000 | Editable, EditInsert, EditRemove and EditKey allowed |
See also TableTreeModel::Attributes typedef.
typedef TableTreeModel::Attribute Attributes
This typedef is declared in QtLua/qtluatabletreemodel.hh source file, line 95.
This variable is declared in QtLua/qtluatabletreemodel.hh source file, line 162.
This member access is private.
TableTreeKeys *_table
This variable is declared in QtLua/qtluatabletreemodel.hh source file, line 163.
This member access is private.
QModelIndex buddy(const QModelIndex &index) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 143.
This member access is protected.
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 159.
This member access is private.
int columnCount(const QModelIndex &parent) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 146.
This member access is protected.
QVariant data(const QModelIndex &index, int role) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 147.
This member access is protected.
void edit_error(const QString &message)
This Qt signal is declared in QtLua/qtluatabletreemodel.hh source file, line 137.
This member is a Qt signal.
Qt::ItemFlags flags(const QModelIndex &index) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 150.
This member access is protected.
TableTreeModel::Attributes get_attr(const QModelIndex &index) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 109.
Get supported operations for entry at given QModelIndex
TableTreeModel::ColumnId get_column_id(int col, TableTreeModel::Attributes attr) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 157.
This member access is private.
Value get_value(const QModelIndex &index) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 106.
Get lua value at given model index
bool hasChildren(const QModelIndex &parent) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 145.
This member access is protected.
QVariant headerData(int section, Qt::Orientation orientation, int role) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 148.
This member access is protected.
bool insertRows(int row, int count, const QModelIndex &parent)
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 152.
This member access is protected.
QModelIndex parent(const QModelIndex &index) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 142.
This member access is protected.
bool removeRows(int row, int count, const QModelIndex &parent)
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 151.
This member access is protected.
int rowCount(const QModelIndex &parent) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 144.
This member access is protected.
bool setData(const QModelIndex &index, const QVariant &value, int role)
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 149.
This member access is protected.
static void table_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = Recursive)
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 124.
Shortcut 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
TableTreeKeys * table_from_index(const QModelIndex &index) const
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 160.
This member access is private.
static void tree_dialog(QWidget *parent, const QString &title, const Value &table, TableTreeModel::Attributes attr = Recursive)
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 121.
Shortcut 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
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 103.
Clear cached table content and reset model.
This enum is for internal use only.
This enum is declared in QtLua/qtluatabletreemodel.hh source file, line 128.
Columns ids
Identifier | Value | Description |
---|---|---|
ColKey | 0 | |
ColValue | 1 | |
ColType | 2 | |
ColNone | 3 |
QModelIndex index(int row, int column, const QModelIndex &parent) const
This function is for internal use only.
This function is declared in QtLua/qtluatabletreemodel.hh source file, line 141.
This member access is protected.