| 2572 | } |
| 2573 | |
| 2574 | void UBDocumentController::duplicateSelectedItem() |
| 2575 | { |
| 2576 | if (UBApplication::applicationController->displayMode() != UBApplicationController::Document) |
| 2577 | return; |
| 2578 | |
| 2579 | if (mSelectionType == Page) |
| 2580 | { |
| 2581 | QList<QGraphicsItem*> selectedItems = mDocumentUI->thumbnailWidget->selectedItems(); |
| 2582 | QList<int> selectedSceneIndexes; |
| 2583 | foreach (QGraphicsItem *item, selectedItems) |
| 2584 | { |
| 2585 | UBThumbnail *thumb = dynamic_cast<UBThumbnail*>(item); |
| 2586 | if (thumb) |
| 2587 | { |
| 2588 | std::shared_ptr<UBDocumentProxy> proxy = mDocumentUI->thumbnailWidget->document()->proxy(); |
| 2589 | |
| 2590 | if (proxy) |
| 2591 | { |
| 2592 | int sceneIndex = thumb->sceneIndex(); |
| 2593 | selectedSceneIndexes << sceneIndex; |
| 2594 | } |
| 2595 | } |
| 2596 | } |
| 2597 | if (selectedSceneIndexes.count() > 0) |
| 2598 | { |
| 2599 | auto document = UBDocument::getDocument(selectedDocument()); |
| 2600 | int offset = 0; |
| 2601 | foreach(int sceneIndex, selectedSceneIndexes) |
| 2602 | { |
| 2603 | document->duplicatePage(sceneIndex + offset); |
| 2604 | offset++; |
| 2605 | } |
| 2606 | |
| 2607 | QDateTime now = QDateTime::currentDateTime(); |
| 2608 | selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(now)); |
| 2609 | UBMetadataDcSubsetAdaptor::persist(selectedDocument()); |
| 2610 | int selectedThumbnailIndex = selectedSceneIndexes.last() + selectedSceneIndexes.size(); |
| 2611 | mDocumentUI->thumbnailWidget->selectItemAt(selectedThumbnailIndex); |
| 2612 | int sceneCount = selectedSceneIndexes.count(); |
| 2613 | UBApplication::showMessage(tr("duplicated %1 page","duplicated %1 pages",sceneCount).arg(sceneCount), false); |
| 2614 | } |
| 2615 | } |
| 2616 | else |
| 2617 | { |
| 2618 | UBDocumentTreeModel *docModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel; |
| 2619 | QModelIndex selectedIndex = firstSelectedTreeIndex(); |
| 2620 | |
| 2621 | Q_ASSERT(!docModel->isConstant(selectedIndex) && !docModel->inTrash(selectedIndex)); |
| 2622 | |
| 2623 | UBApplication::showMessage(tr("Duplicating Document %1").arg(""), true); |
| 2624 | |
| 2625 | docModel->copyIndexToNewParent(selectedIndex, selectedIndex.parent(), UBDocumentTreeModel::aContentCopy); |
| 2626 | |
| 2627 | UBApplication::showMessage(tr("Document %1 copied").arg(""), false); |
| 2628 | } |
| 2629 | |
| 2630 | emit reorderDocumentsRequested(); |
| 2631 | pageSelectionChanged(); |
nothing calls this directly
no test coverage detected