| 411 | } |
| 412 | |
| 413 | bool CFavoriteModel::AddTree(const CFavoriteDatabase::Item &item, int parentId) |
| 414 | { |
| 415 | if (item.id == 0) return false; |
| 416 | |
| 417 | auto parent = GetTree(parentId); |
| 418 | if(!parent) { |
| 419 | qCritical(log) << QString("m_Folders[%1] is nullptr").arg(parentId); |
| 420 | return false; |
| 421 | } |
| 422 | |
| 423 | auto t = new tree(item); |
| 424 | if (!t) { |
| 425 | qCritical(log) << "Failed to allocate memory for tree node"; |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | int pos = parent->GetInserIndex(t); |
| 430 | |
| 431 | QModelIndex parentIndex = CreateIndex(parent); |
| 432 | |
| 433 | beginInsertRows(parentIndex, pos, pos); |
| 434 | |
| 435 | parent->InsertChild(pos, t); |
| 436 | |
| 437 | if (item.isFolder()) { |
| 438 | m_Folders[item.id] = t; |
| 439 | } |
| 440 | |
| 441 | endInsertRows(); |
| 442 | |
| 443 | emit dataChanged(parentIndex, parentIndex); |
| 444 | |
| 445 | return true; |
| 446 | } |
| 447 | |
| 448 | bool CFavoriteModel::UpdateTree(const QString &szFile) |
| 449 | { |
nothing calls this directly
no test coverage detected