small cleanup etc
authorsheepluva
Sat, 30 Nov 2013 14:33:23 +0100
changeset 9727 e89ed65f62da
parent 9726 dfdde45181ec
child 9728 320f89e0b28c
small cleanup etc
QTfrontend/model/playerslistmodel.cpp
QTfrontend/model/playerslistmodel.h
--- a/QTfrontend/model/playerslistmodel.cpp	Sat Nov 30 14:05:22 2013 +0100
+++ b/QTfrontend/model/playerslistmodel.cpp	Sat Nov 30 14:33:23 2013 +0100
@@ -84,6 +84,15 @@
     return true;
 }
 
+QModelIndex PlayersListModel::nicknameIndex(const QString & nickname)
+{
+    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
+
+    if(mil.size() > 0)
+        return mil[0];
+    else
+        return QModelIndex();
+}
 
 void PlayersListModel::addPlayer(const QString & nickname, bool notify)
 {
@@ -105,22 +114,22 @@
     else
         emit nickRemovedLobby(nickname, msg);
 
-    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
+    QModelIndex mi = nicknameIndex(nickname);
 
-    if(mil.size())
-        removeRow(mil[0].row());
+    if(mi.isValid())
+        removeRow(mi.row());
 }
 
 
 void PlayersListModel::playerJoinedRoom(const QString & nickname, bool notify)
 {
-    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
+    QModelIndex mi = nicknameIndex(nickname);
 
-    if(mil.size())
+    if(mi.isValid())
     {
-        setData(mil[0], true, RoomFilterRole);
-        updateIcon(mil[0]);
-        updateSortData(mil[0]);
+        setData(mi, true, RoomFilterRole);
+        updateIcon(mi);
+        updateSortData(mi);
     }
 
     emit nickAdded(nickname, notify);
@@ -131,15 +140,15 @@
 {
     emit nickRemoved(nickname);
 
-    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
+    QModelIndex mi = nicknameIndex(nickname);
 
-    if(mil.size())
+    if(mi.isValid())
     {
-        setData(mil[0], false, RoomFilterRole);
-        setData(mil[0], false, RoomAdmin);
-        setData(mil[0], false, Ready);
-        setData(mil[0], false, InGame);
-        updateIcon(mil[0]);
+        setData(mi, false, RoomFilterRole);
+        setData(mi, false, RoomAdmin);
+        setData(mi, false, Ready);
+        setData(mi, false, InGame);
+        updateIcon(mi);
     }
 }
 
@@ -165,27 +174,27 @@
         saveSet(m_ignoredSet, "ignore");
     }
 
-    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
+    QModelIndex mi = nicknameIndex(nickname);
 
-    if(mil.size())
+    if(mi.isValid())
     {
-        setData(mil[0], isSet, flagType);
+        setData(mi, isSet, flagType);
 
         if(flagType == Friend || flagType == ServerAdmin
                 || flagType == Ignore || flagType == RoomAdmin)
-            updateSortData(mil[0]);
+            updateSortData(mi);
 
-        updateIcon(mil[0]);
+        updateIcon(mi);
     }
 }
 
 
 bool PlayersListModel::isFlagSet(const QString & nickname, StateFlag flagType)
 {
-    QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly);
+    QModelIndex mi = nicknameIndex(nickname);
 
-    if(mil.size())
-        return mil[0].data(flagType).toBool();
+    if(mi.isValid())
+        return mi.data(flagType).toBool();
     else if(flagType == Friend)
         return isFriend(nickname);
     else if(flagType == Ignore)
--- a/QTfrontend/model/playerslistmodel.h	Sat Nov 30 14:05:22 2013 +0100
+++ b/QTfrontend/model/playerslistmodel.h	Sat Nov 30 14:33:23 2013 +0100
@@ -43,6 +43,8 @@
     bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
 
+    QModelIndex nicknameIndex(const QString & nickname);
+
 public slots:
     void addPlayer(const QString & nickname, bool notify);
     void removePlayer(const QString & nickname, const QString & msg = QString());