QTfrontend/model/roomslistmodel.cpp
branch0.9.21
changeset 10739 d886f319e7b3
parent 10511 c33b2f001730
child 10741 7fababf10b60
equal deleted inserted replaced
10737:408803ca951a 10739:d886f319e7b3
   106 
   106 
   107     // decorate room name based on room state
   107     // decorate room name based on room state
   108     if (role == Qt::DecorationRole)
   108     if (role == Qt::DecorationRole)
   109     {
   109     {
   110         const QIcon roomBusyIcon(":/res/iconDamage.png");
   110         const QIcon roomBusyIcon(":/res/iconDamage.png");
       
   111         const QIcon roomBusyIconGreen(":/res/iconDamageLockG.png");
       
   112         const QIcon roomBusyIconRed(":/res/iconDamageLockR.png");
   111         const QIcon roomWaitingIcon(":/res/iconTime.png");
   113         const QIcon roomWaitingIcon(":/res/iconTime.png");
   112 
   114         const QIcon roomWaitingIconGreen(":/res/iconTimeLockG.png");
   113         if (m_data.at(row).at(0).isEmpty())
   115         const QIcon roomWaitingIconRed(":/res/iconTimeLockR.png");
   114             return QVariant(roomWaitingIcon);
   116 
       
   117         QString flags = m_data.at(row).at(0);
       
   118 
       
   119         if (flags.contains("g"))
       
   120         {
       
   121             if (flags.contains("j"))
       
   122                 return QVariant(roomWaitingIconRed);
       
   123             else if (flags.contains("p"))
       
   124                 return QVariant(roomWaitingIconGreen);
       
   125             else
       
   126                 return QVariant(roomWaitingIcon);
       
   127         }
   115         else
   128         else
   116             return QVariant(roomBusyIcon);
   129         {
       
   130             if (flags.contains("j"))
       
   131                 return QVariant(roomBusyIconRed);
       
   132             else if (flags.contains("p"))
       
   133                 return QVariant(roomBusyIconGreen);
       
   134             else
       
   135                 return QVariant(roomBusyIcon);
       
   136         }
   117     }
   137     }
   118 
   138 
   119     QString content = m_data.at(row).at(column);
   139     QString content = m_data.at(row).at(column);
   120 
   140 
   121     if (role == Qt::DisplayRole)
   141     if (role == Qt::DisplayRole)
   188         for (int t = 0; t < c_nColumns; t++)
   208         for (int t = 0; t < c_nColumns; t++)
   189         {
   209         {
   190             l.append(rooms[i + t]);
   210             l.append(rooms[i + t]);
   191         }
   211         }
   192 
   212 
   193         m_data.append(roomInfo2RoomRecord(l));
   213         m_data.append(l);
   194     }
   214     }
   195 
   215 
   196     endResetModel();
   216     endResetModel();
   197 }
   217 }
   198 
   218 
   199 
   219 
   200 void RoomsListModel::addRoom(const QStringList & info)
   220 void RoomsListModel::addRoom(const QStringList & info)
   201 {
   221 {
   202     beginInsertRows(QModelIndex(), 0, 0);
   222     beginInsertRows(QModelIndex(), 0, 0);
   203 
   223 
   204     m_data.prepend(roomInfo2RoomRecord(info));
   224     m_data.prepend(info);
   205 
   225 
   206     endInsertRows();
   226     endInsertRows();
   207 }
   227 }
   208 
   228 
   209 
   229 
   248     int i = rowOfRoom(name);
   268     int i = rowOfRoom(name);
   249 
   269 
   250     if (i < 0)
   270     if (i < 0)
   251         return;
   271         return;
   252 
   272 
   253     m_data[i] = roomInfo2RoomRecord(info);
   273     m_data[i] = info;
   254 
   274 
   255     emit dataChanged(index(i, 0), index(i, columnCount(QModelIndex()) - 1));
   275     emit dataChanged(index(i, 0), index(i, columnCount(QModelIndex()) - 1));
   256 }
   276 }
   257 
       
   258 
       
   259 QStringList RoomsListModel::roomInfo2RoomRecord(const QStringList & info)
       
   260 {
       
   261     QStringList result;
       
   262 
       
   263     result = info;
       
   264 
       
   265     QString flags = info[StateColumn];
       
   266     // for matters of less memory usage and quicker access store
       
   267     // the boolean string as either "t" or empty
       
   268     if (flags.contains('g'))
       
   269         result[StateColumn] = "t";
       
   270     else
       
   271         result[StateColumn] = QString();
       
   272 
       
   273     return result;
       
   274 }