diff -r c863538fcbb6 -r 4fa04caf0f43 hgcacheproxymodel/src/hgdataprovidermodel.cpp --- a/hgcacheproxymodel/src/hgdataprovidermodel.cpp Thu May 27 13:59:05 2010 +0300 +++ b/hgcacheproxymodel/src/hgdataprovidermodel.cpp Fri Jun 11 14:43:11 2010 +0300 @@ -13,11 +13,11 @@ * * Description: * -* Version : %version: 9 % +* Version : %version: 12 % */ #include #include -#include +#include #include #include #include @@ -132,8 +132,13 @@ QVariant res; if ( containsRole(idx, role)){ res = mCache->at(idx)->value(role); - } else if (role == Qt::DecorationRole ){ - res = defaultIcon(); + } else if (isIndexValid(idx)){ + if (role == Qt::DecorationRole ){ + res = defaultIcon(); + } else { + res = getData(idx,role); + } + } return res; } @@ -165,7 +170,7 @@ bool HgDataProviderModel::update(int pos, QList< QPair< QVariant, int > >* list, bool silent) { bool change(false); - if (list && list->count() && pos >=0 && posat(pos)) { + if (list && list->count() && isIndexValid(pos)) { while(list->count()>0){ QPair< QVariant, int > pair = list->takeFirst(); change = update(pos, pair.first, pair.second, true)|change; @@ -182,7 +187,9 @@ bool change(false); if ( isIndexValid(pos)){ + mDataLock.lock(); mCache->at(pos)->insert(role, obj); //this will remove old one if needed + mDataLock.unlock(); change = true; } @@ -196,7 +203,9 @@ { bool change(false); if ( obj.isValid() && !obj.isNull() && isIndexValid(pos) ){ + mDataLock.lock(); mCache->at(pos)->insert(Qt::DecorationRole, obj); //will remove old if needed + mDataLock.unlock(); change = true; if (!silent){ TX_LOG_ARGS(QString("pos:%1").arg( pos ) ); @@ -251,7 +260,10 @@ beginInsertRows(QModelIndex(), pos, pos); } + mDataLock.lock(); mCache->insert(pos, new QMap()); + mDataLock.unlock(); + if (list && list->count()){ update(pos, list, true); } @@ -283,9 +295,11 @@ } beginRemoveRows(QModelIndex(),pos, pos+size-1); + mDataLock.lock(); for (int i=0; icount(); i++){ mCache->removeAt(pos); } + mDataLock.unlock(); endRemoveRows(); } @@ -308,7 +322,7 @@ void HgDataProviderModel::resizeQPixmapPool(int newSize) { -// mQPixmapsLock.lock(); + mQPixmapsLock.lock(); int currentSize = mFreePixmaps.count() + mUsedPixmaps.count(); int diff = currentSize - newSize - KQPixmapCacheEmergencyBuffer; mUnallocatedPixmaps = 0; @@ -325,13 +339,13 @@ diff--; } } -// mQPixmapsLock.unlock(); + mQPixmapsLock.unlock(); mCacheSize = newSize; } void HgDataProviderModel::releasePixmap(int idx) { -// mQPixmapsLock.lock(); + mQPixmapsLock.lock(); if (mUsedPixmaps.contains(idx)) { QPixmap* pix = mUsedPixmaps.take(idx); if ( ( mFreePixmaps.count() + mUsedPixmaps.count() + mUnallocatedPixmaps ) > ( mCacheSize + KQPixmapCacheEmergencyBuffer ) ) { @@ -342,7 +356,7 @@ } else { // TX_LOG_ARGS( QString("can't release pixmap for idx=%0").arg(idx)); } -// mQPixmapsLock.unlock(); + mQPixmapsLock.unlock(); } QVariant HgDataProviderModel::createIcon(int index, QPixmap aPixmap) @@ -355,9 +369,9 @@ } else { *pix = aPixmap; } -// mQPixmapsLock.lock(); + mQPixmapsLock.lock(); mUsedPixmaps.insert(index, pix); -// mQPixmapsLock.unlock(); + mQPixmapsLock.unlock(); return HbIcon(QIcon(*pix)); } TX_EXIT_ARGS( QString("No pixmap avilable")); @@ -368,7 +382,7 @@ { // TX_ENTRY QPixmap* res = NULL; -// mQPixmapsLock.lock(); + mQPixmapsLock.lock(); if ( mUsedPixmaps.contains(idx)){ res = mUsedPixmaps.take(idx);//let's just replace pixmapdata for that pixmap } else { @@ -381,7 +395,7 @@ TX_LOG_ARGS(QString("no free pixmaps")); } } -// mQPixmapsLock.unlock(); + mQPixmapsLock.unlock(); // TX_EXIT return res; }