comparison data/model/Model.cpp @ 1735:d91ff235e69d by-id

Some messing with Model and AlignmentModel
author Chris Cannam
date Tue, 25 Jun 2019 15:29:34 +0100
parents 601851995f4b
children 565575463752
comparison
equal deleted inserted replaced
1733:c3b5564cfb78 1735:d91ff235e69d
32 << m_typeUri << ">)::~Model(): Model deleted " 32 << m_typeUri << ">)::~Model(): Model deleted "
33 << "with no aboutToDelete notification" 33 << "with no aboutToDelete notification"
34 << endl; 34 << endl;
35 } 35 }
36 36
37 if (m_alignment) { 37 if (!m_alignmentModel.isNone()) {
38 m_alignment->aboutToDelete(); 38 ModelById::release(m_alignmentModel);
39 delete m_alignment; 39 }
40 } 40 }
41 } 41
42 42 void
43 void 43 Model::setSourceModel(ModelId modelId)
44 Model::setSourceModel(Model *model) 44 {
45 { 45 /*!!!
46 if (m_sourceModel) { 46 if (m_sourceModel) {
47 disconnect(m_sourceModel, SIGNAL(aboutToBeDeleted()), 47 disconnect(m_sourceModel, SIGNAL(aboutToBeDeleted()),
48 this, SLOT(sourceModelAboutToBeDeleted())); 48 this, SLOT(sourceModelAboutToBeDeleted()));
49 } 49 }
50 50 */
51 m_sourceModel = model; 51
52 52 m_sourceModel = modelId;
53
54 auto model = ModelById::get(m_sourceModel);
55 if (model) {
56 connect(model.get(), SIGNAL(alignmentCompletionChanged()),
57 this, SIGNAL(alignmentCompletionChanged()));
58 }
59
60
61 /*
53 if (m_sourceModel) { 62 if (m_sourceModel) {
54 connect(m_sourceModel, SIGNAL(alignmentCompletionChanged()), 63 connect(m_sourceModel, SIGNAL(alignmentCompletionChanged()),
55 this, SIGNAL(alignmentCompletionChanged())); 64 this, SIGNAL(alignmentCompletionChanged()));
56 connect(m_sourceModel, SIGNAL(aboutToBeDeleted()), 65 connect(m_sourceModel, SIGNAL(aboutToBeDeleted()),
57 this, SLOT(sourceModelAboutToBeDeleted())); 66 this, SLOT(sourceModelAboutToBeDeleted()));
58 } 67 }
59 } 68 */
60 69 }
70 /*!!!
61 void 71 void
62 Model::aboutToDelete() 72 Model::aboutToDelete()
63 { 73 {
64 SVDEBUG << "Model(" << this << ", \"" 74 SVDEBUG << "Model(" << this << ", \""
65 << objectName() << "\", type name \"" 75 << objectName() << "\", type name \""
81 void 91 void
82 Model::sourceModelAboutToBeDeleted() 92 Model::sourceModelAboutToBeDeleted()
83 { 93 {
84 m_sourceModel = nullptr; 94 m_sourceModel = nullptr;
85 } 95 }
86 96 */
87 void 97 void
88 Model::setAlignment(AlignmentModel *alignment) 98 Model::setAlignment(ModelId alignmentModel)
89 { 99 {
90 SVDEBUG << "Model(" << this << "): accepting alignment model " 100 SVDEBUG << "Model(" << this << "): accepting alignment model "
91 << alignment << endl; 101 << alignmentModel << endl;
92 102
93 if (m_alignment) { 103 if (!m_alignmentModel.isNone()) {
94 m_alignment->aboutToDelete(); 104 ModelById::release(m_alignmentModel);
95 delete m_alignment; 105 }
96 } 106
97 107 m_alignmentModel = alignmentModel;
98 m_alignment = alignment; 108
99 109 auto model = ModelById::get(m_alignmentModel);
100 if (m_alignment) { 110 if (model) {
101 connect(m_alignment, SIGNAL(completionChanged()), 111 connect(model.get(), SIGNAL(completionChanged()),
102 this, SIGNAL(alignmentCompletionChanged())); 112 this, SIGNAL(alignmentCompletionChanged()));
103 } 113 }
104 } 114 }
105 115
106 const AlignmentModel * 116 const ModelId
107 Model::getAlignment() const 117 Model::getAlignment() const
108 { 118 {
109 return m_alignment; 119 return m_alignmentModel;
110 } 120 }
111 121
112 const Model * 122 const ModelId
113 Model::getAlignmentReference() const 123 Model::getAlignmentReference() const
114 { 124 {
115 if (!m_alignment) { 125 auto model = ModelById::getAs<AlignmentModel>(m_alignmentModel);
116 if (m_sourceModel) return m_sourceModel->getAlignmentReference(); 126 if (model) return model->getReferenceModel();
117 return nullptr; 127 else return {};
118 }
119 return m_alignment->getReferenceModel();
120 } 128 }
121 129
122 sv_frame_t 130 sv_frame_t
123 Model::alignToReference(sv_frame_t frame) const 131 Model::alignToReference(sv_frame_t frame) const
124 { 132 {