bool ImageScanner::resolveImageHistory(qlonglong imageId, const QString& historyXml, QList<qlonglong>* needTaggingIds) { /** Stage 2 of history scanning */ if (historyXml.isNull()) { return true; // "true" means nothing is left to resolve } DImageHistory history = DImageHistory::fromXml(historyXml); if (history.isNull()) { return true; } ImageHistoryGraph graph; graph.addScannedHistory(history, imageId); if (!graph.hasEdges()) { return true; } QPair<QList<qlonglong>, QList<qlonglong> > cloud = graph.relationCloudParallel(); DatabaseAccess().db()->addImageRelations(cloud.first, cloud.second, DatabaseRelation::DerivedFrom); int needResolvingTag = TagsCache::instance()->getOrCreateInternalTag(InternalTagName::needResolvingHistory()); int needTaggingTag = TagsCache::instance()->getOrCreateInternalTag(InternalTagName::needTaggingHistoryGraph()); // remove the needResolvingHistory tag from all images in graph DatabaseAccess().db()->removeTagsFromItems(graph.allImageIds(), QList<int>() << needResolvingTag); // mark a single image from the graph (sufficient for find the full relation cloud) QList<ImageInfo> roots = graph.rootImages(); if (!roots.isEmpty()) { DatabaseAccess().db()->addItemTag(roots.first().id(), needTaggingTag); if (needTaggingIds) { *needTaggingIds << roots.first().id(); } } return !graph.hasUnresolvedEntries(); }