Mercurial > hg > svgui
comparison layer/Layer.cpp @ 1486:ac0a8addabcf
Merge from branch by-id
author | Chris Cannam |
---|---|
date | Wed, 17 Jul 2019 14:25:16 +0100 |
parents | e540aa5d89cd |
children | b402121d8f5f |
comparison
equal
deleted
inserted
replaced
1468:de41a11cabc2 | 1486:ac0a8addabcf |
---|---|
44 { | 44 { |
45 // SVDEBUG << "Layer::~Layer(" << this << ")" << endl; | 45 // SVDEBUG << "Layer::~Layer(" << this << ")" << endl; |
46 } | 46 } |
47 | 47 |
48 void | 48 void |
49 Layer::connectSignals(const Model *model) | 49 Layer::connectSignals(ModelId modelId) |
50 { | 50 { |
51 connect(model, SIGNAL(modelChanged()), | 51 auto model = ModelById::get(modelId); |
52 this, SIGNAL(modelChanged())); | 52 if (!model) return; |
53 | 53 |
54 connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), | 54 connect(model.get(), SIGNAL(modelChanged(ModelId)), |
55 this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); | 55 this, SIGNAL(modelChanged(ModelId))); |
56 | 56 |
57 connect(model, SIGNAL(completionChanged()), | 57 connect(model.get(), SIGNAL(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t)), |
58 this, SIGNAL(modelCompletionChanged())); | 58 this, SIGNAL(modelChangedWithin(ModelId, sv_frame_t, sv_frame_t))); |
59 | 59 |
60 connect(model, SIGNAL(alignmentCompletionChanged()), | 60 connect(model.get(), SIGNAL(completionChanged(ModelId)), |
61 this, SIGNAL(modelAlignmentCompletionChanged())); | 61 this, SIGNAL(modelCompletionChanged(ModelId))); |
62 | |
63 connect(model.get(), SIGNAL(alignmentCompletionChanged(ModelId)), | |
64 this, SIGNAL(modelAlignmentCompletionChanged(ModelId))); | |
62 } | 65 } |
63 | 66 |
64 QString | 67 QString |
65 Layer::getPropertyContainerIconName() const | 68 Layer::getPropertyContainerIconName() const |
66 { | 69 { |
82 LayerFactory *factory = LayerFactory::getInstance(); | 85 LayerFactory *factory = LayerFactory::getInstance(); |
83 QString layerName = factory->getLayerPresentationName | 86 QString layerName = factory->getLayerPresentationName |
84 (factory->getLayerType(this)); | 87 (factory->getLayerType(this)); |
85 | 88 |
86 QString modelName; | 89 QString modelName; |
87 if (getModel()) modelName = getModel()->objectName(); | 90 auto model = ModelById::get(getModel()); |
91 if (model) modelName = model->objectName(); | |
88 | 92 |
89 QString text; | 93 QString text; |
90 if (modelName != "") { | 94 if (modelName != "") { |
91 text = QString("%1: %2").arg(modelName).arg(layerName); | 95 text = QString("%1: %2").arg(modelName).arg(layerName); |
92 } else { | 96 } else { |
101 { | 105 { |
102 QObject::setObjectName(name); | 106 QObject::setObjectName(name); |
103 emit layerNameChanged(); | 107 emit layerNameChanged(); |
104 } | 108 } |
105 | 109 |
106 PlayParameters * | 110 std::shared_ptr<PlayParameters> |
107 Layer::getPlayParameters() | 111 Layer::getPlayParameters() |
108 { | 112 { |
109 // cerr << "Layer (" << this << ", " << objectName() << ")::getPlayParameters: model is "<< getModel() << endl; | 113 return PlayParameterRepository::getInstance()->getPlayParameters |
110 const Model *model = getModel(); | 114 (getModel().untyped); |
111 if (model) { | |
112 return PlayParameterRepository::getInstance()->getPlayParameters(model); | |
113 } | |
114 return nullptr; | |
115 } | 115 } |
116 | 116 |
117 void | 117 void |
118 Layer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) | 118 Layer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) |
119 { | 119 { |
141 bool | 141 bool |
142 Layer::getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const | 142 Layer::getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const |
143 { | 143 { |
144 if (!hasTimeXAxis()) return false; | 144 if (!hasTimeXAxis()) return false; |
145 | 145 |
146 const Model *m = getModel(); | 146 auto model = ModelById::get(getModel()); |
147 if (!m) return false; | 147 if (!model) return false; |
148 | 148 |
149 value = double(v->getFrameForX(x)) / m->getSampleRate(); | 149 value = double(v->getFrameForX(x)) / model->getSampleRate(); |
150 unit = "s"; | 150 unit = "s"; |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 bool | 154 bool |
166 } | 166 } |
167 | 167 |
168 sv_frame_t | 168 sv_frame_t |
169 Layer::alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const | 169 Layer::alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const |
170 { | 170 { |
171 const Model *m = getModel(); | 171 auto model = ModelById::get(getModel()); |
172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : nullptr) << endl; | 172 if (model && !model->getAlignmentReference().isNone()) { |
173 if (m && m->getAlignmentReference()) { | 173 return model->alignToReference(frame); |
174 return m->alignToReference(frame); | |
175 } else { | 174 } else { |
176 return v->getView()->alignToReference(frame); | 175 return v->getView()->alignToReference(frame); |
177 } | 176 } |
178 } | 177 } |
179 | 178 |
180 sv_frame_t | 179 sv_frame_t |
181 Layer::alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const | 180 Layer::alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const |
182 { | 181 { |
183 const Model *m = getModel(); | 182 auto model = ModelById::get(getModel()); |
184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : nullptr) << endl; | 183 if (model && !model->getAlignmentReference().isNone()) { |
185 if (m && m->getAlignmentReference()) { | 184 return model->alignFromReference(frame); |
186 return m->alignFromReference(frame); | |
187 } else { | 185 } else { |
188 return v->getView()->alignFromReference(frame); | 186 return v->getView()->alignFromReference(frame); |
189 } | 187 } |
190 } | 188 } |
191 | 189 |
642 if (m_presentationName != "") { | 640 if (m_presentationName != "") { |
643 extraAttributes = QString("%1 presentationName=\"%2\"") | 641 extraAttributes = QString("%1 presentationName=\"%2\"") |
644 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); | 642 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); |
645 } | 643 } |
646 | 644 |
645 int modelExportId = -1; | |
646 auto model = ModelById::get(getModel()); | |
647 if (model) modelExportId = model->getExportId(); | |
648 | |
647 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5") | 649 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5") |
648 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName | 650 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName |
649 (LayerFactory::getInstance()->getLayerType(this)))) | 651 (LayerFactory::getInstance()->getLayerType(this)))) |
650 .arg(getExportId()) | 652 .arg(getExportId()) |
651 .arg(encodeEntities(objectName())) | 653 .arg(encodeEntities(objectName())) |
652 .arg(getModel() ? getModel()->getExportId() : -1) | 654 .arg(modelExportId) |
653 .arg(extraAttributes); | 655 .arg(extraAttributes); |
654 | 656 |
655 if (m_measureRects.empty()) { | 657 if (m_measureRects.empty()) { |
656 stream << QString("/>\n"); | 658 stream << QString("/>\n"); |
657 return; | 659 return; |
675 | 677 |
676 if (m_presentationName != "") { | 678 if (m_presentationName != "") { |
677 extraAttributes = QString("%1 presentationName=\"%2\"") | 679 extraAttributes = QString("%1 presentationName=\"%2\"") |
678 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); | 680 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); |
679 } | 681 } |
682 | |
683 int modelExportId = -1; | |
684 auto model = ModelById::get(getModel()); | |
685 if (model) modelExportId = model->getExportId(); | |
680 | 686 |
681 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") | 687 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") |
682 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName | 688 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName |
683 (LayerFactory::getInstance()->getLayerType(this)))) | 689 (LayerFactory::getInstance()->getLayerType(this)))) |
684 .arg(getExportId()) | 690 .arg(getExportId()) |
685 .arg(encodeEntities(objectName())) | 691 .arg(encodeEntities(objectName())) |
686 .arg(getModel() ? getModel()->getExportId() : -1) | 692 .arg(modelExportId) |
687 .arg(extraAttributes); | 693 .arg(extraAttributes); |
688 } | 694 } |
689 | 695 |