[Ktutorial-commits] SF.net SVN: ktutorial:[126] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-09 03:01:33
|
Revision: 126
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=126&view=rev
Author: danxuliu
Date: 2010-03-09 03:01:27 +0000 (Tue, 09 Mar 2010)
Log Message:
-----------
Fix header data update in TreeModel.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp 2010-03-09 02:18:24 UTC (rev 125)
+++ trunk/ktutorial/ktutorial-editor/src/view/TreeModel.cpp 2010-03-09 03:01:27 UTC (rev 126)
@@ -188,6 +188,11 @@
}
void TreeModel::treeItemDataChanged(TreeItem* item) {
+ if (item == mRootItem) {
+ emit headerDataChanged(Qt::Horizontal, 0, 0);
+ return;
+ }
+
QModelIndex index = createIndex(item->childIndex(), 0, item);
emit dataChanged(index, index);
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp 2010-03-09 02:18:24 UTC (rev 125)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TreeModelTest.cpp 2010-03-09 03:01:27 UTC (rev 126)
@@ -49,6 +49,7 @@
void testChangeChildrenOfRemovedNestedItem();
void testChangeItemData();
+ void testChangeRootItemData();
void testDataWithInvalidIndex();
void testDataWithInvalidRole();
@@ -516,6 +517,37 @@
QCOMPARE(qvariant_cast<QModelIndex>(argument), index);
}
+//Qt::Orientation must be declared as a metatype to be used in qvariant_cast
+Q_DECLARE_METATYPE(Qt::Orientation);
+
+void TreeModelTest::testChangeRootItemData() {
+ StubTreeItem* rootItem = new StubTreeItem("root");
+ TreeModel model(rootItem);
+
+ //Qt::Orientation must be registered in order to be used with QSignalSpy
+ int orientationIndexType = qRegisterMetaType<Qt::Orientation>("Qt::Orientation");
+ QSignalSpy headerDataChangedSpy(&model,
+ SIGNAL(headerDataChanged(Qt::Orientation, int, int)));
+
+ rootItem->setText("root modified");
+
+ QCOMPARE(model.rowCount(), 0);
+ QCOMPARE(model.columnCount(), 1);
+ QCOMPARE(model.headerData(0, Qt::Horizontal).toString(),
+ QString("root modified"));
+
+ QCOMPARE(headerDataChangedSpy.count(), 1);
+ QVariant argument = headerDataChangedSpy.at(0).at(0);
+ QCOMPARE(argument.userType(), orientationIndexType);
+ QCOMPARE(qvariant_cast<Qt::Orientation>(argument), Qt::Horizontal);
+ argument = headerDataChangedSpy.at(0).at(1);
+ QCOMPARE(argument.type(), QVariant::Int);
+ QCOMPARE(argument.toInt(), 0);
+ argument = headerDataChangedSpy.at(0).at(2);
+ QCOMPARE(argument.type(), QVariant::Int);
+ QCOMPARE(argument.toInt(), 0);
+}
+
void TreeModelTest::testDataWithInvalidIndex() {
TreeModel model(mSingleItem);
mSingleItem = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|