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

Commit 7c5d807d authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2][Model] Interface for groups in timeline

parent 43d40bf1
......@@ -53,6 +53,10 @@ int GroupsModel::groupItems(const std::unordered_set<int>& ids)
void GroupsModel::ungroupItem(int id)
{
int gid = getRootId(id);
if (gid == id) {
//element is not part of a group
return;
}
if (auto ptr = m_parent.lock()) {
ptr->deregisterGroup(gid);
} else {
......@@ -63,6 +67,24 @@ void GroupsModel::ungroupItem(int id)
destructGroupItem(gid);
}
void GroupsModel::createGroupItem(int id)
{
Q_ASSERT(m_upLink.count(id) == 0);
Q_ASSERT(m_downLink.count(id) == 0);
m_upLink[id] = -1;
m_downLink[id] = std::unordered_set<int>();
}
void GroupsModel::destructGroupItem(int id)
{
removeFromGroup(id);
for (int child : m_downLink[id]) {
m_upLink[child] = -1;
}
m_downLink.erase(id);
m_upLink.erase(id);
}
int GroupsModel::getRootId(int id) const
{
Q_ASSERT(m_upLink.count(id) > 0);
......@@ -114,24 +136,6 @@ std::unordered_set<int> GroupsModel::getLeaves(int id) const
return result;
}
void GroupsModel::createGroupItem(int id)
{
Q_ASSERT(m_upLink.count(id) == 0);
Q_ASSERT(m_downLink.count(id) == 0);
m_upLink[id] = -1;
m_downLink[id] = std::unordered_set<int>();
}
void GroupsModel::destructGroupItem(int id)
{
removeFromGroup(id);
for (int child : m_downLink[id]) {
m_upLink[child] = -1;
}
m_downLink.erase(id);
m_upLink.erase(id);
}
void GroupsModel::setGroup(int id, int groupId)
{
Q_ASSERT(m_upLink.count(id) > 0);
......
......@@ -42,10 +42,22 @@ public:
int groupItems(const std::unordered_set<int>& ids);
/* Deletes the topmost group containing given element
Note that if the element is not in a group, then it will not be touched.
@param id id of the groupitem
*/
void ungroupItem(int id);
/* @brief Create a groupItem in the hierarchy. Initially it is not part of a group
@param id id of the groupItem
*/
void createGroupItem(int id);
/* @brief Destruct a groupItem in the hierarchy.
All its children will become their own roots
@param id id of the groupitem
*/
void destructGroupItem(int id);
/* @brief Get the overall father of a given groupItem
@param id id of the groupitem
*/
......@@ -68,16 +80,6 @@ public:
std::unordered_set<int> getLeaves(int id) const;
protected:
/* @brief Create a groupItem in the hierarchy. Initially it is not part of a group
@param id id of the groupItem
*/
void createGroupItem(int id);
/* @brief Destruct a groupItem in the hierarchy.
All its children will become their own roots
@param id id of the groupitem
*/
void destructGroupItem(int id);
/* @brief change the group of a given item
@param id of the groupItem
......
......@@ -111,6 +111,16 @@ bool TimelineModel::requestClipChangeTrack(int cid, int tid, int position)
return ok;
}
void TimelineModel::groupClips(std::unordered_set<int>&& ids)
{
m_groups->groupItems(std::forward<std::unordered_set<int>>(ids));
}
void TimelineModel::ungroupClip(int id)
{
m_groups->ungroupItem(id);
}
void TimelineModel::registerTrack(std::unique_ptr<TrackModel>&& track, int pos)
{
int id = track->getId();
......@@ -138,6 +148,7 @@ void TimelineModel::registerClip(std::shared_ptr<ClipModel> clip)
int id = clip->getId();
Q_ASSERT(m_allClips.count(id) == 0);
m_allClips[id] = clip;
m_groups->createGroupItem(id);
}
void TimelineModel::registerGroup(int groupId)
......@@ -160,6 +171,7 @@ void TimelineModel::deregisterClip(int id)
//TODO send deletion order to the track containing the clip
Q_ASSERT(m_allClips.count(id) > 0);
m_allClips.erase(id);
m_groups->destructGroupItem(id);
}
void TimelineModel::deregisterGroup(int id)
......
......@@ -85,6 +85,18 @@ public:
@param position is the position where we want to insert
*/
bool requestClipChangeTrack(int cid, int tid, int position);
/* @brief Group together a set of ids
Typically, ids would be ids of clips, but for convenience, some of them can be ids of groups as well.
@param ids Set of ids to group
*/
void groupClips(std::unordered_set<int>&& ids);
/* @brief Destruct the topmost group containing clip
@param id of the clip to degroup (all clips belonging to the same group will be ungrouped as well)
*/
void ungroupClip(int id);
protected:
/* @brief Register a new track. This is a call-back meant to be called from TrackModel
@param pos indicates the number of the track we are adding. If this is -1, then we add at the end.
......
......@@ -186,6 +186,12 @@ TEST_CASE("Interface test of the group hierarchy", "[GroupsModel]")
for (int i = 0; i < 10; i++) {
groups.createGroupItem(i);
//the following call shouldn't do anything, but we test that behaviour too.
groups.ungroupItem(i);
REQUIRE(groups.getRootId(i) == i);
REQUIRE(groups.isLeaf(i));
REQUIRE(groups.getLeaves(i).size() == 1);
REQUIRE(groups.getSubtree(i).size() == 1);
}
auto g1 = std::unordered_set<int>({4,6,7,9});
......
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