Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Nov 29, 2022
1 parent f9d021e commit 0def65e
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/Chord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@ void Chord::test() {
auto Chord::pointer_copy_self() -> std::unique_ptr<NoteChord> {
return std::make_unique<Chord>(*this);
}

auto Chord::new_child_note_chord_pointer() -> std::unique_ptr<NoteChord> {
return std::make_unique<Note>();
};
2 changes: 2 additions & 0 deletions src/Chord.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ class Chord : public NoteChord {
auto setData(int column, const QVariant &value, int role) -> bool override;
void test() override;
auto pointer_copy_self() -> std::unique_ptr<NoteChord> override;
auto new_child_note_chord_pointer() -> std::unique_ptr<NoteChord> override;

};
7 changes: 7 additions & 0 deletions src/Note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,10 @@ void Note::test() {
auto Note::pointer_copy_self() -> std::unique_ptr<NoteChord> {
return std::make_unique<Note>(*this);
}

auto Note::new_child_note_chord_pointer() -> std::unique_ptr<NoteChord> {
qCritical("Only chords can have chilrden!");
return nullptr;
};


2 changes: 2 additions & 0 deletions src/Note.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ class Note : public NoteChord {
auto setData(int column, const QVariant &value, int role) -> bool override;
void test() override;
auto pointer_copy_self() -> std::unique_ptr<NoteChord> override;
auto new_child_note_chord_pointer() -> std::unique_ptr<NoteChord> override;

};
2 changes: 1 addition & 1 deletion src/NoteChord.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NoteChord {
virtual ~NoteChord() = default;

virtual auto pointer_copy_self() -> std::unique_ptr<NoteChord> = 0;
// virtual auto new_child_note_chord_pointer() -> std::unique_ptr<NoteChord> = 0;
virtual auto new_child_note_chord_pointer() -> std::unique_ptr<NoteChord> = 0;

static auto error_column(int column) -> void;
[[nodiscard]] static auto headerData(int section, Qt::Orientation orientation,
Expand Down
5 changes: 3 additions & 2 deletions src/TestEverything.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ void TestEverything::test_everything() {
QCOMPARE(first_chord_node.get_child_count(), 3);
auto &first_note_node = first_chord_node.get_child(0);
first_note_node.note_chord_pointer -> test();
auto first_chord_index = song.index(1, 1);
auto first_note_index = song.index(1, 1, first_chord_index);
auto first_chord_index = song.index(0, 0);
auto first_note_index = song.index(0, 0, first_chord_index);
song.copy(first_chord_index, 3, editor.copied);


editor.save("C:/Users/brand/Justly/examples/simple.json");
Expand Down
7 changes: 1 addition & 6 deletions src/TreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ auto TreeNode::new_child_note_chord_pointer() -> std::unique_ptr<NoteChord> {
if (note_chord_pointer == nullptr) {
return std::make_unique<Chord>();
}
// TODO: do this with dispatch?
// make sure the parent is a chord
if (note_chord_pointer -> get_level() != 1) {
qCritical("Only chords can have chilrden!");
}
return std::make_unique<Note>();
return note_chord_pointer -> new_child_note_chord_pointer();
}

TreeNode::TreeNode(TreeNode *parent_pointer_input)
Expand Down
6 changes: 3 additions & 3 deletions src/TreeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class TreeNode {
public:
// pointer so it can be null for root
TreeNode *const parent_pointer = nullptr;
// pointers so they can be notes or chords
std::vector<std::unique_ptr<TreeNode>> child_pointers;
// pointer so it can be a note or a chord
const std::unique_ptr<NoteChord> note_chord_pointer;

// pointers so they can be notes or chords
std::vector<std::unique_ptr<TreeNode>> child_pointers;

explicit TreeNode(TreeNode *parent_pointer_input = nullptr);
TreeNode(TreeNode& copied, TreeNode *parent_pointer_input);
TreeNode(TreeNode& copied);
Expand Down

0 comments on commit 0def65e

Please sign in to comment.