| 517 | } |
| 518 | |
| 519 | void ReadingListModel::deleteItem(const QModelIndex &mi) |
| 520 | { |
| 521 | if (isEditable(mi)) { |
| 522 | QLOG_DEBUG() << "parent row :" << mi.parent().data() << "-" << mi.row(); |
| 523 | beginRemoveRows(mi.parent(), mi.row(), mi.row()); |
| 524 | QString connectionName = ""; |
| 525 | { |
| 526 | QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath); |
| 527 | |
| 528 | auto item = static_cast<ListItem *>(mi.internalPointer()); |
| 529 | |
| 530 | if (typeid(*item) == typeid(ReadingListItem)) { |
| 531 | auto rli = static_cast<ReadingListItem *>(item); |
| 532 | QLOG_DEBUG() << "num children : " << rli->parent->childCount(); |
| 533 | rli->parent->removeChild(rli); |
| 534 | QLOG_DEBUG() << "num children : " << rli->parent->childCount(); |
| 535 | DBHelper::removeListFromDB(item->getId(), db); |
| 536 | if (rli->parent->getId() != 0) { |
| 537 | reorderingChildren(rli->parent->children()); |
| 538 | } |
| 539 | QLOG_DEBUG() << "num children : " << rli->parent->childCount(); |
| 540 | } else if (typeid(*item) == typeid(LabelItem)) { |
| 541 | auto li = static_cast<LabelItem *>(item); |
| 542 | labels.removeOne(li); |
| 543 | DBHelper::removeLabelFromDB(item->getId(), db); |
| 544 | } |
| 545 | connectionName = db.connectionName(); |
| 546 | } |
| 547 | QSqlDatabase::removeDatabase(connectionName); |
| 548 | |
| 549 | endRemoveRows(); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | const QList<LabelItem *> ReadingListModel::getLabels() |
| 554 | { |
no test coverage detected