| 761 | |
| 762 | |
| 763 | void UBPersistenceManager::deleteDocumentScenes(std::shared_ptr<UBDocumentProxy> proxy, const QList<int>& indexes) |
| 764 | { |
| 765 | checkIfDocumentRepositoryExists(); |
| 766 | |
| 767 | int pageCount = proxy->pageCount(); |
| 768 | |
| 769 | QList<int> compactedIndexes; |
| 770 | |
| 771 | foreach(int index, indexes) |
| 772 | { |
| 773 | if (!compactedIndexes.contains(index)) |
| 774 | compactedIndexes.append(index); |
| 775 | } |
| 776 | |
| 777 | if (compactedIndexes.size() == pageCount) |
| 778 | { |
| 779 | deleteDocument(proxy); |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | if (compactedIndexes.size() == 0) |
| 784 | return; |
| 785 | |
| 786 | QString sourceName = proxy->metaData(UBSettings::documentName).toString(); |
| 787 | std::shared_ptr<UBDocumentProxy> trashDocProxy = createDocument(UBSettings::trashedDocumentGroupNamePrefix/* + sourceGroupName*/, sourceName, false); |
| 788 | |
| 789 | foreach(int index, compactedIndexes) |
| 790 | { |
| 791 | std::shared_ptr<UBGraphicsScene> scene = loadDocumentScene(proxy, index); |
| 792 | if (scene) |
| 793 | { |
| 794 | //scene is about to move into new document |
| 795 | foreach (QUrl relativeFile, scene->relativeDependencies()) |
| 796 | { |
| 797 | QString source = scene->document()->persistencePath() + "/" + relativeFile.toString(); |
| 798 | QString target = trashDocProxy->persistencePath() + "/" + relativeFile.toString(); |
| 799 | |
| 800 | QFileInfo fi(target); |
| 801 | QDir d = fi.dir(); |
| 802 | |
| 803 | d.mkpath(d.absolutePath()); |
| 804 | QFile::copy(source, target); |
| 805 | } |
| 806 | insertDocumentSceneAt(trashDocProxy, scene, trashDocProxy->pageCount(), true, true); |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | for (int i = 1; i < indexes.size(); i++) |
| 811 | { |
| 812 | renamePage(trashDocProxy, i , i - 1); |
| 813 | } |
| 814 | |
| 815 | foreach(int index, compactedIndexes) |
| 816 | { |
| 817 | QString svgFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.svg", index); |
| 818 | |
| 819 | QFile::remove(svgFileName); |
| 820 | |