QTfrontend/model/playerslistmodel.cpp
changeset 9725 68b5d87cfdb0
parent 9503 8f9b04138456
child 9727 e89ed65f62da
--- a/QTfrontend/model/playerslistmodel.cpp	Sat Nov 30 11:14:32 2013 +0100
+++ b/QTfrontend/model/playerslistmodel.cpp	Sat Nov 30 13:42:14 2013 +0100
@@ -146,6 +146,25 @@
 
 void PlayersListModel::setFlag(const QString &nickname, StateFlag flagType, bool isSet)
 {
+    if(flagType == Friend)
+    {
+        if(isSet)
+            m_friendsSet.insert(nickname.toLower());
+        else
+            m_friendsSet.remove(nickname.toLower());
+
+        saveSet(m_friendsSet, "friends");
+    }
+    else if(flagType == Ignore)
+    {
+        if(isSet)
+            m_ignoredSet.insert(nickname.toLower());
+        else
+            m_ignoredSet.remove(nickname.toLower());
+
+        saveSet(m_ignoredSet, "ignore");
+    }
+
     QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
 
     if(mil.size())
@@ -156,26 +175,6 @@
                 || flagType == Ignore || flagType == RoomAdmin)
             updateSortData(mil[0]);
 
-        if(flagType == Friend)
-        {
-            if(isSet)
-                m_friendsSet.insert(nickname.toLower());
-            else
-                m_friendsSet.remove(nickname.toLower());
-
-            saveSet(m_friendsSet, "friends");
-        }
-
-        if(flagType == Ignore)
-        {
-            if(isSet)
-                m_ignoredSet.insert(nickname.toLower());
-            else
-                m_ignoredSet.remove(nickname.toLower());
-
-            saveSet(m_ignoredSet, "ignore");
-        }
-
         updateIcon(mil[0]);
     }
 }
@@ -187,6 +186,10 @@
 
     if(mil.size())
         return mil[0].data(flagType).toBool();
+    else if(flagType == Friend)
+        return isFriend(nickname);
+    else if(flagType == Ignore)
+        return isIgnored(nickname);
     else
         return false;
 }
@@ -344,11 +347,20 @@
         checkFriendIgnore(index(i));
 }
 
+bool PlayersListModel::isFriend(const QString & nickname)
+{
+    return m_friendsSet.contains(nickname.toLower());
+}
+
+bool PlayersListModel::isIgnored(const QString & nickname)
+{
+    return m_ignoredSet.contains(nickname.toLower());
+}
 
 void PlayersListModel::checkFriendIgnore(const QModelIndex &mi)
 {
-    setData(mi, m_friendsSet.contains(mi.data().toString().toLower()), Friend);
-    setData(mi, m_ignoredSet.contains(mi.data().toString().toLower()), Ignore);
+    setData(mi, isFriend(mi.data().toString()), Friend);
+    setData(mi, isIgnored(mi.data().toString()), Ignore);
 
     updateIcon(mi);
     updateSortData(mi);