Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
relocate_arranger_object_command.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <utility>
7
8#include "structure/arrangement/arranger_object_all.h"
9#include "structure/arrangement/arranger_object_owner.h"
10
11#include <QUndoCommand>
12
13namespace zrythm::commands
14{
15template <structure::arrangement::FinalArrangerObjectSubclass ObjectT>
16class RelocateArrangerObjectCommand : public QUndoCommand
17{
18public:
19 RelocateArrangerObjectCommand (
20 structure::arrangement::ArrangerObjectUuidReference region_ref,
23 : QUndoCommand (QObject::tr ("Relocate Object")),
24 obj_ref_ (std::move (region_ref)), target_owner_ (target_owner),
25 source_owner_ (source_owner)
26 {
27 if (
28 !std::ranges::contains (
29 source_owner_.get_children_vector (), obj_ref_.id (),
30 &structure::arrangement::ArrangerObjectUuidReference::id))
31 {
32 throw std::invalid_argument ("Source owner does not include the object");
33 }
34 }
35
36 void undo () override
37 {
38 // move object back
39 auto region_ref = target_owner_.remove_object (obj_ref_.id ());
40 source_owner_.add_object (region_ref);
41 }
42 void redo () override
43 {
44 // move object
45 auto region_ref = source_owner_.remove_object (obj_ref_.id ());
46 target_owner_.add_object (region_ref);
47 }
48
49private:
50 structure::arrangement::ArrangerObjectUuidReference obj_ref_;
53};
54
55} // namespace zrythm::commands