comparison data/model/Model.cpp @ 319:3ff8f571da09

* Hoist alignment model set/query up to Model, so any models can be aligned * Add Model::aboutToDelete and aboutToBeDeleted for management of models that are contained by or referred to by other models instead of only the document
author Chris Cannam
date Wed, 24 Oct 2007 15:21:38 +0000
parents 70a232b1f12a
children a71dec01c4d3
comparison
equal deleted inserted replaced
318:7a4bd2c8585c 319:3ff8f571da09
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "Model.h" 16 #include "Model.h"
17 #include "AlignmentModel.h"
17 #include "base/PlayParameterRepository.h" 18 #include "base/PlayParameterRepository.h"
18 19
19 #include <QTextStream> 20 #include <QTextStream>
20 21
21 #include <iostream> 22 #include <iostream>
24 25
25 Model::~Model() 26 Model::~Model()
26 { 27 {
27 // std::cerr << "Model::~Model(" << this << ")" << std::endl; 28 // std::cerr << "Model::~Model(" << this << ")" << std::endl;
28 29
30 if (!m_aboutToDelete) {
31 std::cerr << "NOTE: Model::~Model(" << this << ", \""
32 << objectName().toStdString() << "\"): Model deleted "
33 << "with no aboutToDelete notification" << std::endl;
34 }
35
36 if (m_alignment) {
37 m_alignment->aboutToDelete();
38 delete m_alignment;
39 }
40
29 // Subclasses have to handle adding themselves to the repository, 41 // Subclasses have to handle adding themselves to the repository,
30 // if they want to be played. We can't do it from here because 42 // if they want to be played. We can't do it from here because
31 // the repository would be unable to tell whether we were playable 43 // the repository would be unable to tell whether we were playable
32 // or not (because dynamic_cast won't work from the base class ctor) 44 // or not (because dynamic_cast won't work from the base class ctor)
33 PlayParameterRepository::getInstance()->removeModel(this); 45 PlayParameterRepository::getInstance()->removeModel(this);
46 }
47
48 void
49 Model::setSourceModel(Model *model)
50 {
51 if (m_sourceModel) {
52 disconnect(m_sourceModel, SIGNAL(aboutToBeDeleted()),
53 this, SLOT(sourceModelAboutToBeDeleted()));
54 }
55
56 m_sourceModel = model;
57
58 if (m_sourceModel) {
59 connect(m_sourceModel, SIGNAL(aboutToBeDeleted()),
60 this, SLOT(sourceModelAboutToBeDeleted()));
61 }
62 }
63
64 void
65 Model::aboutToDelete()
66 {
67 if (m_aboutToDelete) {
68 std::cerr << "WARNING: Model(" << this << ", \""
69 << objectName().toStdString() << "\")::aboutToDelete: "
70 << "aboutToDelete called more than once for the same model"
71 << std::endl;
72 }
73
74 emit aboutToBeDeleted();
75 m_aboutToDelete = true;
76 }
77
78 void
79 Model::sourceModelAboutToBeDeleted()
80 {
81 m_sourceModel = 0;
82 }
83
84 void
85 Model::setAlignment(AlignmentModel *alignment)
86 {
87 if (m_alignment) {
88 m_alignment->aboutToDelete();
89 delete m_alignment;
90 }
91 m_alignment = alignment;
92 connect(m_alignment, SIGNAL(completionChanged()),
93 this, SIGNAL(alignmentCompletionChanged()));
94 }
95
96 const Model *
97 Model::getAlignmentReference() const
98 {
99 if (!m_alignment) return 0;
100 return m_alignment->getReferenceModel();
101 }
102
103 size_t
104 Model::alignToReference(size_t frame) const
105 {
106 if (!m_alignment) return frame;
107 return m_alignment->toReference(frame);
108 }
109
110 size_t
111 Model::alignFromReference(size_t refFrame) const
112 {
113 if (!m_alignment) return refFrame;
114 return m_alignment->fromReference(refFrame);
115 }
116
117 int
118 Model::getAlignmentCompletion() const
119 {
120 std::cerr << "Model::getAlignmentCompletion" << std::endl;
121 if (!m_alignment) return 100;
122 int completion = 0;
123 (void)m_alignment->isReady(&completion);
124 std::cerr << " -> " << completion << std::endl;
125 return completion;
34 } 126 }
35 127
36 void 128 void
37 Model::toXml(QTextStream &stream, QString indent, 129 Model::toXml(QTextStream &stream, QString indent,
38 QString extraAttributes) const 130 QString extraAttributes) const