Mercurial > hg > svapp
comparison framework/Document.cpp @ 667:31ea416fea3c single-point
Ensure main model also gets aligned (as reference)
author | Chris Cannam |
---|---|
date | Fri, 26 Apr 2019 18:39:46 +0100 |
parents | 21673429dba5 |
children | 0960e27c3232 |
comparison
equal
deleted
inserted
replaced
666:21673429dba5 | 667:31ea416fea3c |
---|---|
577 } | 577 } |
578 | 578 |
579 if (m_autoAlignment) { | 579 if (m_autoAlignment) { |
580 SVDEBUG << "Document::setMainModel: auto-alignment is on, aligning model if possible" << endl; | 580 SVDEBUG << "Document::setMainModel: auto-alignment is on, aligning model if possible" << endl; |
581 alignModel(m_mainModel); | 581 alignModel(m_mainModel); |
582 } else { | |
583 SVDEBUG << "Document::setMainModel: auto-alignment is off" << endl; | |
582 } | 584 } |
583 | 585 |
584 emit mainModelChanged(m_mainModel); | 586 emit mainModelChanged(m_mainModel); |
585 | 587 |
586 delete oldMainModel; | 588 delete oldMainModel; |
1099 } | 1101 } |
1100 | 1102 |
1101 void | 1103 void |
1102 Document::alignModel(Model *model) | 1104 Document::alignModel(Model *model) |
1103 { | 1105 { |
1104 SVDEBUG << "Document::alignModel(" << model << ")" << endl; | 1106 SVDEBUG << "Document::alignModel(" << model << ") (main model is " << m_mainModel << ")" << endl; |
1105 | 1107 |
1106 if (!m_mainModel) { | 1108 if (!m_mainModel) { |
1107 SVDEBUG << "(no main model to align to)" << endl; | 1109 SVDEBUG << "(no main model to align to)" << endl; |
1108 return; | 1110 return; |
1109 } | 1111 } |
1110 | 1112 |
1111 RangeSummarisableTimeValueModel *rm = | 1113 RangeSummarisableTimeValueModel *rm = |
1112 dynamic_cast<RangeSummarisableTimeValueModel *>(model); | 1114 dynamic_cast<RangeSummarisableTimeValueModel *>(model); |
1113 if (!rm) { | 1115 if (!rm) { |
1114 SVDEBUG << "(main model is not alignable-to)" << endl; | 1116 SVDEBUG << "(model " << rm << " is not an alignable sort)" << endl; |
1115 return; | 1117 return; |
1116 } | 1118 } |
1117 | 1119 |
1118 if (rm->getAlignmentReference() == m_mainModel) { | 1120 if (rm->getAlignmentReference() == m_mainModel) { |
1119 SVDEBUG << "(model " << rm << " is already aligned to main model " << m_mainModel << ")" << endl; | 1121 SVDEBUG << "(model " << rm << " is already aligned to main model " << m_mainModel << ")" << endl; |
1123 if (model == m_mainModel) { | 1125 if (model == m_mainModel) { |
1124 // The reference has an empty alignment to itself. This makes | 1126 // The reference has an empty alignment to itself. This makes |
1125 // it possible to distinguish between the reference and any | 1127 // it possible to distinguish between the reference and any |
1126 // unaligned model just by looking at the model itself, | 1128 // unaligned model just by looking at the model itself, |
1127 // without also knowing what the main model is | 1129 // without also knowing what the main model is |
1128 SVDEBUG << "Document::alignModel(" << model << "): is main model, setting appropriately" << endl; | 1130 SVDEBUG << "Document::alignModel(" << model << "): is main model, setting alignment to itself appropriately" << endl; |
1129 rm->setAlignment(new AlignmentModel(model, model, nullptr)); | 1131 rm->setAlignment(new AlignmentModel(model, model, nullptr)); |
1130 return; | 1132 return; |
1131 } | 1133 } |
1132 | 1134 |
1135 SVDEBUG << "Document::alignModel: aligning..." << endl; | |
1136 if (rm->getAlignmentReference() != nullptr) { | |
1137 SVDEBUG << "(Note: model " << rm << " is currently aligned to model " | |
1138 << rm->getAlignmentReference() << "; this will replace that)" | |
1139 << endl; | |
1140 } | |
1141 | |
1133 if (!m_align->alignModel(this, m_mainModel, rm)) { | 1142 if (!m_align->alignModel(this, m_mainModel, rm)) { |
1134 SVCERR << "Alignment failed: " << m_align->getError() << endl; | 1143 SVCERR << "Alignment failed: " << m_align->getError() << endl; |
1135 emit alignmentFailed(m_align->getError()); | 1144 emit alignmentFailed(m_align->getError()); |
1136 } | 1145 } |
1137 } | 1146 } |