10 #include <argos3/core/utility/logging/argos_log.h>
11 #include <argos3/core/wrappers/lua/lua_utility.h>
19 bool b_remove_empty_tables,
21 QAbstractItemModel(pc_parent),
23 m_bRemoveEmptyTables(b_remove_empty_tables) {
39 if(!c_index.isValid()) {
42 if(n_role != Qt::DisplayRole) {
46 return pcItem->
GetData(c_index.column());
53 if (!c_index.isValid()) {
57 return Qt::ItemIsEnabled;
66 const QModelIndex& c_parent)
const {
67 if(!hasIndex(n_row, n_column, c_parent)) {
71 if(!c_parent.isValid()) {
72 pcParentItem = m_pcDataRoot;
79 return createIndex(n_row, n_column, pcChildItem);
90 if (!c_index.isValid()) {
95 if (pcParentItem == m_pcDataRoot) {
99 return createIndex(pcParentItem->
GetRow(), 0, pcParentItem);
108 if(c_parent.column() > 0) {
111 if(!c_parent.isValid()) {
112 pcParentItem = m_pcDataRoot;
124 m_ptState = pt_state;
135 lua_pushnil(m_ptState);
136 lua_getglobal(m_ptState,
"_G");
139 lua_pop(m_ptState, 2);
155 QList<QVariant> cData;
156 switch(lua_type(pt_state, -2)) {
158 cData << lua_toboolean(pt_state, -2);
161 cData << lua_tonumber(pt_state, -2);
164 cData << lua_tostring(pt_state, -2);
168 if(lua_istable(pt_state, -1)) {
171 lua_pushnil(pt_state);
172 while(lua_next(pt_state, -2)) {
176 lua_pop(pt_state, 1);
178 if(m_bRemoveEmptyTables) {
185 switch(lua_type(pt_state, -1)) {
187 cData << lua_toboolean(pt_state, -1);
191 cData << lua_tonumber(pt_state, -1);
195 cData << lua_tostring(pt_state, -1);
199 cData[0] = cData[0].toString() + tr(
"()");
212 bool b_remove_empty_tables,
213 QObject* pc_parent) :
220 Qt::Orientation e_orientation,
222 if(e_orientation != Qt::Horizontal ||
223 n_role != Qt::DisplayRole ||
228 return n_section == 0 ? tr(
"Variable") : tr(
"Value");
243 int nValueType = lua_type(pt_state, -1);
244 int nKeyType = lua_type(pt_state, -2);
245 if(nValueType == LUA_TSTRING || nValueType == LUA_TNUMBER || nValueType == LUA_TBOOLEAN) {
246 if(nKeyType != LUA_TSTRING) {
249 else if(nKeyType == LUA_TSTRING) {
250 return std::string(lua_tostring(pt_state, -2)) !=
"_VERSION";
253 else if(nValueType == LUA_TTABLE) {
254 if(nKeyType == LUA_TNUMBER) {
257 else if(nKeyType == LUA_TSTRING) {
259 std::string(lua_tostring(pt_state, -2)) !=
"_G" &&
260 std::string(lua_tostring(pt_state, -2)) !=
"coroutine" &&
261 std::string(lua_tostring(pt_state, -2)) !=
"debug" &&
262 std::string(lua_tostring(pt_state, -2)) !=
"io" &&
263 std::string(lua_tostring(pt_state, -2)) !=
"os" &&
264 std::string(lua_tostring(pt_state, -2)) !=
"package" &&
265 std::string(lua_tostring(pt_state, -2)) !=
"string" &&
266 std::string(lua_tostring(pt_state, -2)) !=
"table";
276 bool b_remove_empty_tables,
277 QObject* pc_parent) :
284 Qt::Orientation e_orientation,
300 int nValueType = lua_type(pt_state, -1);
301 int nKeyType = lua_type(pt_state, -2);
302 if(nValueType == LUA_TFUNCTION && nKeyType == LUA_TSTRING) {
304 std::string(lua_tostring(pt_state, -2)) !=
"assert" &&
305 std::string(lua_tostring(pt_state, -2)) !=
"collectgarbage" &&
306 std::string(lua_tostring(pt_state, -2)) !=
"dofile" &&
307 std::string(lua_tostring(pt_state, -2)) !=
"error" &&
308 std::string(lua_tostring(pt_state, -2)) !=
"gcinfo" &&
309 std::string(lua_tostring(pt_state, -2)) !=
"getfenv" &&
310 std::string(lua_tostring(pt_state, -2)) !=
"getmetatable" &&
311 std::string(lua_tostring(pt_state, -2)) !=
"ipairs" &&
312 std::string(lua_tostring(pt_state, -2)) !=
"load" &&
313 std::string(lua_tostring(pt_state, -2)) !=
"loadfile" &&
314 std::string(lua_tostring(pt_state, -2)) !=
"loadstring" &&
315 std::string(lua_tostring(pt_state, -2)) !=
"module" &&
316 std::string(lua_tostring(pt_state, -2)) !=
"newproxy" &&
317 std::string(lua_tostring(pt_state, -2)) !=
"next" &&
318 std::string(lua_tostring(pt_state, -2)) !=
"pairs" &&
319 std::string(lua_tostring(pt_state, -2)) !=
"pcall" &&
320 std::string(lua_tostring(pt_state, -2)) !=
"rawequal" &&
321 std::string(lua_tostring(pt_state, -2)) !=
"rawget" &&
322 std::string(lua_tostring(pt_state, -2)) !=
"rawset" &&
323 std::string(lua_tostring(pt_state, -2)) !=
"require" &&
324 std::string(lua_tostring(pt_state, -2)) !=
"select" &&
325 std::string(lua_tostring(pt_state, -2)) !=
"setfenv" &&
326 std::string(lua_tostring(pt_state, -2)) !=
"setmetatable" &&
327 std::string(lua_tostring(pt_state, -2)) !=
"unpack" &&
328 std::string(lua_tostring(pt_state, -2)) !=
"xpcall";
330 else if(nValueType == LUA_TTABLE) {
331 if(nKeyType == LUA_TNUMBER) {
334 else if(nKeyType == LUA_TSTRING) {
336 std::string(lua_tostring(pt_state, -2)) !=
"_G" &&
337 std::string(lua_tostring(pt_state, -2)) !=
"coroutine" &&
338 std::string(lua_tostring(pt_state, -2)) !=
"debug" &&
339 std::string(lua_tostring(pt_state, -2)) !=
"io" &&
340 std::string(lua_tostring(pt_state, -2)) !=
"os" &&
341 std::string(lua_tostring(pt_state, -2)) !=
"package";
QVariant GetData(int n_col) const
CQTOpenGLLuaStateTreeFunctionModel(lua_State *pt_state, bool b_remove_empty_tables, QObject *pc_parent=0)
CQTOpenGLLuaStateTreeItem * GetParent()
virtual bool IsTypeVisitable(lua_State *pt_state)
virtual ~CQTOpenGLLuaStateTreeModel()
CQTOpenGLLuaStateTreeModel(lua_State *pt_state, bool b_remove_empty_tables, QObject *pc_parent=0)
virtual bool IsTypeVisitable(lua_State *pt_state)=0
virtual Qt::ItemFlags flags(const QModelIndex &c_index) const
virtual QVariant data(const QModelIndex &c_index, int n_role) const
virtual QVariant headerData(int n_section, Qt::Orientation e_orientation, int n_role=Qt::DisplayRole) const
void ProcessLuaState(lua_State *pt_state, CQTOpenGLLuaStateTreeItem *pc_item)
virtual QModelIndex index(int n_row, int n_column, const QModelIndex &c_parent=QModelIndex()) const
CQTOpenGLLuaStateTreeVariableModel(lua_State *pt_state, bool b_remove_empty_tables, QObject *pc_parent=0)
size_t GetNumChildren() const
virtual int columnCount(const QModelIndex &c_parent=QModelIndex()) const
CQTOpenGLLuaStateTreeItem * GetChild(size_t un_idx)
virtual bool IsTypeVisitable(lua_State *pt_state)
void AddChild(CQTOpenGLLuaStateTreeItem *pc_child)
The namespace containing all the ARGoS related code.
virtual int rowCount(const QModelIndex &c_parent=QModelIndex()) const
virtual QModelIndex parent(const QModelIndex &c_index) const
void SetLuaState(lua_State *pt_state)
virtual QVariant headerData(int n_section, Qt::Orientation e_orientation, int n_role=Qt::DisplayRole) const
void RemoveChild(CQTOpenGLLuaStateTreeItem *pc_child)
virtual int columnCount(const QModelIndex &c_parent=QModelIndex()) const