1+ #include " NotePropertyMapper.h"
2+ #include " NotePropertyMapper_p.h"
3+
4+ #include < dspxmodel/SelectionModel.h>
5+
6+ namespace Core {
7+
8+ NotePropertyMapper::NotePropertyMapper (QObject *parent)
9+ : QObject(parent), d_ptr(new NotePropertyMapperPrivate) {
10+ Q_D (NotePropertyMapper);
11+ d->q_ptr = this ;
12+ }
13+
14+ NotePropertyMapper::~NotePropertyMapper () = default ;
15+
16+ dspx::SelectionModel *NotePropertyMapper::selectionModel () const {
17+ Q_D (const NotePropertyMapper);
18+ return d->selectionModel ;
19+ }
20+
21+ void NotePropertyMapper::setSelectionModel (dspx::SelectionModel *selectionModel) {
22+ Q_D (NotePropertyMapper);
23+ if (d->selectionModel == selectionModel) {
24+ return ;
25+ }
26+ d->setSelectionModel (selectionModel);
27+ Q_EMIT selectionModelChanged ();
28+ }
29+
30+ QVariant NotePropertyMapper::centShift () const {
31+ Q_D (const NotePropertyMapper);
32+ return d->value <NotePropertyMapperPrivate::CentShiftProperty>();
33+ }
34+
35+ void NotePropertyMapper::setCentShift (const QVariant ¢Shift) {
36+ Q_D (NotePropertyMapper);
37+ d->setValue <NotePropertyMapperPrivate::CentShiftProperty>(centShift);
38+ }
39+
40+ QVariant NotePropertyMapper::keyNum () const {
41+ Q_D (const NotePropertyMapper);
42+ return d->value <NotePropertyMapperPrivate::KeyNumProperty>();
43+ }
44+
45+ void NotePropertyMapper::setKeyNum (const QVariant &keyNum) {
46+ Q_D (NotePropertyMapper);
47+ d->setValue <NotePropertyMapperPrivate::KeyNumProperty>(keyNum);
48+ }
49+
50+ QVariant NotePropertyMapper::language () const {
51+ Q_D (const NotePropertyMapper);
52+ return d->value <NotePropertyMapperPrivate::LanguageProperty>();
53+ }
54+
55+ void NotePropertyMapper::setLanguage (const QVariant &language) {
56+ Q_D (NotePropertyMapper);
57+ d->setValue <NotePropertyMapperPrivate::LanguageProperty>(language);
58+ }
59+
60+ QVariant NotePropertyMapper::length () const {
61+ Q_D (const NotePropertyMapper);
62+ return d->value <NotePropertyMapperPrivate::LengthProperty>();
63+ }
64+
65+ void NotePropertyMapper::setLength (const QVariant &length) {
66+ Q_D (NotePropertyMapper);
67+ d->setValue <NotePropertyMapperPrivate::LengthProperty>(length);
68+ }
69+
70+ QVariant NotePropertyMapper::lyric () const {
71+ Q_D (const NotePropertyMapper);
72+ return d->value <NotePropertyMapperPrivate::LyricProperty>();
73+ }
74+
75+ void NotePropertyMapper::setLyric (const QVariant &lyric) {
76+ Q_D (NotePropertyMapper);
77+ d->setValue <NotePropertyMapperPrivate::LyricProperty>(lyric);
78+ }
79+
80+ QVariant NotePropertyMapper::pos () const {
81+ Q_D (const NotePropertyMapper);
82+ return d->value <NotePropertyMapperPrivate::PosProperty>();
83+ }
84+
85+ void NotePropertyMapper::setPos (const QVariant &pos) {
86+ Q_D (NotePropertyMapper);
87+ d->setValue <NotePropertyMapperPrivate::PosProperty>(pos);
88+ }
89+
90+ QVariant NotePropertyMapper::pronunciationOriginal () const {
91+ Q_D (const NotePropertyMapper);
92+ return d->value <NotePropertyMapperPrivate::PronunciationOriginalProperty>();
93+ }
94+
95+ void NotePropertyMapper::setPronunciationOriginal (const QVariant &pronunciationOriginal) {
96+ Q_D (NotePropertyMapper);
97+ d->setValue <NotePropertyMapperPrivate::PronunciationOriginalProperty>(pronunciationOriginal);
98+ }
99+
100+ QVariant NotePropertyMapper::pronunciationEdited () const {
101+ Q_D (const NotePropertyMapper);
102+ return d->value <NotePropertyMapperPrivate::PronunciationEditedProperty>();
103+ }
104+
105+ void NotePropertyMapper::setPronunciationEdited (const QVariant &pronunciationEdited) {
106+ Q_D (NotePropertyMapper);
107+ d->setValue <NotePropertyMapperPrivate::PronunciationEditedProperty>(pronunciationEdited);
108+ }
109+
110+ QVariant NotePropertyMapper::singingClip () const {
111+ Q_D (const NotePropertyMapper);
112+ return d->value <NotePropertyMapperPrivate::SingingClipProperty>();
113+ }
114+
115+ void NotePropertyMapperPrivate::setSelectionModel (dspx::SelectionModel *selectionModel_) {
116+ if (selectionModel == selectionModel_) {
117+ return ;
118+ }
119+ detachSelectionModel ();
120+ selectionModel = selectionModel_;
121+ attachSelectionModel ();
122+ refreshCache ();
123+ }
124+
125+ void NotePropertyMapperPrivate::attachSelectionModel () {
126+ Q_Q (NotePropertyMapper);
127+ if (!selectionModel) {
128+ return ;
129+ }
130+ noteSelectionModel = selectionModel->noteSelectionModel ();
131+ if (!noteSelectionModel) {
132+ return ;
133+ }
134+ QObject::connect (noteSelectionModel, &dspx::NoteSelectionModel::itemSelected, q, [this ](dspx::Note *note, bool selected) {
135+ handleItemSelected (note, selected);
136+ });
137+ const auto existing = noteSelectionModel->selectedItems ();
138+ for (auto *note : existing) {
139+ addItem (note);
140+ }
141+ refreshCache ();
142+ }
143+
144+ void NotePropertyMapperPrivate::detachSelectionModel () {
145+ if (noteSelectionModel) {
146+ QObject::disconnect (noteSelectionModel, nullptr , q_ptr, nullptr );
147+ }
148+ clear ();
149+ noteSelectionModel = nullptr ;
150+ selectionModel = nullptr ;
151+ }
152+ }
153+
154+ #include " moc_NotePropertyMapper.cpp"
0 commit comments