--- a/src/hbwidgets/itemviews/hbabstractitemcontainer_p.cpp Thu May 27 13:10:59 2010 +0300
+++ b/src/hbwidgets/itemviews/hbabstractitemcontainer_p.cpp Fri Jun 11 13:58:22 2010 +0300
@@ -362,35 +362,29 @@
HbAbstractViewItem* HbAbstractItemContainerPrivate::item(const QModelIndex &index) const
{
int itemCount = mItems.count();
- for (int i = 0; i < itemCount; ++i) {
- // This could use binary search as model indexes are in sorted.
- if (mItems.at(i)->modelIndex() == index) {
- return mItems.at(i);
- }
- }
-
- // TODO: The lower (commented out) part of the code is an optimized version of the above.
- // However, there are problems with TreeView's deep models concerning the optimized version.
- // The optimized version should be fixed and taken into use later on.
+ if (index.isValid()) {
+ if (itemCount > 0) {
+ HbModelIterator *iterator = mItemView->modelIterator();
+ int positionFirstIndex = iterator->indexPosition(mItems.first()->modelIndex());
- /*
- int itemCount = mItems.count();
- if (itemCount > 0) {
- if (index.isValid()) {
- int itemIndex = mItemView->indexPosition(index) - mItemView->indexPosition(mItems.first()->modelIndex());
- return mItems.value(itemIndex);
- } else {
- for (int i = 0; i < itemCount; ++i) {
- // This could use binary search as model indexes are in sorted.
- HbAbstractViewItem *item = mItems.at(i);
- if (item->modelIndex() == index) {
+ // when new items are inserted, they will appear in the end of container before a model index is assigned to them
+ if (positionFirstIndex >= 0) {
+ int positionIndex = iterator->indexPosition(index);
+ HbAbstractViewItem *item = mItems.value(positionIndex - positionFirstIndex);
+ if ( item
+ && item->modelIndex() == index) {
return item;
}
}
}
+ } else {
+ // searching items e.g. removed from model
+ for (int i = 0; i < itemCount; ++i) {
+ if (!mItems.at(i)->modelIndex().isValid()) {
+ return mItems.at(i);
+ }
+ }
}
- */
-
return 0;
}
@@ -1184,7 +1178,7 @@
newSize.setWidth(d->mItemView->size().width());
}
}
-
+
resize(newSize);
}