From 9bba92715d96939e4d36c6ea42e8b466756bf891 Mon Sep 17 00:00:00 2001 From: Alexader Karaivanov Date: Wed, 10 Mar 2010 12:42:39 +0100 Subject: Fixes Q3ListViewItem grandchildren not sorted if item has one child Q3ListViewItem::sortChildItems() used to exits early if there is only 1 child item and leaves grandchildren unsorted. Merge-request: 2260 Reviewed-by: Olivier Goffart --- src/qt3support/itemviews/q3listview.cpp | 9 ++- tests/auto/q3listview/tst_q3listview.cpp | 126 ++++++++++++++++++++++++++++++- 2 files changed, 133 insertions(+), 2 deletions(-) diff --git a/src/qt3support/itemviews/q3listview.cpp b/src/qt3support/itemviews/q3listview.cpp index 12dad84..4900827 100644 --- a/src/qt3support/itemviews/q3listview.cpp +++ b/src/qt3support/itemviews/q3listview.cpp @@ -1324,8 +1324,15 @@ void Q3ListViewItem::sortChildItems(int column, bool ascending) const int nColumns = (listView() ? listView()->columns() : 0); // and don't sort if we already have the right sorting order - if (column > nColumns || childItem == 0 || childItem->siblingItem == 0) + if (column > nColumns || childItem == 0) return; + + // If there is just one child, just sort its children + if (childItem->siblingItem == 0) { + if (childItem->isOpen()) + childItem->sortChildItems(column, ascending); + return; + } // make an array for qHeapSort() Q3ListViewPrivate::SortableItem * siblings diff --git a/tests/auto/q3listview/tst_q3listview.cpp b/tests/auto/q3listview/tst_q3listview.cpp index 4de6f95..56fa25f 100644 --- a/tests/auto/q3listview/tst_q3listview.cpp +++ b/tests/auto/q3listview/tst_q3listview.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include #include @@ -87,6 +88,8 @@ public slots: private slots: void getSetCheck(); void sortchild(); + void sortchild2(); // item -> item -> 3 items + void sortchild3(); // item -> 3 items void takeItem_data(); void takeItem(); void selections_mouseClick_data(); @@ -262,7 +265,7 @@ void tst_Q3ListView::sortchild() QVERIFY( item == item1 ); listview->setSorting( 0, FALSE ); - + item = listview->firstChild(); QVERIFY( item == item1 ); item = item->itemBelow(); @@ -291,6 +294,127 @@ void tst_Q3ListView::sortchild() delete listview; } +void tst_Q3ListView::sortchild2() +{ + Q3ListView* listview = new Q3ListView( 0 ); + + listview->addColumn( "" ); + + Q3ListViewItem* item1 = new Q3ListViewItem( listview, "zzz" ); + Q3ListViewItem* item2 = new Q3ListViewItem( listview, "hhh" ); + Q3ListViewItem* item3 = new Q3ListViewItem( listview, "bbb" ); + Q3ListViewItem* item4 = new Q3ListViewItem( listview, "jjj" ); + Q3ListViewItem* item5 = new Q3ListViewItem( listview, "ddd" ); + Q3ListViewItem* item6 = new Q3ListViewItem( listview, "lll" ); + + Q3ListViewItem* item31 = new Q3ListViewItem( item3, "bbb-level2" ); + + Q3ListViewItem* item31b = new Q3ListViewItem( item31, "234" ); + Q3ListViewItem* item31c = new Q3ListViewItem( item31, "345" ); + Q3ListViewItem* item31a = new Q3ListViewItem( item31, "123" ); + + listview->setOpen( item3, TRUE ); + listview->setOpen( item31, TRUE ); + + listview->setSorting( 0, TRUE ); + listview->show(); + + Q3ListViewItem *item = listview->firstChild(); + QVERIFY( item == item3 ); + item = item->itemBelow(); + QVERIFY( item == item31 ); + item = item->itemBelow(); + QVERIFY( item == item31a ); + item = item->itemBelow(); + QVERIFY( item == item31b ); + item = item->itemBelow(); + QVERIFY( item == item31c ); + item = item->itemBelow(); + QVERIFY( item == item5 ); + item = item->itemBelow(); + QVERIFY( item == item2 ); + item = item->itemBelow(); + QVERIFY( item == item4 ); + item = item->itemBelow(); + QVERIFY( item == item6 ); + item = item->itemBelow(); + QVERIFY( item == item1 ); + + listview->setSorting( 0, FALSE ); + + item = listview->firstChild(); + QVERIFY( item == item1 ); + item = item->itemBelow(); + QVERIFY( item == item6 ); + item = item->itemBelow(); + QVERIFY( item == item4 ); + item = item->itemBelow(); + QVERIFY( item == item2 ); + item = item->itemBelow(); + QVERIFY( item == item5 ); + item = item->itemBelow(); + QVERIFY( item == item3 ); + item = item->itemBelow(); + QVERIFY( item == item31 ); + item = item->itemBelow(); + QVERIFY( item == item31c ); + item = item->itemBelow(); + QVERIFY( item == item31b ); + item = item->itemBelow(); + QVERIFY( item == item31a ); + + item = listview->firstChild(); + item->moveItem( item->itemBelow() ); + + listview->setSorting( 0, FALSE ); + QVERIFY( item == listview->firstChild() ); + + delete listview; +} + +void tst_Q3ListView::sortchild3() +{ + Q3ListView* listview = new Q3ListView( 0 ); + + listview->addColumn( "" ); + + Q3ListViewItem* item3 = new Q3ListViewItem( listview, "bbb" ); + + + Q3ListViewItem* item31b = new Q3ListViewItem( item3, "234" ); + Q3ListViewItem* item31c = new Q3ListViewItem( item3, "345" ); + Q3ListViewItem* item31a = new Q3ListViewItem( item3, "123" ); + + listview->setOpen( item3, TRUE ); + + listview->setSorting( 0, TRUE ); + listview->show(); + + Q3ListViewItem *item = listview->firstChild(); + QVERIFY( item == item3 ); + item = item->itemBelow(); + QVERIFY( item == item31a ); + item = item->itemBelow(); + QVERIFY( item == item31b ); + item = item->itemBelow(); + QVERIFY( item == item31c ); + item = item->itemBelow(); + + listview->setSorting( 0, FALSE ); + + item = listview->firstChild(); + QVERIFY( item == item3 ); + item = item->itemBelow(); + QVERIFY( item == item31c ); + item = item->itemBelow(); + QVERIFY( item == item31b ); + item = item->itemBelow(); + QVERIFY( item == item31a ); + + delete listview; +} + + void tst_Q3ListView::takeItem_data() { QTest::addColumn("selectionMode"); -- cgit v0.12