Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
foldable_track.h
1// SPDX-FileCopyrightText: © 2021, 2024-2025 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "structure/tracks/track.h"
7
8namespace zrythm::structure::tracks
9{
13class FoldableTrackMixin : public QAbstractListModel
14{
15 Q_OBJECT
16 Q_PROPERTY (bool folded READ folded WRITE setFolded NOTIFY foldedChanged)
17 QML_ELEMENT
18 QML_UNCREATABLE ("")
19
20public:
21 FoldableTrackMixin (
22 TrackRegistry &track_registry,
23 QObject * parent = nullptr) noexcept;
24 ~FoldableTrackMixin () noexcept override = default;
25 Z_DISABLE_COPY_MOVE (FoldableTrackMixin)
26
27 enum TrackRoles
28 {
29 TrackPtrRole = Qt::UserRole + 1,
30 };
31
32 // ========================================================================
33 // QML Interface
34 // ========================================================================
35
36 bool folded () const { return folded_; }
37 void setFolded (bool folded)
38 {
39 if (folded_ == folded)
40 return;
41
42 folded_ = folded;
43 Q_EMIT foldedChanged (folded);
44 }
45 Q_SIGNAL void foldedChanged (bool folded);
46
47 QHash<int, QByteArray> roleNames () const override;
48 int rowCount (const QModelIndex &parent = QModelIndex ()) const override;
49 QVariant
50 data (const QModelIndex &index, int role = Qt::DisplayRole) const override;
51
52 // ========================================================================
53
54private:
55 static constexpr auto kChildrenKey = "children"sv;
56 static constexpr auto kFoldedKey = "folded"sv;
57 friend void to_json (nlohmann::json &j, const FoldableTrackMixin &track);
58 friend void from_json (const nlohmann::json &j, FoldableTrackMixin &track);
59
60private:
61 TrackRegistry &track_registry_;
62
64 bool folded_ = false;
65
66 std::vector<TrackUuidReference> children_;
67};
68
69} // namespace zrythm::structure::tracks