Mercurial > hg > svgui
comparison layer/Layer.cpp @ 1469:11a150e65ee1 by-id
Some work on updating layers for ModelId bits
author | Chris Cannam |
---|---|
date | Thu, 27 Jun 2019 13:16:25 +0100 |
parents | 5554d5187494 |
children | 696e569ff21b |
comparison
equal
deleted
inserted
replaced
1468:de41a11cabc2 | 1469:11a150e65ee1 |
---|---|
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 if (!model) return; | |
53 | |
54 connect(model.get(), SIGNAL(modelChanged()), | |
52 this, SIGNAL(modelChanged())); | 55 this, SIGNAL(modelChanged())); |
53 | 56 |
54 connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), | 57 connect(model.get(), SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), |
55 this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); | 58 this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); |
56 | 59 |
57 connect(model, SIGNAL(completionChanged()), | 60 connect(model.get(), SIGNAL(completionChanged()), |
58 this, SIGNAL(modelCompletionChanged())); | 61 this, SIGNAL(modelCompletionChanged())); |
59 | 62 |
60 connect(model, SIGNAL(alignmentCompletionChanged()), | 63 connect(model.get(), SIGNAL(alignmentCompletionChanged()), |
61 this, SIGNAL(modelAlignmentCompletionChanged())); | 64 this, SIGNAL(modelAlignmentCompletionChanged())); |
62 } | 65 } |
63 | 66 |
64 QString | 67 QString |
65 Layer::getPropertyContainerIconName() const | 68 Layer::getPropertyContainerIconName() const |
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 { |
105 | 109 |
106 PlayParameters * | 110 PlayParameters * |
107 Layer::getPlayParameters() | 111 Layer::getPlayParameters() |
108 { | 112 { |
109 // cerr << "Layer (" << this << ", " << objectName() << ")::getPlayParameters: model is "<< getModel() << endl; | 113 // cerr << "Layer (" << this << ", " << objectName() << ")::getPlayParameters: model is "<< getModel() << endl; |
110 const Model *model = getModel(); | 114 auto model = ModelById::get(getModel()); |
111 if (model) { | 115 if (model) { |
112 return PlayParameterRepository::getInstance()->getPlayParameters(model); | 116 return PlayParameterRepository::getInstance()->getPlayParameters(model); |
113 } | 117 } |
114 return nullptr; | 118 return nullptr; |
115 } | 119 } |
141 bool | 145 bool |
142 Layer::getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const | 146 Layer::getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const |
143 { | 147 { |
144 if (!hasTimeXAxis()) return false; | 148 if (!hasTimeXAxis()) return false; |
145 | 149 |
146 const Model *m = getModel(); | 150 auto model = ModelById::get(getModel()); |
147 if (!m) return false; | 151 if (!model) return false; |
148 | 152 |
149 value = double(v->getFrameForX(x)) / m->getSampleRate(); | 153 value = double(v->getFrameForX(x)) / model->getSampleRate(); |
150 unit = "s"; | 154 unit = "s"; |
151 return true; | 155 return true; |
152 } | 156 } |
153 | 157 |
154 bool | 158 bool |
166 } | 170 } |
167 | 171 |
168 sv_frame_t | 172 sv_frame_t |
169 Layer::alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const | 173 Layer::alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const |
170 { | 174 { |
171 const Model *m = getModel(); | 175 auto model = ModelById::get(getModel()); |
172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : nullptr) << endl; | 176 if (model && !model->getAlignmentReference().isNone()) { |
173 if (m && m->getAlignmentReference()) { | 177 return model->alignToReference(frame); |
174 return m->alignToReference(frame); | |
175 } else { | 178 } else { |
176 return v->getView()->alignToReference(frame); | 179 return v->getView()->alignToReference(frame); |
177 } | 180 } |
178 } | 181 } |
179 | 182 |
180 sv_frame_t | 183 sv_frame_t |
181 Layer::alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const | 184 Layer::alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const |
182 { | 185 { |
183 const Model *m = getModel(); | 186 auto model = ModelById::get(getModel()); |
184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : nullptr) << endl; | 187 if (model && !model->getAlignmentReference().isNone()) { |
185 if (m && m->getAlignmentReference()) { | 188 return model->alignFromReference(frame); |
186 return m->alignFromReference(frame); | |
187 } else { | 189 } else { |
188 return v->getView()->alignFromReference(frame); | 190 return v->getView()->alignFromReference(frame); |
189 } | 191 } |
190 } | 192 } |
191 | 193 |
642 if (m_presentationName != "") { | 644 if (m_presentationName != "") { |
643 extraAttributes = QString("%1 presentationName=\"%2\"") | 645 extraAttributes = QString("%1 presentationName=\"%2\"") |
644 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); | 646 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); |
645 } | 647 } |
646 | 648 |
649 int modelExportId = -1; | |
650 auto model = ModelById::get(getModel()); | |
651 if (model) modelExportId = model->getExportId(); | |
652 | |
647 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5") | 653 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5") |
648 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName | 654 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName |
649 (LayerFactory::getInstance()->getLayerType(this)))) | 655 (LayerFactory::getInstance()->getLayerType(this)))) |
650 .arg(getExportId()) | 656 .arg(getExportId()) |
651 .arg(encodeEntities(objectName())) | 657 .arg(encodeEntities(objectName())) |
652 .arg(getModel() ? getModel()->getExportId() : -1) | 658 .arg(modelExportId) |
653 .arg(extraAttributes); | 659 .arg(extraAttributes); |
654 | 660 |
655 if (m_measureRects.empty()) { | 661 if (m_measureRects.empty()) { |
656 stream << QString("/>\n"); | 662 stream << QString("/>\n"); |
657 return; | 663 return; |
675 | 681 |
676 if (m_presentationName != "") { | 682 if (m_presentationName != "") { |
677 extraAttributes = QString("%1 presentationName=\"%2\"") | 683 extraAttributes = QString("%1 presentationName=\"%2\"") |
678 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); | 684 .arg(extraAttributes).arg(encodeEntities(m_presentationName)); |
679 } | 685 } |
686 | |
687 int modelExportId = -1; | |
688 auto model = ModelById::get(getModel()); | |
689 if (model) modelExportId = model->getExportId(); | |
680 | 690 |
681 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") | 691 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") |
682 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName | 692 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName |
683 (LayerFactory::getInstance()->getLayerType(this)))) | 693 (LayerFactory::getInstance()->getLayerType(this)))) |
684 .arg(getExportId()) | 694 .arg(getExportId()) |
685 .arg(encodeEntities(objectName())) | 695 .arg(encodeEntities(objectName())) |
686 .arg(getModel() ? getModel()->getExportId() : -1) | 696 .arg(modelExportId) |
687 .arg(extraAttributes); | 697 .arg(extraAttributes); |
688 } | 698 } |
689 | 699 |