hgcacheproxymodel/src/hgdataprovidermodel.cpp
changeset 17 a10844a9914d
parent 6 1cdcc61142d2
child 20 a60f8b6b1d32
--- a/hgcacheproxymodel/src/hgdataprovidermodel.cpp	Fri Sep 03 10:22:04 2010 +0300
+++ b/hgcacheproxymodel/src/hgdataprovidermodel.cpp	Fri Sep 17 15:55:58 2010 +0300
@@ -13,7 +13,7 @@
 *
 * Description:
 *
-*  Version     : %version: 15 %
+*  Version     : %version: 18 %
 */
 #include <e32debug.h>
 #include <QVariant>
@@ -43,9 +43,9 @@
     TX_ENTRY    
     clearCache();
     delete mCache;
-    qDeleteAll( mFreePixmaps.begin(), mFreePixmaps.end() );
+    qDeleteAll(mFreePixmaps.begin(), mFreePixmaps.end());
     mFreePixmaps.clear();
-    qDeleteAll( mUsedPixmaps.begin(), mUsedPixmaps.end() );
+    qDeleteAll(mUsedPixmaps.begin(), mUsedPixmaps.end());
     mUsedPixmaps.clear();
     TX_EXIT
 }
@@ -57,21 +57,25 @@
     int min = count();
     int max = 0;
     
-    for ( int idx = 0; idx < list.count(); idx++){
+    bool correct = false;
+    
+    for (int idx = 0; idx < list.count(); idx++) {
         i = list[idx];
-        if ( i >=0 && i<count()){
-            if ( i < min){
+        if (i >=0 && i<count()) {
+            if (i < min) {
                 min = i;
-            } if ( i > max){
+            }
+            if (i > max) {
                 max = i;
             }
             resetIcon(i);
+            correct = true;
         }
     }
     
     doReleaseData(list, silent);
     
-    if (min<max){ //min<max is true if at least one item is in range <0,count())
+    if (correct) {
         emitDataChanged(min, max, silent);
     }
     TX_EXIT
@@ -95,10 +99,10 @@
                                      const QModelIndex &parent) const
 {   
     Q_UNUSED(parent);
-    if (  row >= rowCount() ){
+    if (row >= rowCount()) {
         row = -1;
     }
-    if (  column >= columnCount() ){
+    if (column >= columnCount()) {
         column = -1;
     }
     
@@ -131,13 +135,13 @@
 QVariant HgDataProviderModel::data(int idx, int role) const
 {
     QVariant res;
-    if ( containsRole(idx, role)){
+    if (containsRole(idx, role)) {
         res = mCache->at(idx)->value(role);
-    } else if (isIndexValid(idx)){
-        if (role == Qt::DecorationRole ){
+    } else if (isIndexValid(idx)) {
+        if (role == Qt::DecorationRole) {
             res = defaultIcon();
         } else {
-            res = getData(idx,role);
+            res = getData(idx, role);
         }
         
     }
@@ -147,7 +151,7 @@
 QMap<int, QVariant> HgDataProviderModel::itemData(const QModelIndex &index) const
 {
     QMap<int, QVariant> res;
-    if ( index.row()>=0 && index.row()<count() ){
+    if (index.row()>=0 && index.row()<count()) {
         res = QMap<int, QVariant>(*mCache->at(index.row()));
     }   
     return res;
@@ -155,11 +159,11 @@
 
 void HgDataProviderModel::clearCache()
 {
-    for ( int i=0; i<count(); i++){
+    for (int i=0; i<count(); i++) {
         releasePixmap(i);
     }
     
-    qDeleteAll( mCache->begin(), mCache->end() );
+    qDeleteAll(mCache->begin(), mCache->end());
     mCache->clear();
 }
 
@@ -172,11 +176,11 @@
 {
     bool change(false);
     if (list && list->count() && isIndexValid(pos)) {
-        while(list->count()>0){
+        while(list->count()>0) {
             QPair< QVariant, int > pair = list->takeFirst();
             change = update(pos, pair.first, pair.second, true)|change;
         }
-        if ( !silent && change ){
+        if (!silent && change) {
             emitDataChanged(pos, pos, false);
         }
     }
@@ -187,14 +191,14 @@
 {
     bool change(false);
     
-    if ( isIndexValid(pos)){
+    if (isIndexValid(pos)) {
         mDataLock.lock();
         mCache->at(pos)->insert(role, obj); //this will remove old one if needed
         mDataLock.unlock();        
         change = true;
     }
     
-    if ( !silent && change ){
+    if (!silent && change) {
         emitDataChanged(pos, pos, false);
     }
     return change;
@@ -203,19 +207,19 @@
 bool HgDataProviderModel::updateIcon(int pos, QVariant obj, bool silent)
 {
     bool change(false);
-    if ( obj.isValid() && !obj.isNull() && isIndexValid(pos) ){
+    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){
+        if (!silent) {
             TX_LOG_ARGS(QString("pos:%1").arg( pos ) );
-            if ( mObserver){
+            if (mObserver) {
                 mObserver->dataUpdated(pos,pos);
             } else { //if no observer, let's emit signal
                 QModelIndex topLeft = index(pos, 0);
                 QModelIndex bottomRight = index(pos, 0);
-                emit dataChanged(topLeft,bottomRight);
+                emit dataChanged(topLeft, bottomRight);
             }
         }
     }
@@ -224,7 +228,7 @@
 
 void HgDataProviderModel::resetIcon(int pos)
 {
-    if ( containsRole(pos, Qt::DecorationRole)){
+    if (containsRole(pos, Qt::DecorationRole)) {
         mCache->at(pos)->remove(Qt::DecorationRole);
     }
 }
@@ -254,25 +258,25 @@
 void HgDataProviderModel::clearItem(int pos, bool silent)
 {
     bool change = false;
-    if ( isIndexValid(pos)){
+    if (isIndexValid(pos)) {
         mDataLock.lock();    
         mCache->at(pos)->clear();
         mDataLock.unlock();
         change = true;
     }
     
-    if ( change && !silent){
+    if (change && !silent) {
         emit dataChanged( index(pos, 0), index(pos, 0) );
     }
 }
 
 void HgDataProviderModel::doInsertItem(int pos, QList< QPair< QVariant, int > >* list, bool silent)
 {
-    if (pos >mCache->count() || pos <0){
+    if (pos >mCache->count() || pos <0) {
         return;
     }
     
-    if ( !silent){
+    if (!silent) {
         beginInsertRows(QModelIndex(), pos, pos);
     }
     
@@ -280,11 +284,11 @@
     mCache->insert(pos, new QMap<int, QVariant>());
     mDataLock.unlock();
     
-    if (list && list->count()){
+    if (list && list->count()) {
         update(pos, list, true);
     }
     
-    if ( !silent){
+    if (!silent) {
         endInsertRows();
     } 
 }
@@ -297,27 +301,27 @@
 
 void HgDataProviderModel::removeItems(int pos, int size, bool silent)
 {
-    if (pos >=mCache->count()){
+    if (pos >=mCache->count()) {
         return;
-    } else if (pos <0){
+    } else if (pos <0) {
         size = size + pos; //pos <0
         pos = 0;
     }
     
-    if (size >mCache->count()){
+    if (size >mCache->count()) {
         size = mCache->count();
     }
-    if (size <=0){
+    if (size <=0) {
         return;
     }
-    if (!silent){
+    if (!silent) {
         beginRemoveRows(QModelIndex(),pos, pos+size-1);
     } else {
         qWarning("Removing items without notifying might be danger.");
     }
     
     mDataLock.lock();
-    for (int i=0; i<size && pos<mCache->count(); i++){
+    for (int i=0; i<size && pos<mCache->count(); i++) {
         mCache->removeAt(pos);
     }
     mDataLock.unlock();
@@ -345,11 +349,11 @@
 
 void HgDataProviderModel::emitDataChanged(int from, int to, bool silent)
 {
-    if ( !silent ){
+    if (!silent) {
 //        TX_LOG
         QModelIndex topLeft = index(from, 0);
         QModelIndex bottomRight = index(to, 0);
-        emit dataChanged(topLeft,bottomRight);
+        emit dataChanged(topLeft, bottomRight);
     }
 }
 
@@ -359,14 +363,14 @@
     int currentSize = mFreePixmaps.count() + mUsedPixmaps.count();
     int diff = currentSize - newSize - KQPixmapCacheEmergencyBuffer;
     mUnallocatedPixmaps = 0;
-    while (diff != 0){
-        if (diff < 0){
+    while (diff != 0) {
+        if (diff < 0) {
             mUnallocatedPixmaps++;
             diff++;
-        }else{
-            if (mUnallocatedPixmaps>0){
+        } else {
+            if (mUnallocatedPixmaps>0) {
                 mUnallocatedPixmaps--;
-            } else if (mFreePixmaps.count()){
+            } else if (mFreePixmaps.count()) {
                 mFreePixmaps.removeLast();
             } //else will be deleted with releasePixmap;
             diff--;
@@ -381,7 +385,7 @@
     mQPixmapsLock.lock();
     if (mUsedPixmaps.contains(idx)) {
         QPixmap* pix = mUsedPixmaps.take(idx);
-        if ( ( mFreePixmaps.count() + mUsedPixmaps.count() + mUnallocatedPixmaps ) >= ( mCacheSize + KQPixmapCacheEmergencyBuffer ) ) {
+        if ((mFreePixmaps.count() + mUsedPixmaps.count() + mUnallocatedPixmaps ) >= ( mCacheSize + KQPixmapCacheEmergencyBuffer)) {
             delete pix; //we have too many pixmaps
         } else {
             mFreePixmaps.append(pix);
@@ -397,8 +401,8 @@
     TX_ENTRY
     QVariant res;
 	QPixmap* pix = getPixmap(index);
-	if (pix){
-		if ( pix->pixmapData() ) {
+	if (pix) {
+		if (pix->pixmapData()) {
 			pix->pixmapData()->fromImage(aPixmap.toImage(), Qt::AutoColor );  
 		} else {
 			*pix = aPixmap;
@@ -406,7 +410,7 @@
 		mQPixmapsLock.lock();
 		mUsedPixmaps.insert(index, pix);
 		mQPixmapsLock.unlock();
-		switch (mIconMode){
+		switch (mIconMode) {
             case HgDataProviderIconHbIcon : 
                 res = HbIcon(QIcon(*pix));  
                 break;
@@ -424,7 +428,7 @@
 		}
 	}
 	
-	if (res.isNull()){
+	if (res.isNull()) {
 	    TX_EXIT_ARGS( QString("No pixmap avilable"));
 	}
 	
@@ -436,12 +440,12 @@
 //    TX_ENTRY
     QPixmap* res = NULL;
     mQPixmapsLock.lock();
-    if ( mUsedPixmaps.contains(idx)){
+    if (mUsedPixmaps.contains(idx)) {
         res = mUsedPixmaps.take(idx);//let's just replace pixmapdata for that pixmap
     } else {
-        if (!mFreePixmaps.isEmpty()){
+        if (!mFreePixmaps.isEmpty()) {
             res = mFreePixmaps.takeFirst();
-        }else if (mUnallocatedPixmaps){
+        }else if (mUnallocatedPixmaps) {
             mUnallocatedPixmaps--;
             res = new QPixmap();
         } else {