QTfrontend/model/playerslistmodel.cpp
changeset 7728 664738870325
parent 7727 bd252cacabe8
child 7731 262228c64f15
equal deleted inserted replaced
7727:bd252cacabe8 7728:664738870325
    83 
    83 
    84 void PlayersListModel::addPlayer(const QString & nickname)
    84 void PlayersListModel::addPlayer(const QString & nickname)
    85 {
    85 {
    86     insertRow(rowCount());
    86     insertRow(rowCount());
    87 
    87 
    88     setData(index(rowCount() - 1), nickname);
    88     QModelIndex mi = index(rowCount() - 1);
    89 
    89     setData(mi, nickname);
    90     updateIcon(index(rowCount() - 1));
    90 
       
    91     updateSortData(mi);
       
    92     updateIcon(mi);
    91 }
    93 }
    92 
    94 
    93 
    95 
    94 void PlayersListModel::removePlayer(const QString & nickname)
    96 void PlayersListModel::removePlayer(const QString & nickname)
    95 {
    97 {
   105     QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
   107     QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname);
   106 
   108 
   107     if(mil.size())
   109     if(mil.size())
   108     {
   110     {
   109         setData(mil[0], isSet, flagType);
   111         setData(mil[0], isSet, flagType);
       
   112 
       
   113         if(flagType == Friend || flagType == ServerAdmin
       
   114                 || flagType == Ignore || flagType == RoomAdmin)
       
   115             updateSortData(mil[0]);
       
   116 
   110         updateIcon(mil[0]);
   117         updateIcon(mil[0]);
   111     }
   118     }
   112 }
   119 }
   113 
   120 
   114 
   121 
   186 {
   193 {
   187     static QHash<quint32, QIcon> iconsCache;
   194     static QHash<quint32, QIcon> iconsCache;
   188 
   195 
   189     return iconsCache;
   196     return iconsCache;
   190 }
   197 }
       
   198 
       
   199 void PlayersListModel::updateSortData(const QModelIndex & index)
       
   200 {
       
   201     QString result = QString("%1%2%3%4%5")
       
   202             .arg(1 - index.data(RoomAdmin).toInt())
       
   203             .arg(1 - index.data(ServerAdmin).toInt())
       
   204             .arg(1 - index.data(Friend).toInt())
       
   205             .arg(index.data(Ignore).toInt())
       
   206             .arg(index.data(Qt::DisplayRole).toString().toLower())
       
   207             ;
       
   208 
       
   209     setData(index, result, SortRole);
       
   210 }