Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Load/save of groups (subgroups not working yet)

parent a343393a
......@@ -741,7 +741,7 @@ void ProjectManager::prepareSave()
// TODO REFAC: save target tracks, preview chunks and guides
pCore->binController()->saveDocumentProperties(m_project->documentProperties(), m_project->metadata(), m_project->getGuideModel());
pCore->binController()->saveProperty(QStringLiteral("kdenlive:documentnotes"), documentNotes());
pCore->binController()->saveProperty(QStringLiteral("kdenlive:groups"), m_mainTimelineModel->groupsData());
pCore->binController()->saveProperty(QStringLiteral("kdenlive:docproperties.groups"), m_mainTimelineModel->groupsData());
}
void ProjectManager::slotResetProfiles()
......@@ -865,7 +865,7 @@ void ProjectManager::updateTimeline(int pos)
Mlt::Tractor tractor(s);
m_mainTimelineModel = TimelineItemModel::construct(&pCore->getCurrentProfile()->profile(), m_project->getGuideModel(), m_project->commandStack());
constructTimelineFromMelt(m_mainTimelineModel, tractor);
m_mainTimelineModel->loadGroups(m_project->getDocumentProperty(QStringLiteral("groups")));
m_project->loadThumbs();
pCore->monitorManager()->projectMonitor()->setProducer(m_mainTimelineModel->producer(), pos);
......
......@@ -24,9 +24,6 @@
#include "timelineitemmodel.hpp"
#include <QDebug>
#include <QModelIndex>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <queue>
#include <utility>
......@@ -254,22 +251,7 @@ void GroupsModel::removeFromGroup(int id)
m_upLink[id] = -1;
}
const QString GroupsModel::toJson() const
std::unordered_map<int, int>GroupsModel::groupsData()
{
READ_LOCK();
QJsonArray list;
for (const auto &uplink : m_upLink) {
QJsonObject currentGroup;
currentGroup.insert(QLatin1String("id"), QJsonValue(uplink.first));
currentGroup.insert(QLatin1String("parent"), QJsonValue(uplink.second));
std::unordered_set<int> children = getLeaves(uplink.first);
QJsonArray array;
for (const int &child : children) {
array.append(child);
}
currentGroup.insert(QLatin1String("leaves"), QJsonValue(array));
list.push_back(currentGroup);
}
QJsonDocument json(list);
return QString(json.toJson());
return m_upLink;
}
......@@ -49,7 +49,6 @@ public:
Returns the id of the new group, or -1 on error.
*/
int groupItems(const std::unordered_set<int> &ids, Fun &undo, Fun &redo, bool temporarySelection = false);
const QString toJson() const;
protected:
/* Lambda version */
......@@ -109,6 +108,10 @@ public:
*/
std::unordered_set<int> getDirectChildren(int id) const;
/* @brief Returns group data for saving
*/
std::unordered_map<int, int>groupsData();
protected:
/* @brief Destruct a groupItem in the hierarchy.
All its children will become their own roots
......
......@@ -38,6 +38,10 @@
#include <mlt++/MltTransition.h>
#include <mlt++/MltField.h>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <utility>
TimelineItemModel::TimelineItemModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack> undo_stack)
......@@ -400,7 +404,68 @@ const QString TimelineItemModel::getCompositingTransition()
const QString TimelineItemModel::groupsData()
{
return m_groups->toJson();
std::unordered_map<int, int>upLinks = m_groups->groupsData();
QJsonArray list;
for (const auto &uplink : upLinks) {
QJsonObject currentGroup;
int cid = uplink.first;
if (isClip(cid) || isComposition(cid)) {
continue;
} else {
// encountering a group
currentGroup.insert(QLatin1String("id"), QJsonValue(cid));
currentGroup.insert(QLatin1String("parent"), QJsonValue(uplink.second));
std::unordered_set<int> children = m_groups->getLeaves(cid);
QJsonArray array;
for (const int &child : children) {
if (isClip(child) || isComposition(child)) {
array.append(QString("%1:%2").arg(getTrackMltIndex(getItemTrackId(child))).arg(getItemPosition(child)));
} else {
// this is a subgroup
array.append(child);
}
}
currentGroup.insert(QLatin1String("leaves"), QJsonValue(array));
}
list.push_back(currentGroup);
}
QJsonDocument json(list);
return QString(json.toJson());
}
bool TimelineItemModel::loadGroups(const QString &groupsData)
{
auto json = QJsonDocument::fromJson(groupsData.toUtf8());
if (!json.isArray()) {
qDebug() << "Error : Json file should be an array";
return false;
}
auto list = json.array();
for (const auto &entry : list) {
if (!entry.isObject()) {
qDebug() << "Warning : Skipping invalid marker data";
continue;
}
auto entryObj = entry.toObject();
if (!entryObj.contains(QLatin1String("leaves"))) {
qDebug() << "Warning : Skipping invalid empty group";
continue;
}
auto clipList = entryObj[QLatin1String("leaves")].toArray();
std::unordered_set<int> ids;
for (int i = 0; i < clipList.count(); i++) {
QString clip = clipList[i].toString();
if (clip.contains(QStringLiteral(":"))) {
int track = getTrackIndexFromPosition(clip.section(":", 0, 0).toInt() - 1);
int position = clip.section(":", 1, 1).toInt();
int cid = getClipByPosition(track, position);
ids.insert(cid);
}
}
requestClipsGroup(ids, false, false);
return true;
}
return false;
}
bool TimelineItemModel::isInSelection(int cid) const
......
......@@ -89,6 +89,7 @@ public:
void buildTrackCompositing();
static const QString getCompositingTransition();
const QString groupsData();
bool loadGroups(const QString &groupsData);
virtual void _beginRemoveRows(const QModelIndex &, int, int) override;
virtual void _beginInsertRows(const QModelIndex &, int, int) override;
......
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