Mercurial > hg > svcore
comparison data/model/Model.cpp @ 1766:85b9b466a59f
Merge from branch by-id
author | Chris Cannam |
---|---|
date | Wed, 17 Jul 2019 14:24:51 +0100 |
parents | ee7fd2c01d87 |
children | aa0b56d72f27 |
comparison
equal
deleted
inserted
replaced
1730:649ac57c5a2d | 1766:85b9b466a59f |
---|---|
22 | 22 |
23 //#define DEBUG_COMPLETION 1 | 23 //#define DEBUG_COMPLETION 1 |
24 | 24 |
25 Model::~Model() | 25 Model::~Model() |
26 { | 26 { |
27 SVDEBUG << "Model::~Model(" << this << ")" << endl; | 27 SVDEBUG << "Model::~Model: " << this << " with id " << getId() << endl; |
28 | |
29 if (!m_aboutToDelete) { | |
30 SVDEBUG << "NOTE: Model(" << this << ", \"" | |
31 << objectName() << "\", type uri <" | |
32 << m_typeUri << ">)::~Model(): Model deleted " | |
33 << "with no aboutToDelete notification" | |
34 << endl; | |
35 } | |
36 | |
37 if (m_alignment) { | |
38 m_alignment->aboutToDelete(); | |
39 delete m_alignment; | |
40 } | |
41 } | |
42 | |
43 int | |
44 Model::getNextId() | |
45 { | |
46 static int nextId = 0; | |
47 static QMutex mutex; | |
48 QMutexLocker locker(&mutex); | |
49 int i = nextId; | |
50 if (nextId == INT_MAX) { | |
51 nextId = INT_MIN; | |
52 } | |
53 ++nextId; | |
54 return i; | |
55 } | 28 } |
56 | 29 |
57 void | 30 void |
58 Model::setSourceModel(Model *model) | 31 Model::setSourceModel(ModelId modelId) |
59 { | 32 { |
60 if (m_sourceModel) { | 33 m_sourceModel = modelId; |
61 disconnect(m_sourceModel, SIGNAL(aboutToBeDeleted()), | |
62 this, SLOT(sourceModelAboutToBeDeleted())); | |
63 } | |
64 | 34 |
65 m_sourceModel = model; | 35 auto model = ModelById::get(m_sourceModel); |
66 | 36 if (model) { |
67 if (m_sourceModel) { | 37 connect(model.get(), SIGNAL(alignmentCompletionChanged(ModelId)), |
68 connect(m_sourceModel, SIGNAL(alignmentCompletionChanged()), | 38 this, SIGNAL(alignmentCompletionChanged(ModelId))); |
69 this, SIGNAL(alignmentCompletionChanged())); | |
70 connect(m_sourceModel, SIGNAL(aboutToBeDeleted()), | |
71 this, SLOT(sourceModelAboutToBeDeleted())); | |
72 } | 39 } |
73 } | 40 } |
74 | 41 |
75 void | 42 void |
76 Model::aboutToDelete() | 43 Model::setAlignment(ModelId alignmentModel) |
77 { | |
78 SVDEBUG << "Model(" << this << ", \"" | |
79 << objectName() << "\", type name \"" | |
80 << getTypeName() << "\", type uri <" | |
81 << m_typeUri << ">)::aboutToDelete()" << endl; | |
82 | |
83 if (m_aboutToDelete) { | |
84 SVDEBUG << "WARNING: Model(" << this << ", \"" | |
85 << objectName() << "\", type uri <" | |
86 << m_typeUri << ">)::aboutToDelete: " | |
87 << "aboutToDelete called more than once for the same model" | |
88 << endl; | |
89 } | |
90 | |
91 emit aboutToBeDeleted(); | |
92 m_aboutToDelete = true; | |
93 } | |
94 | |
95 void | |
96 Model::sourceModelAboutToBeDeleted() | |
97 { | |
98 m_sourceModel = nullptr; | |
99 } | |
100 | |
101 void | |
102 Model::setAlignment(AlignmentModel *alignment) | |
103 { | 44 { |
104 SVDEBUG << "Model(" << this << "): accepting alignment model " | 45 SVDEBUG << "Model(" << this << "): accepting alignment model " |
105 << alignment << endl; | 46 << alignmentModel << endl; |
106 | 47 |
107 if (m_alignment) { | 48 if (auto model = ModelById::get(m_alignmentModel)) { |
108 m_alignment->aboutToDelete(); | 49 disconnect(model.get(), SIGNAL(completionChanged(ModelId)), |
109 delete m_alignment; | 50 this, SIGNAL(alignmentCompletionChanged(ModelId))); |
110 } | 51 } |
111 | 52 |
112 m_alignment = alignment; | 53 m_alignmentModel = alignmentModel; |
113 | 54 |
114 if (m_alignment) { | 55 if (auto model = ModelById::get(m_alignmentModel)) { |
115 connect(m_alignment, SIGNAL(completionChanged()), | 56 connect(model.get(), SIGNAL(completionChanged(ModelId)), |
116 this, SIGNAL(alignmentCompletionChanged())); | 57 this, SIGNAL(alignmentCompletionChanged(ModelId))); |
117 } | 58 } |
118 } | 59 } |
119 | 60 |
120 const AlignmentModel * | 61 const ModelId |
121 Model::getAlignment() const | 62 Model::getAlignment() const |
122 { | 63 { |
123 return m_alignment; | 64 return m_alignmentModel; |
124 } | 65 } |
125 | 66 |
126 const Model * | 67 const ModelId |
127 Model::getAlignmentReference() const | 68 Model::getAlignmentReference() const |
128 { | 69 { |
129 if (!m_alignment) { | 70 auto model = ModelById::getAs<AlignmentModel>(m_alignmentModel); |
130 if (m_sourceModel) return m_sourceModel->getAlignmentReference(); | 71 if (model) return model->getReferenceModel(); |
131 return nullptr; | 72 else return {}; |
132 } | |
133 return m_alignment->getReferenceModel(); | |
134 } | 73 } |
135 | 74 |
136 sv_frame_t | 75 sv_frame_t |
137 Model::alignToReference(sv_frame_t frame) const | 76 Model::alignToReference(sv_frame_t frame) const |
138 { | 77 { |
139 // cerr << "Model(" << this << ")::alignToReference(" << frame << ")" << endl; | 78 auto alignmentModel = ModelById::getAs<AlignmentModel>(m_alignmentModel); |
140 if (!m_alignment) { | 79 |
141 if (m_sourceModel) return m_sourceModel->alignToReference(frame); | 80 if (!alignmentModel) { |
142 else return frame; | 81 auto sourceModel = ModelById::get(m_sourceModel); |
82 if (sourceModel) { | |
83 return sourceModel->alignToReference(frame); | |
84 } | |
85 return frame; | |
143 } | 86 } |
144 sv_frame_t refFrame = m_alignment->toReference(frame); | 87 |
145 const Model *m = m_alignment->getReferenceModel(); | 88 sv_frame_t refFrame = alignmentModel->toReference(frame); |
146 if (m && refFrame > m->getEndFrame()) refFrame = m->getEndFrame(); | 89 auto refModel = ModelById::get(alignmentModel->getReferenceModel()); |
147 // cerr << "have alignment, aligned is " << refFrame << endl; | 90 if (refModel && refFrame > refModel->getEndFrame()) { |
91 refFrame = refModel->getEndFrame(); | |
92 } | |
148 return refFrame; | 93 return refFrame; |
149 } | 94 } |
150 | 95 |
151 sv_frame_t | 96 sv_frame_t |
152 Model::alignFromReference(sv_frame_t refFrame) const | 97 Model::alignFromReference(sv_frame_t refFrame) const |
153 { | 98 { |
154 // cerr << "Model(" << this << ")::alignFromReference(" << refFrame << ")" << endl; | 99 auto alignmentModel = ModelById::getAs<AlignmentModel>(m_alignmentModel); |
155 if (!m_alignment) { | 100 |
156 if (m_sourceModel) return m_sourceModel->alignFromReference(refFrame); | 101 if (!alignmentModel) { |
157 else return refFrame; | 102 auto sourceModel = ModelById::get(m_sourceModel); |
103 if (sourceModel) { | |
104 return sourceModel->alignFromReference(refFrame); | |
105 } | |
106 return refFrame; | |
158 } | 107 } |
159 sv_frame_t frame = m_alignment->fromReference(refFrame); | 108 |
109 sv_frame_t frame = alignmentModel->fromReference(refFrame); | |
160 if (frame > getEndFrame()) frame = getEndFrame(); | 110 if (frame > getEndFrame()) frame = getEndFrame(); |
161 // cerr << "have alignment, aligned is " << frame << endl; | |
162 return frame; | 111 return frame; |
163 } | 112 } |
164 | 113 |
165 int | 114 int |
166 Model::getAlignmentCompletion() const | 115 Model::getAlignmentCompletion() const |
167 { | 116 { |
168 #ifdef DEBUG_COMPLETION | 117 #ifdef DEBUG_COMPLETION |
169 SVCERR << "Model(" << this << ")::getAlignmentCompletion: m_alignment = " | 118 SVCERR << "Model(" << this |
170 << m_alignment << endl; | 119 << ")::getAlignmentCompletion: m_alignmentModel = " |
120 << m_alignmentModel << endl; | |
171 #endif | 121 #endif |
172 if (!m_alignment) { | 122 |
173 if (m_sourceModel) return m_sourceModel->getAlignmentCompletion(); | 123 auto alignmentModel = ModelById::getAs<AlignmentModel>(m_alignmentModel); |
174 else return 100; | 124 |
125 if (!alignmentModel) { | |
126 auto sourceModel = ModelById::get(m_sourceModel); | |
127 if (sourceModel) { | |
128 return sourceModel->getAlignmentCompletion(); | |
129 } | |
130 return 100; | |
175 } | 131 } |
132 | |
176 int completion = 0; | 133 int completion = 0; |
177 (void)m_alignment->isReady(&completion); | 134 (void)alignmentModel->isReady(&completion); |
178 #ifdef DEBUG_COMPLETION | 135 #ifdef DEBUG_COMPLETION |
179 SVCERR << "Model(" << this << ")::getAlignmentCompletion: completion = " << completion | 136 SVCERR << "Model(" << this |
137 << ")::getAlignmentCompletion: completion = " << completion | |
180 << endl; | 138 << endl; |
181 #endif | 139 #endif |
182 return completion; | 140 return completion; |
183 } | 141 } |
184 | 142 |
185 QString | 143 QString |
186 Model::getTitle() const | 144 Model::getTitle() const |
187 { | 145 { |
188 if (m_sourceModel) return m_sourceModel->getTitle(); | 146 auto source = ModelById::get(m_sourceModel); |
147 if (source) return source->getTitle(); | |
189 else return ""; | 148 else return ""; |
190 } | 149 } |
191 | 150 |
192 QString | 151 QString |
193 Model::getMaker() const | 152 Model::getMaker() const |
194 { | 153 { |
195 if (m_sourceModel) return m_sourceModel->getMaker(); | 154 auto source = ModelById::get(m_sourceModel); |
155 if (source) return source->getMaker(); | |
196 else return ""; | 156 else return ""; |
197 } | 157 } |
198 | 158 |
199 QString | 159 QString |
200 Model::getLocation() const | 160 Model::getLocation() const |
201 { | 161 { |
202 if (m_sourceModel) return m_sourceModel->getLocation(); | 162 auto source = ModelById::get(m_sourceModel); |
163 if (source) return source->getLocation(); | |
203 else return ""; | 164 else return ""; |
204 } | 165 } |
205 | 166 |
206 void | 167 void |
207 Model::toXml(QTextStream &stream, QString indent, | 168 Model::toXml(QTextStream &stream, QString indent, |