Hi, just started a new project with PyQt which will involve a model, hence I've sat down and checked wether the python-version of the modeltest is up-to-date with the C++ version.
There turned out to be one bug (broken signal names) and the C++ version now also checks the layoutChanged signal. Attached two patches fix that. I didn't test yet against an actual model, so might have done something wrong in porting. Andreas -- You have the body of a 19 year old. Please return it before it gets wrinkled.
>From f78e30900d928f2e87202509e9ef0ddd14c634fa Mon Sep 17 00:00:00 2001 From: Andreas Pakulat <[email protected]> Date: Sun, 20 Feb 2011 21:56:40 +0100 Subject: [PATCH 1/2] Fix signal names. The PyQt documentation does not indicate that these signals have been renamed from their C++ version, so the testing of them was broken. --- tests/modeltest/modeltest.py | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/modeltest/modeltest.py b/tests/modeltest/modeltest.py index 64f0511..e2f7a9a 100644 --- a/tests/modeltest/modeltest.py +++ b/tests/modeltest/modeltest.py @@ -40,7 +40,7 @@ class ModelTest(QtCore.QObject): self.connect( self.model, QtCore.SIGNAL("columnsAboutToBeInserted(const QModelIndex&, int, int)"), self.runAllTests) self.connect( self.model, QtCore.SIGNAL("columnsAboutToBeRemoved(const QModelIndex&, int, int)"), self.runAllTests) - self.connect( self.model, QtCore.SIGNAL("columnsBeInserted(const QModelIndex&, int, int)"), self.runAllTests) + self.connect( self.model, QtCore.SIGNAL("columnsInserted(const QModelIndex&, int, int)"), self.runAllTests) self.connect( self.model, QtCore.SIGNAL("columnsRemoved(const QModelIndex&, int, int)"), self.runAllTests) self.connect( self.model, QtCore.SIGNAL("dataChanged(const QModelIndex&, const QModelIndex&)"), self.runAllTests) self.connect( self.model, QtCore.SIGNAL("headerDataChanged(Qt::Orientation, int, int)"), self.runAllTests) @@ -49,13 +49,13 @@ class ModelTest(QtCore.QObject): self.connect( self.model, QtCore.SIGNAL("modelReset()"), self.runAllTests) self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeInserted(const QModelIndex&, int, int)"), self.runAllTests) self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeRemoved(const QModelIndex&, int, int)"), self.runAllTests) - self.connect( self.model, QtCore.SIGNAL("rowsBeInserted(const QModelIndex&, int, int)"), self.runAllTests) + self.connect( self.model, QtCore.SIGNAL("rowsInserted(const QModelIndex&, int, int)"), self.runAllTests) self.connect( self.model, QtCore.SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), self.runAllTests) # Special checks for inserting/removing self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeInserted(const QModelIndex&, int, int)"), self.rowsAboutToBeInserted) self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeRemoved(const QModelIndex&, int, int)"), self.rowsAboutToBeRemoved) - self.connect( self.model, QtCore.SIGNAL("rowsBeInserted(const QModelIndex&, int, int)"), self.rowsInserted) + self.connect( self.model, QtCore.SIGNAL("rowsInserted(const QModelIndex&, int, int)"), self.rowsInserted) self.connect( self.model, QtCore.SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), self.rowsRemoved) self.runAllTests() -- 1.7.2.3
>From c7fb450a7da01dac6fb7351efb547af4ceba97d6 Mon Sep 17 00:00:00 2001 From: Andreas Pakulat <[email protected]> Date: Sun, 20 Feb 2011 21:57:25 +0100 Subject: [PATCH 2/2] Add new check for layout-changes. This is a test that has been added to the C++ version at some point, it verifies the first 100 rows to be changing in the correct way when the layout changes. --- tests/modeltest/modeltest.py | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/tests/modeltest/modeltest.py b/tests/modeltest/modeltest.py index e2f7a9a..d0c6e12 100644 --- a/tests/modeltest/modeltest.py +++ b/tests/modeltest/modeltest.py @@ -35,6 +35,7 @@ class ModelTest(QtCore.QObject): self.model = sip.cast(_model, QtCore.QAbstractItemModel) self.insert = [] self.remove = [] + self.changing = [] self.fetchingMore = False assert(self.model) @@ -53,6 +54,9 @@ class ModelTest(QtCore.QObject): self.connect( self.model, QtCore.SIGNAL("rowsRemoved(const QModelIndex&, int, int)"), self.runAllTests) # Special checks for inserting/removing + self.connect( self.model, QtCore.SIGNAL("layoutAboutToBeChanged()"), self.layoutAboutToBeChanged ) + self.connect( self.model, QtCore.SIGNAL("layoutChanged()"), self.layoutChanged ) + self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeInserted(const QModelIndex&, int, int)"), self.rowsAboutToBeInserted) self.connect( self.model, QtCore.SIGNAL("rowsAboutToBeRemoved(const QModelIndex&, int, int)"), self.rowsAboutToBeRemoved) self.connect( self.model, QtCore.SIGNAL("rowsInserted(const QModelIndex&, int, int)"), self.rowsInserted) @@ -341,6 +345,15 @@ class ModelTest(QtCore.QObject): assert(c['last'] == self.model.data(self.model.index(start-1, 0, c['parent']))) assert(c['next'] == self.model.data(self.model.index(start, 0, c['parent']))) + def layoutAboutToBeChanged(self): + for i in range(0, max(0, min( self.model.rowCount(), 100))): + self.changing.add( QtCore.QPersistentModelIndex( self.model.index( i, 0 ) ) ) + + def layoutChanged(self): + for c in self.changing: + assert(c == self.model.index( c.row(), c.column(), c.parent() )) + self.changing = [] + def checkChildren(self, parent, depth = 0): """ Called from parent() test. -- 1.7.2.3
_______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
