| 486 | } |
| 487 | |
| 488 | void ReadingListModel::rename(const QModelIndex &mi, const QString &name) |
| 489 | { |
| 490 | if (!isEditable(mi)) |
| 491 | return; |
| 492 | QString connectionName = ""; |
| 493 | { |
| 494 | QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); |
| 495 | |
| 496 | auto item = static_cast<ListItem *>(mi.internalPointer()); |
| 497 | |
| 498 | if (typeid(*item) == typeid(ReadingListItem)) { |
| 499 | auto rli = static_cast<ReadingListItem *>(item); |
| 500 | rli->setName(name); |
| 501 | DBHelper::renameList(item->getId(), name, db); |
| 502 | |
| 503 | if (rli->parent->getId() != 0) { |
| 504 | // TODO |
| 505 | // move row depending on the name |
| 506 | } else |
| 507 | emit dataChanged(index(mi.row(), 0), index(mi.row(), 0)); |
| 508 | } else if (typeid(*item) == typeid(LabelItem)) { |
| 509 | auto li = static_cast<LabelItem *>(item); |
| 510 | li->setName(name); |
| 511 | DBHelper::renameLabel(item->getId(), name, db); |
| 512 | emit dataChanged(index(mi.row(), 0), index(mi.row(), 0)); |
| 513 | } |
| 514 | connectionName = db.connectionName(); |
| 515 | } |
| 516 | QSqlDatabase::removeDatabase(connectionName); |
| 517 | } |
| 518 | |
| 519 | void ReadingListModel::deleteItem(const QModelIndex &mi) |
| 520 | { |