| 561 | } |
| 562 | |
| 563 | void CFavoriteView::dropEvent(QDropEvent *event) |
| 564 | { |
| 565 | qDebug(log) << Q_FUNC_INFO << "drop action:" << event->dropAction(); |
| 566 | bool bRet = false; |
| 567 | auto urls = event->mimeData()->urls(); |
| 568 | foreach(auto url, urls) |
| 569 | { |
| 570 | if(url.isLocalFile()) { |
| 571 | QString filename = url.toLocalFile(); |
| 572 | if (m_pDatabase->ImportFromJsonFile(filename)) { |
| 573 | slotRefresh(); |
| 574 | emit sigShowMessageBox(tr("Success"), tr("Successfully imported favorite from JSON file: %1").arg(filename), QMessageBox::Information); |
| 575 | } else { |
| 576 | QString szErr = tr("Failed to import favorite from JSON file: %1").arg(filename) + "\n"; |
| 577 | if(!m_pDatabase->GetError().isEmpty()) |
| 578 | szErr += "\n" + tr("Error: ") + m_pDatabase->GetError(); |
| 579 | emit sigShowMessageBox(tr("Failure"), szErr, QMessageBox::Critical); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | if(bRet) |
| 584 | event->accept(); |
| 585 | |
| 586 | const CFavoriteMimeData *pData = qobject_cast<const CFavoriteMimeData*>(event->mimeData()); |
| 587 | if(!pData || pData->m_Items.isEmpty() || !m_pTreeView || !m_pModel) { |
| 588 | event->ignore(); |
| 589 | return; |
| 590 | } |
| 591 | |
| 592 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 593 | auto idxParent = m_pTreeView->indexAt(event->position().toPoint()); |
| 594 | #else |
| 595 | auto idxParent = m_pTreeView->indexAt(event->pos()); |
| 596 | #endif |
| 597 | QVariant v = m_pModel->data(idxParent, CFavoriteModel::RoleItem); |
| 598 | CFavoriteDatabase::Item item(TreeItem::TYPE::Node); |
| 599 | if(v.isValid()) |
| 600 | item = v.value<CFavoriteDatabase::Item>(); |
| 601 | if(0 <= item.id && item.isFolder()) |
| 602 | { |
| 603 | foreach(auto i, pData->m_Items) |
| 604 | { |
| 605 | if(i == idxParent) { |
| 606 | qWarning(log) << "Don't drag, the same node."; |
| 607 | break; |
| 608 | } |
| 609 | if (event->dropAction() == Qt::MoveAction) |
| 610 | bRet = m_pModel->Move(i, idxParent); |
| 611 | else if (event->dropAction() == Qt::CopyAction) |
| 612 | bRet = m_pModel->Copy(i, idxParent); |
| 613 | if(!bRet) break; |
| 614 | } |
| 615 | } else { |
| 616 | qWarning(log) << "Don't group node. the id:" << item.id |
| 617 | << " Folder:" << item.isFolder(); |
| 618 | } |
| 619 | |
| 620 | if(bRet) |