Skip to content

Commit 8f1fd8e

Browse files
committed
add qtmodeltester and SliceBaseTableModel, DesignAxisModel fixes
1 parent 24f4147 commit 8f1fd8e

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/slice/models.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ def setData(self, index, value, role):
3636
return False
3737

3838
def rowCount(self, index):
39-
return len(self._data)
39+
# the index validity check approach addresses the qabstractitemmodel.cpp check:
40+
# QtWarningMsg: FAIL! model->hasChildren(topIndex) () returned FALSE (qabstractitemmodeltester.cpp:366)
41+
# See https://stackoverflow.com/a/50988188/2848172
42+
if index.isValid():
43+
return 0
44+
else:
45+
return len(self._data)
4046

4147
def columnCount(self, index):
42-
return len(self._data[0])
48+
# the index validity check approach addresses the qabstractitemmodel.cpp check:
49+
# QtWarningMsg: FAIL! model->hasChildren(topIndex) () returned FALSE (qabstractitemmodeltester.cpp:366)
50+
# See https://stackoverflow.com/a/50988188/2848172
51+
if index.isValid():
52+
return 0
53+
else:
54+
return len(self._data[0])
4355

4456
def get_data(self):
4557
return self._data
@@ -193,13 +205,18 @@ def headerData(self, section, orientation, role):
193205
return self._h_header[section]
194206

195207
def flags(self, index):
208+
# Note: index validity checks in this block address qabstractitemmodeltester error:
209+
# QtWarningMsg: FAIL! flags == Qt::ItemIsDropEnabled || flags == 0 () returned FALSE (qabstractitemmodeltester.cpp:329)
210+
196211
# column 0 (axis value range and default) is set
197212
# to non-editable
198-
if index.column() == 0:
213+
if index.isValid() and index.column() == 0:
199214
return super().flags(index) | Qt.ItemIsSelectable
200215
# column 1 (instance value) is set to editable
201-
else:
216+
elif index.isValid() and index.column() == 1:
202217
return super().flags(index) | Qt.ItemIsEditable
218+
else:
219+
return super().flags(index)
203220

204221
def load_font(self, font_model):
205222
ttfont = TTFont(font_model.fontpath)

tests/test_models.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from PyQt5.QtWidgets import QTableView
4+
5+
from slice.models import DesignAxisModel, FontModel, FontBitFlagModel, FontNameModel
6+
7+
8+
def test_font_model():
9+
fm = FontModel("testpath")
10+
assert fm.fontpath == "testpath"
11+
12+
13+
def test_designaxis_model_default(qtbot, qtmodeltester):
14+
tableview = QTableView()
15+
model = DesignAxisModel()
16+
tableview.setModel(model)
17+
qtbot.addWidget(tableview)
18+
# check model with default instantiation
19+
qtmodeltester.check(model)
20+
21+
22+
def test_designaxis_model_filled(qtbot, qtmodeltester):
23+
pass

0 commit comments

Comments
 (0)