diff --git a/lib/macro/macro-tab.cpp b/lib/macro/macro-tab.cpp index f8158a79..6cc4c96a 100644 --- a/lib/macro/macro-tab.cpp +++ b/lib/macro/macro-tab.cpp @@ -123,7 +123,9 @@ void AdvSceneSwitcher::on_macroAdd_clicked() } if (selectedMacro->IsGroup()) { - ui->macros->Add(newMacro, selectedMacro); + ui->macros->ExpandGroup(selectedMacro); + Macro::PrepareMoveToGroup(selectedMacro, newMacro); + ui->macros->AddToGroup(newMacro, selectedMacro); emit MacroAdded(QString::fromStdString(name)); return; } diff --git a/lib/macro/macro-tree.cpp b/lib/macro/macro-tree.cpp index 05006a5d..6c7f18cc 100644 --- a/lib/macro/macro-tree.cpp +++ b/lib/macro/macro-tree.cpp @@ -414,6 +414,20 @@ void MacroTreeModel::Add(std::shared_ptr item) QItemSelectionModel::Select); } +void MacroTreeModel::MoveToBeginningOfGroup(std::shared_ptr item, + std::shared_ptr group) +{ + auto it = std::find(_macros.begin(), _macros.end(), item); + assert(it != _macros.end()); + std::shared_ptr tmp = *it; + _macros.erase(it); + it = std::find(_macros.begin(), _macros.end(), group); + assert(it != _macros.end()); + _macros.insert(std::next(it), tmp); + + Reset(_macros); +} + void MacroTreeModel::Remove(std::shared_ptr item) { auto lock = LockContext(); @@ -789,6 +803,13 @@ void MacroTree::Add(std::shared_ptr item, assert(GetModel()->IsInValidState()); } +void MacroTree::AddToGroup(std::shared_ptr item, + std::shared_ptr group) const +{ + GetModel()->Add(item); + GetModel()->MoveToBeginningOfGroup(item, group); +} + std::shared_ptr MacroTree::GetCurrentMacro() const { return GetModel()->GetCurrentMacro(); @@ -1160,6 +1181,18 @@ bool MacroTree::SelectionEmpty() const return selectedIndexes().empty(); } +void MacroTree::ExpandGroup(std::shared_ptr item) const +{ + auto *mtm = GetModel(); + mtm->ExpandGroup(item); +} + +void MacroTree::CollapseGroup(std::shared_ptr item) const +{ + auto *mtm = GetModel(); + mtm->CollapseGroup(item); +} + void MacroTree::MoveItemBefore(const std::shared_ptr &item, const std::shared_ptr &after) const { diff --git a/lib/macro/macro-tree.hpp b/lib/macro/macro-tree.hpp index fd798f7b..09015f18 100644 --- a/lib/macro/macro-tree.hpp +++ b/lib/macro/macro-tree.hpp @@ -91,6 +91,8 @@ private: void MoveItemAfter(const std::shared_ptr &item, const std::shared_ptr &after); void Add(std::shared_ptr item); + void MoveToBeginningOfGroup(std::shared_ptr item, + std::shared_ptr); void Remove(std::shared_ptr item); std::shared_ptr Neighbor(const std::shared_ptr &m, bool above) const; @@ -126,6 +128,8 @@ public: void Reset(std::deque> &, bool highlight); void Add(std::shared_ptr item, std::shared_ptr after = {}) const; + void AddToGroup(std::shared_ptr item, + std::shared_ptr group) const; void Remove(std::shared_ptr item) const; void Up(std::shared_ptr item) const; void Down(std::shared_ptr item) const; @@ -135,6 +139,8 @@ public: bool GroupedItemsSelected() const; bool SingleItemSelected() const; bool SelectionEmpty() const; + void ExpandGroup(std::shared_ptr item) const; + void CollapseGroup(std::shared_ptr item) const; public slots: void GroupSelectedItems();