| 232 | } |
| 233 | |
| 234 | bool AliasModel::setData(const QModelIndex &index, const QVariant &value, int) |
| 235 | { |
| 236 | if(!index.isValid() || anime.isEmpty()) return false; |
| 237 | QString alias = value.toString(); |
| 238 | auto remove = [=](int row){ |
| 239 | beginRemoveRows(QModelIndex(), row, row); |
| 240 | aliasList.removeAt(row); |
| 241 | endRemoveRows(); |
| 242 | }; |
| 243 | if(alias.isEmpty()) |
| 244 | { |
| 245 | remove(index.row()); |
| 246 | return false; |
| 247 | } |
| 248 | if(alias == anime) |
| 249 | { |
| 250 | remove(index.row()); |
| 251 | emit addFailed(); |
| 252 | return false; |
| 253 | } |
| 254 | if(AnimeWorker::instance()->hasAnime(alias)) |
| 255 | { |
| 256 | remove(index.row()); |
| 257 | emit addFailed(); |
| 258 | return false; |
| 259 | } |
| 260 | if(AnimeWorker::instance()->addAlias(anime, alias)) |
| 261 | { |
| 262 | aliasList[index.row()] = alias; |
| 263 | return true; |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | remove(index.row()); |
| 268 | emit addFailed(); |
| 269 | return false; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | StaffModel::StaffModel(const Anime *anime, QObject *parent) : QAbstractItemModel(parent) |
| 274 | { |