qmlfrontend/players_model.cpp
changeset 16039 a73b9770467a
parent 15919 d52f5d8e75e6
equal deleted inserted replaced
16035:1f9f971adec4 16039:a73b9770467a
    21 }
    21 }
    22 
    22 
    23 QVariant PlayersListModel::data(const QModelIndex &index, int role) const {
    23 QVariant PlayersListModel::data(const QModelIndex &index, int role) const {
    24   if (!index.isValid() || index.row() < 0 || index.row() >= rowCount() ||
    24   if (!index.isValid() || index.row() < 0 || index.row() >= rowCount() ||
    25       index.column() != 0)
    25       index.column() != 0)
    26     return QVariant(QVariant::Invalid);
    26     return QVariant{};
    27 
    27 
    28   return m_data.at(index.row()).value(role);
    28   return m_data.at(index.row()).value(role);
    29 }
    29 }
    30 
    30 
    31 bool PlayersListModel::setData(const QModelIndex &index, const QVariant &value,
    31 bool PlayersListModel::setData(const QModelIndex &index, const QVariant &value,
   268 
   268 
   269   return iconsCache;
   269   return iconsCache;
   270 }
   270 }
   271 
   271 
   272 void PlayersListModel::updateSortData(const QModelIndex &index) {
   272 void PlayersListModel::updateSortData(const QModelIndex &index) {
   273   QString result =
   273   const auto result =
   274       QString("%1%2%3%4%5%6")
   274       QStringLiteral("%1%2%3%4%5%6")
   275           // room admins go first, then server admins, then friends
   275           // room admins go first, then server admins, then friends
   276           .arg(1 - index.data(RoomAdmin).toInt())
   276           .arg(1 - index.data(RoomAdmin).toInt())
   277           .arg(1 - index.data(ServerAdmin).toInt())
   277           .arg(1 - index.data(ServerAdmin).toInt())
   278           .arg(1 - index.data(Friend).toInt())
   278           .arg(1 - index.data(Friend).toInt())
   279           // ignored at bottom
   279           // ignored at bottom
   318 
   318 
   319   QFile txt(fileName);
   319   QFile txt(fileName);
   320   if (!txt.open(QIODevice::ReadOnly)) return;
   320   if (!txt.open(QIODevice::ReadOnly)) return;
   321 
   321 
   322   QTextStream stream(&txt);
   322   QTextStream stream(&txt);
   323   stream.setCodec("UTF-8");
       
   324 
   323 
   325   while (!stream.atEnd()) {
   324   while (!stream.atEnd()) {
   326     QString str = stream.readLine();
   325     QString str = stream.readLine();
   327     if (str.startsWith(";") || str.isEmpty()) continue;
   326     if (str.startsWith(';') || str.isEmpty()) {
       
   327       continue;
       
   328     }
   328 
   329 
   329     set.insert(str.trimmed());
   330     set.insert(str.trimmed());
   330   }
   331   }
   331 
   332 
   332   txt.close();
   333   txt.close();
   349   }
   350   }
   350 
   351 
   351   if (!txt.open(QIODevice::WriteOnly | QIODevice::Truncate)) return;
   352   if (!txt.open(QIODevice::WriteOnly | QIODevice::Truncate)) return;
   352 
   353 
   353   QTextStream stream(&txt);
   354   QTextStream stream(&txt);
   354   stream.setCodec("UTF-8");
       
   355 
   355 
   356   stream << "; this list is used by Hedgewars - do not edit it unless you know "
   356   stream << "; this list is used by Hedgewars - do not edit it unless you know "
   357             "what you're doing!"
   357             "what you're doing!"
   358          << Qt::endl;
   358          << Qt::endl;
   359 
   359