bool BuildingModel::setData(const QModelIndex &index, const QVariant &value, int role) { qDebug() << "Setting data"; if (!index.isValid() || index.row() < 0 || index.row() >= rowCount()) { qDebug() << "Index not found"; return false; } auto room = _rooms.at(index.row()); switch (role) { case NameRole: room->setName(value.toString()); break; case LightStateRole: qDebug() << "Setting light state " << value; room->setLightState(value==1 ? LightState::On : LightState::Off); break; case RoomStateRole: qDebug() << "Setting room state" << value; room->setRoomState(value==0 ? RoomState::Ok : RoomState::Error); break; default: return false; } emit dataChanged(index, index); return true; }
void Dbconnect::updateRoomState(QString build_no,QString room_no) { QSqlTableModel* model_guest = getTbModel("guest"); QString gin_sql_where = QString("room_no='%1-%2' and edate is null and is_yu=0").arg(build_no).arg(room_no); model_guest->setFilter(gin_sql_where); model_guest->select(); if(model_guest->rowCount() > 0){ setRoomState(build_no,room_no,Db::ROOM_STATE_GUESTIN); return; } QString gyu_sql_where = QString("room_no='%1-%2' and is_yu='1'").arg(build_no).arg(room_no); model_guest->setFilter(gyu_sql_where); model_guest->select(); if(model_guest->rowCount() > 0){ setRoomState(build_no,room_no,Db::ROOM_STATE_GUESTYU); return; } setRoomState(build_no,room_no,Db::ROOM_STATE_EMPTY); }