Commit 78c6a435 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Only save bin thumbnail on project save to avoid displaying incorrect thumb...

Only save bin thumbnail on project save to avoid displaying incorrect thumb after unsaved project change
parent ffba99db
Pipeline #154883 passed with stage
in 6 minutes and 4 seconds
......@@ -915,6 +915,21 @@ std::vector<QString> ProjectItemModel::getAllClipIds() const
return result;
}
void ProjectItemModel::updateCacheThumbnail(std::unordered_map<QString, std::vector<int>> &thumbData)
{
READ_LOCK();
for (const auto &clip : m_allItems) {
auto c = std::static_pointer_cast<AbstractProjectItem>(clip.second.lock());
if (c->itemType() == AbstractProjectItem::ClipItem) {
int frameNumber = qMax(0, std::static_pointer_cast<ProjectClip>(c)->getProducerIntProperty(QStringLiteral("kdenlive:thumbnailFrame")));
thumbData[c->clipId()].push_back(frameNumber);
} else if (c->itemType() == AbstractProjectItem::SubClipItem) {
QPoint p = c->zone();
thumbData[std::static_pointer_cast<ProjectSubClip>(c)->getMasterClip()->clipId()].push_back(p.x());
}
}
}
QStringList ProjectItemModel::getClipByUrl(const QFileInfo &url) const
{
READ_LOCK();
......
......@@ -87,6 +87,9 @@ public:
/** @brief Returns the id of all the clips (excluding folders) */
std::vector<QString> getAllClipIds() const;
/** @brief Updates the list of all created bin thumbnails */
void updateCacheThumbnail(std::unordered_map<QString, std::vector<int>> &thumbData);
/** @brief Convenience method to access root folder */
std::shared_ptr<ProjectFolder> getRootFolder() const;
......
......@@ -299,7 +299,7 @@ void ClipLoadTask::generateThumbnail(std::shared_ptr<ProjectClip>binClip, std::s
// We don't follow m_isCanceled there,
qDebug()<<"=== GOT THUMB FOR: "<<m_in<<"x"<<m_out;
QMetaObject::invokeMethod(binClip.get(), "setThumbnail", Qt::QueuedConnection, Q_ARG(QImage,result), Q_ARG(int,m_in), Q_ARG(int,m_out), Q_ARG(bool,false));
ThumbnailCache::get()->storeThumbnail(QString::number(m_owner.second), frameNumber, result, true);
ThumbnailCache::get()->storeThumbnail(QString::number(m_owner.second), frameNumber, result, false);
}
}
}
......
......@@ -360,7 +360,15 @@ bool ProjectManager::saveFileAs(const QString &outputFileName, bool saveACopy)
}
QUrl url = QUrl::fromLocalFile(outputFileName);
// Save timeline thumbnails
ThumbnailCache::get()->saveCachedThumbs(pCore->window()->getMainTimeline()->controller()->getThumbKeys());
std::unordered_map<QString, std::vector<int>> thumbKeys = pCore->window()->getMainTimeline()->controller()->getThumbKeys();
pCore->projectItemModel()->updateCacheThumbnail(thumbKeys);
// Remove duplicates
for (auto p : thumbKeys) {
std::sort(p.second.begin(), p.second.end());
auto last = std::unique(p.second.begin(), p.second.end());
p.second.erase(last, p.second.end());
}
ThumbnailCache::get()->saveCachedThumbs(thumbKeys);
if (!saveACopy) {
m_project->setUrl(url);
// setting up autosave file in ~/.kde/data/stalefiles/kdenlive/
......
......@@ -4196,11 +4196,6 @@ const std::unordered_map<QString, std::vector<int>> TimelineController::getThumb
framesToStore[binId].push_back(clp.second->getIn());
framesToStore[binId].push_back(clp.second->getOut());
}
for (auto p : framesToStore) {
std::sort(p.second.begin(), p.second.end());
auto last = std::unique(p.second.begin(), p.second.end());
p.second.erase(last, p.second.end());
}
return framesToStore;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment