From b2f995ff508174fd872f8251dd8dfa4aa90448f3 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sat, 15 Jan 2011 06:33:25 +0200 Subject: [PATCH] Fixed crash in qt download dialog --- qt/update_dialog.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/qt/update_dialog.cpp b/qt/update_dialog.cpp index 984c783085..377c1b5165 100644 --- a/qt/update_dialog.cpp +++ b/qt/update_dialog.cpp @@ -132,25 +132,42 @@ namespace qt } } + QTreeWidgetItem * MatchedItem(QTreeWidgetItem & parent, int index) + { + if (index >= 0) + { + for (int i = 0; i < parent.childCount(); ++i) + { + QTreeWidgetItem * item = parent.child(i); + if (index == item->data(KColumnIndexCountry, Qt::UserRole).toInt()) + return item; + } + } + return NULL; + } + /// @return can be null if index is invalid QTreeWidgetItem * GetTreeItemByIndex(QTreeWidget & tree, TIndex const & index) { QTreeWidgetItem * item = 0; - if (index.m_group >= 0 && index.m_group < tree.topLevelItemCount()) + if (index.m_group >= 0) { - item = tree.topLevelItem(index.m_group); - ASSERT_EQUAL( item->data(KColumnIndexCountry, Qt::UserRole).toInt(), index.m_group, () ); - if (index.m_country >= 0 && index.m_country < item->childCount()) + for (int i = 0; i < tree.topLevelItemCount(); ++i) { - item = item->child(index.m_country); - ASSERT_EQUAL( item->data(KColumnIndexCountry, Qt::UserRole).toInt(), index.m_country, () ); - if (index.m_region >= 0 && index.m_region < item->childCount()) + QTreeWidgetItem * grItem = tree.topLevelItem(i); + if (index.m_group == grItem->data(KColumnIndexCountry, Qt::UserRole).toInt()) { - item = item->child(index.m_region); - ASSERT_EQUAL( item->data(KColumnIndexCountry, Qt::UserRole).toInt(), index.m_region, () ); + item = grItem; + break; } } } + if (item && index.m_country >= 0) + { + item = MatchedItem(*item, index.m_country); + if (item && index.m_region >= 0) + item = MatchedItem(*item, index.m_region); + } return item; }