Re-enable access to protected functions
[lqt/mk.git] / test / protected_test.lua
blob90ead6f54cb52fd63253c967ecd283994abd9d55
1 require "qtcore"
2 require "qtgui"
4 A = QApplication(1, {'Protected test'})
6 -- We will implement our custom model
7 M = QAbstractListModel()
9 -- stored in the environment table of the userdata
10 M.luaData = {'Hello', 'World'}
12 -- these are implemented virtual methods
13 function M:rowCount()
14 return #self.luaData
15 end
17 local empty = QVariant()
18 function M:data(index, role)
19 if role == Qt.ItemDataRole.DisplayRole then
20 local row = index:row()
21 return QVariant(self.luaData[row + 1])
22 end
23 return empty
24 end
26 -- this is a custom helper function
27 function M:addAnotherString(str)
28 table.insert(self.luaData, str)
29 local row = #self.luaData - 1
30 local index = self:createIndex(row, 0, 0)
31 self:dataChanged(index, index)
32 end
34 -- some simple layout - list and a button
35 MW = QWidget()
37 W = QListView()
38 W:setModel(M)
40 B = QPushButton('Add Lua data')
41 local counter = 1
42 B:connect('2clicked()', function()
43 M:addAnotherString('Added text ' .. counter)
44 counter = counter + 1
45 end)
47 L = QVBoxLayout()
48 L:addWidget(W)
49 L:addWidget(B)
50 MW:setLayout(L)
52 MW:show()
53 A.exec()