Commit 3e0144b4 authored by Nicolas Carion's avatar Nicolas Carion
Browse files

make sure parent folder are correctly stored

parent 0d9b06f6
......@@ -85,8 +85,7 @@ bool TreeItem::appendChild(std::shared_ptr<TreeItem> child)
}
if (auto ptr = m_model.lock()) {
ptr->notifyRowAboutToAppend(shared_from_this());
child->m_depth = m_depth + 1;
child->m_parentItem = shared_from_this();
child->updateParent(shared_from_this());
int id = child->getId();
auto it = m_childItems.insert(m_childItems.end(), child);
m_iteratorTable[id] = it;
......@@ -102,17 +101,16 @@ bool TreeItem::appendChild(std::shared_ptr<TreeItem> child)
void TreeItem::moveChild(int ix, std::shared_ptr<TreeItem> child)
{
if (auto ptr = m_model.lock()) {
auto childPtr = child->m_parentItem.lock();
if (childPtr && childPtr->getId() != m_id) {
childPtr->removeChild(child);
auto parentPtr = child->m_parentItem.lock();
if (parentPtr && parentPtr->getId() != m_id) {
parentPtr->removeChild(child);
} else {
// deletion of child
auto it = m_iteratorTable[child->getId()];
m_childItems.erase(it);
}
ptr->notifyRowAboutToAppend(shared_from_this());
child->m_depth = m_depth + 1;
child->m_parentItem = shared_from_this();
child->updateParent(shared_from_this());
int id = child->getId();
auto pos = m_childItems.begin();
std::advance(pos, ix);
......@@ -264,3 +262,11 @@ bool TreeItem::isRoot() const
{
return m_isRoot;
}
void TreeItem::updateParent(std::shared_ptr<TreeItem> parent)
{
m_parentItem = parent;
if (parent) {
m_depth = parent->m_depth + 1;
}
}
......@@ -144,6 +144,12 @@ protected:
static void registerSelf(std::shared_ptr<TreeItem> self);
void deregisterSelf();
/* @brief Reflect update of the parent ptr (for example set the correct depth)
This is meant to be overriden in derived classes
@param ptr is the pointer to the new parent
*/
virtual void updateParent(std::shared_ptr<TreeItem> parent);
std::list<std::shared_ptr<TreeItem>> m_childItems;
std::unordered_map<int, std::list<std::shared_ptr<TreeItem>>::iterator>
m_iteratorTable; // this logs the iterator associated which each child id. This allows easy access of a child based on its id.
......
......@@ -280,14 +280,14 @@ QString AbstractProjectItem::lastParentId() const
return m_lastParentId;
}
bool AbstractProjectItem::changeParent(std::shared_ptr<TreeItem> newParent)
void AbstractProjectItem::updateParent(std::shared_ptr<TreeItem> newParent)
{
bool reload = !m_lastParentId.isEmpty();
m_lastParentId.clear();
if (newParent) {
m_lastParentId = std::static_pointer_cast<AbstractProjectItem>(newParent)->clipId();
}
bool result = TreeItem::changeParent(newParent);
bool result = TreeItem::updateParent(newParent);
if (reload && result) {
pCore->jobManager()->startJob<ThumbJob>({clipId()}, {}, QString(), 150, -1, true);
pCore->jobManager()->startJob<AudioThumbJob>({clipId()}, {}, QString());
......
......@@ -171,8 +171,8 @@ public:
Return the empty string if the element was parentless */
QString lastParentId() const;
/* @brief This is an overload of TreeItem::changeParent that tracks the id of the id of the parent */
bool changeParent(std::shared_ptr<TreeItem> newParent) override;
/* @brief This is an overload of TreeItem::updateParent that tracks the id of the id of the parent */
void updateParent(std::shared_ptr<TreeItem> newParent) override;
/* Returns a ptr to the enclosing dir, and nullptr if none is found.
@param strict if set to false, the enclosing dir of a dir is itself, otherwise we try to find a "true" parent
......
......@@ -2287,9 +2287,7 @@ void Bin::doMoveClip(const QString &id, const QString &newParentId)
}
std::shared_ptr<AbstractProjectItem> currentParent = currentItem->parent();
std::shared_ptr<ProjectFolder> newParent = m_itemModel->getFolderByBinId(newParentId);
currentParent->removeChild(currentItem);
currentItem->changeParent(newParent);
currentItem->updateParentInfo(newParentId, newParent->name());
}
void Bin::doMoveFolder(const QString &id, const QString &newParentId)
......
......@@ -36,6 +36,7 @@ BinPlaylist::BinPlaylist()
void BinPlaylist::manageBinItemInsertion(const std::shared_ptr<AbstractProjectItem> &binElem)
{
qDebug() << "MANAGE BIN ITEM INSERT"<<binElem->clipId();
QString id = binElem->clipId();
switch (binElem->itemType()) {
case AbstractProjectItem::FolderItem: {
......@@ -49,9 +50,12 @@ void BinPlaylist::manageBinItemInsertion(const std::shared_ptr<AbstractProjectIt
case AbstractProjectItem::ClipItem: {
Q_ASSERT(m_allClips.count(id) == 0);
auto clip = std::static_pointer_cast<ProjectClip>(binElem);
qDebug() << "Inserting clip"<<binElem->clipId();
if (clip->isValid()) {
qDebug() << "Inserting valid clip"<<binElem->clipId();
m_binPlaylist->append(*clip->originalProducer().get());
} else {
qDebug() << "Inserting invalid clip"<<binElem->clipId();
// if clip is not loaded yet, we insert a dummy producer
Mlt::Producer dummy(pCore->getCurrentProfile()->profile(), "color:blue");
dummy.set("kdenlive:id", id.toUtf8().constData());
......@@ -108,6 +112,7 @@ void BinPlaylist::removeBinClip(const QString &id)
void BinPlaylist::changeProducer(const QString &id, const std::shared_ptr<Mlt::Producer> &producer)
{
Q_ASSERT(m_allClips.count(id) > 0);
qDebug() << "888888888 Changing producer"<<id;
removeBinClip(id);
m_binPlaylist->append(*producer.get());
}
......
......@@ -364,6 +364,8 @@ bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool repl
}
// Make sure we have a hash for this clip
getFileHash();
// set parent again (some info need to be stored in producer)
updateParent(parentItem().lock());
return true;
}
......@@ -396,7 +398,7 @@ std::shared_ptr<Mlt::Producer> ProjectClip::thumbProducer()
std::shared_ptr<Mlt::Producer> ProjectClip::timelineProducer(PlaylistState::ClipState state, int track)
{
if (!m_service.startsWith(QLatin1String("avformat"))) {
std::shared_ptr<Mlt::Producer>prod(originalProducer()->cut());
std::shared_ptr<Mlt::Producer> prod(originalProducer()->cut());
int length = getProducerIntProperty(QStringLiteral("kdenlive:duration"));
if (length > 0) {
prod->set_in_and_out(0, length);
......@@ -653,10 +655,14 @@ ClipPropertiesController *ProjectClip::buildProperties(QWidget *parent)
return panel;
}
void ProjectClip::updateParentInfo(const QString &folderid, const QString &foldername)
void ProjectClip::updateParent(std::shared_ptr<TreeItem> parent)
{
Q_UNUSED(foldername);
ClipController::setProducerProperty(QStringLiteral("kdenlive:folderid"), folderid);
if (parent) {
auto item = std::static_pointer_cast<AbstractProjectItem>(parent);
ClipController::setProducerProperty(QStringLiteral("kdenlive:folderid"), item->clipId());
qDebug() << "Setting parent to " << item->clipId();
}
AbstractProjectItem::updateParent(parent);
}
bool ProjectClip::matches(const QString &condition)
......
......@@ -164,7 +164,6 @@ public:
QVariantList audioFrameCache;
bool audioThumbCreated() const;
void updateParentInfo(const QString &folderid, const QString &foldername);
void setWaitingStatus(const QString &id);
/** @brief Returns true if the clip matched a condition, for example vcodec=mpeg1video. */
bool matches(const QString &condition);
......@@ -200,6 +199,9 @@ protected:
*/
void registerTimelineClip(std::weak_ptr<TimelineModel> timeline, int clipId);
/* @brief update the producer to reflect new parent folder */
void updateParent(std::shared_ptr<TreeItem> parent) override;
/** @brief This is a call-back called by a ClipModel when it is deleted
@param clipId id of the deleted clip
*/
......
......@@ -478,18 +478,21 @@ QString ClipController::serviceName() const
void ClipController::setProducerProperty(const QString &name, int value)
{
if (!m_masterProducer) return;
// TODO: also set property on all track producers
m_masterProducer->parent().set(name.toUtf8().constData(), value);
}
void ClipController::setProducerProperty(const QString &name, double value)
{
if (!m_masterProducer) return;
// TODO: also set property on all track producers
m_masterProducer->parent().set(name.toUtf8().constData(), value);
}
void ClipController::setProducerProperty(const QString &name, const QString &value)
{
if (!m_masterProducer) return;
// TODO: also set property on all track producers
if (value.isEmpty()) {
m_masterProducer->parent().set(name.toUtf8().constData(), (char *)nullptr);
......
......@@ -865,7 +865,7 @@ void ProjectManager::slotMoveFinished(KJob *job)
void ProjectManager::updateTimeline(int pos)
{
pCore->jobManager()->slotCancelJobs();
// qDebug() << "Loading xml"<<m_project->getProjectXml().constData();
qDebug() << "Loading xml"<<m_project->getProjectXml().constData();
QScopedPointer<Mlt::Producer> xmlProd(new Mlt::Producer(pCore->getCurrentProfile()->profile(), "xml-string", m_project->getProjectXml().constData()));
Mlt::Service s(*xmlProd);
Mlt::Tractor tractor(s);
......
......@@ -451,7 +451,7 @@ int Render::setSceneList(QString playlist, int position)
// if (m_winid == -1) return -1;
int error = 0;
// qCDebug(KDENLIVE_LOG) << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
qDebug() << "////// RENDER, SET SCENE LIST:\n" << playlist <<"\n..........:::.";
// Remove previous profile info
QDomDocument doc;
......
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