Insert duplicated macro after original macro

This commit is contained in:
WarmUpTill 2023-05-08 21:49:42 +02:00 committed by WarmUpTill
parent 25b5590d2c
commit d45d4ded99
5 changed files with 18 additions and 12 deletions

View File

@ -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));
}

View File

@ -260,7 +260,8 @@ MacroIndexToModelIndex(int realIdx,
void MacroTreeModel::MoveItemBefore(const std::shared_ptr<Macro> &item,
const std::shared_ptr<Macro> &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<Macro> &item,
void MacroTreeModel::MoveItemAfter(const std::shared_ptr<Macro> &item,
const std::shared_ptr<Macro> &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<std::shared_ptr<Macro>> &macros,
GetModel()->Reset(macros);
}
void MacroTree::Add(std::shared_ptr<Macro> item) const
void MacroTree::Add(std::shared_ptr<Macro> item,
std::shared_ptr<Macro> after) const
{
GetModel()->Add(item);
if (after) {
MoveItemAfter(item, after);
}
}
std::shared_ptr<Macro> 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<Macro> subitem = items[j];
auto subitemGroup = subitem->Parent();
auto subitemGroup = subitem->Parent().get();
if (subitemGroup == item.get()) {
if (!collapsed) {

View File

@ -120,7 +120,8 @@ class MacroTree : public QListView {
public:
explicit MacroTree(QWidget *parent = nullptr);
void Reset(std::deque<std::shared_ptr<Macro>> &, bool highlight);
void Add(std::shared_ptr<Macro> item) const;
void Add(std::shared_ptr<Macro> item,
std::shared_ptr<Macro> after = {}) const;
void Remove(std::shared_ptr<Macro> item) const;
void Up(std::shared_ptr<Macro> item) const;
void Down(std::shared_ptr<Macro> item) const;

View File

@ -325,10 +325,9 @@ void Macro::UpdateConditionIndices()
}
}
Macro *Macro::Parent()
std::shared_ptr<Macro> Macro::Parent()
{
auto p = _parent.lock();
return p.get();
return _parent.lock();
}
bool Macro::Save(obs_data_t *obj) const

View File

@ -64,7 +64,7 @@ public:
void SetCollapsed(bool val) { _isCollapsed = val; }
bool IsCollapsed() { return _isCollapsed; }
void SetParent(std::shared_ptr<Macro> m) { _parent = m; }
Macro *Parent();
std::shared_ptr<Macro> Parent();
bool Save(obs_data_t *obj) const;
bool Load(obs_data_t *obj);