diff --git a/src/macro-core/macro-tab.cpp b/src/macro-core/macro-tab.cpp index e18f47ab..ef130b44 100644 --- a/src/macro-core/macro-tab.cpp +++ b/src/macro-core/macro-tab.cpp @@ -612,9 +612,10 @@ void AdvSceneSwitcher::CopyMacro() newMacro->Load(data); newMacro->PostLoad(); newMacro->SetName(name); + Macro::PrepareMoveToGroup(macro->Parent(), newMacro); obs_data_release(data); - ui->macros->Add(newMacro); + ui->macros->Add(newMacro, macro); ui->macroAdd->disconnect(addPulse); emit MacroAdded(QString::fromStdString(name)); } diff --git a/src/macro-core/macro-tree.cpp b/src/macro-core/macro-tree.cpp index 2e87e993..3163c9c3 100644 --- a/src/macro-core/macro-tree.cpp +++ b/src/macro-core/macro-tree.cpp @@ -260,7 +260,8 @@ MacroIndexToModelIndex(int realIdx, void MacroTreeModel::MoveItemBefore(const std::shared_ptr &item, const std::shared_ptr &before) { - if (!item || !before || item == before) { + if (!item || !before || item == before || + Neighbor(item, false) == before) { return; } @@ -313,7 +314,7 @@ void MacroTreeModel::MoveItemBefore(const std::shared_ptr &item, void MacroTreeModel::MoveItemAfter(const std::shared_ptr &item, const std::shared_ptr &after) { - if (!item || !after || item == after) { + if (!item || !after || item == after || Neighbor(item, true) == after) { return; } @@ -706,9 +707,13 @@ void MacroTree::Reset(std::deque> ¯os, GetModel()->Reset(macros); } -void MacroTree::Add(std::shared_ptr item) const +void MacroTree::Add(std::shared_ptr item, + std::shared_ptr after) const { GetModel()->Add(item); + if (after) { + MoveItemAfter(item, after); + } } std::shared_ptr MacroTree::GetCurrentMacro() const @@ -834,7 +839,7 @@ void MacroTree::dropEvent(QDropEvent *event) Macro *dropItem = items[ModelIndexToMacroIndex(row, items)] .get(); // Item being dropped on bool itemIsGroup = dropItem->IsGroup(); - Macro *dropGroup = itemIsGroup ? dropItem : dropItem->Parent(); + Macro *dropGroup = itemIsGroup ? dropItem : dropItem->Parent().get(); // Not a group if moving above the group if (indicator == QAbstractItemView::AboveItem && itemIsGroup) { @@ -880,7 +885,7 @@ void MacroTree::dropEvent(QDropEvent *event) } if (hasGroups) { - if (!itemBelow || itemBelow->Parent() != dropGroup) { + if (!itemBelow || itemBelow->Parent().get() != dropGroup) { dropGroup = nullptr; dropOnCollapsed = false; } @@ -923,7 +928,7 @@ void MacroTree::dropEvent(QDropEvent *event) bool collapsed = item->IsCollapsed(); for (int j = items.size() - 1; j >= 0; j--) { std::shared_ptr subitem = items[j]; - auto subitemGroup = subitem->Parent(); + auto subitemGroup = subitem->Parent().get(); if (subitemGroup == item.get()) { if (!collapsed) { diff --git a/src/macro-core/macro-tree.hpp b/src/macro-core/macro-tree.hpp index 3eac8158..f1757d85 100644 --- a/src/macro-core/macro-tree.hpp +++ b/src/macro-core/macro-tree.hpp @@ -120,7 +120,8 @@ class MacroTree : public QListView { public: explicit MacroTree(QWidget *parent = nullptr); void Reset(std::deque> &, bool highlight); - void Add(std::shared_ptr item) const; + void Add(std::shared_ptr item, + std::shared_ptr after = {}) const; void Remove(std::shared_ptr item) const; void Up(std::shared_ptr item) const; void Down(std::shared_ptr item) const; diff --git a/src/macro-core/macro.cpp b/src/macro-core/macro.cpp index a3ead0d0..f5b5b6dc 100644 --- a/src/macro-core/macro.cpp +++ b/src/macro-core/macro.cpp @@ -325,10 +325,9 @@ void Macro::UpdateConditionIndices() } } -Macro *Macro::Parent() +std::shared_ptr Macro::Parent() { - auto p = _parent.lock(); - return p.get(); + return _parent.lock(); } bool Macro::Save(obs_data_t *obj) const diff --git a/src/macro-core/macro.hpp b/src/macro-core/macro.hpp index dc81fab0..4300cad4 100644 --- a/src/macro-core/macro.hpp +++ b/src/macro-core/macro.hpp @@ -64,7 +64,7 @@ public: void SetCollapsed(bool val) { _isCollapsed = val; } bool IsCollapsed() { return _isCollapsed; } void SetParent(std::shared_ptr m) { _parent = m; } - Macro *Parent(); + std::shared_ptr Parent(); bool Save(obs_data_t *obj) const; bool Load(obs_data_t *obj);