comparison framework/Document.cpp @ 663:351b1302064e single-point

Make layer order in document also stable on file load/save
author Chris Cannam
date Tue, 02 Apr 2019 14:45:57 +0100
parents a2bf5e6c54ce
children 06db8f3ceb95
comparison
equal deleted inserted replaced
662:ffd213b292f9 663:351b1302064e
124 Layer *newLayer = LayerFactory::getInstance()->createLayer(type); 124 Layer *newLayer = LayerFactory::getInstance()->createLayer(type);
125 if (!newLayer) return nullptr; 125 if (!newLayer) return nullptr;
126 126
127 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName())); 127 newLayer->setObjectName(getUniqueLayerName(newLayer->objectName()));
128 128
129 m_layers.insert(newLayer); 129 m_layers.push_back(newLayer);
130 130
131 #ifdef DEBUG_DOCUMENT 131 #ifdef DEBUG_DOCUMENT
132 SVDEBUG << "Document::createLayer: Added layer of type " << type 132 SVDEBUG << "Document::createLayer: Added layer of type " << type
133 << ", now have " << m_layers.size() << " layers" << endl; 133 << ", now have " << m_layers.size() << " layers" << endl;
134 #endif 134 #endif
170 setModel(newLayer, model); 170 setModel(newLayer, model);
171 171
172 //!!! and all channels 172 //!!! and all channels
173 setChannel(newLayer, -1); 173 setChannel(newLayer, -1);
174 174
175 m_layers.insert(newLayer); 175 m_layers.push_back(newLayer);
176 176
177 #ifdef DEBUG_DOCUMENT 177 #ifdef DEBUG_DOCUMENT
178 SVDEBUG << "Document::createImportedLayer: Added layer of type " << type 178 SVDEBUG << "Document::createImportedLayer: Added layer of type " << type
179 << ", now have " << m_layers.size() << " layers" << endl; 179 << ", now have " << m_layers.size() << " layers" << endl;
180 #endif 180 #endif
437 } 437 }
438 SVDEBUG << endl; 438 SVDEBUG << endl;
439 SVDEBUG << "Old main model: " << oldMainModel << endl; 439 SVDEBUG << "Old main model: " << oldMainModel << endl;
440 #endif 440 #endif
441 441
442 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 442 for (Layer *layer: m_layers) {
443 443
444 Layer *layer = *i;
445 Model *model = layer->getModel(); 444 Model *model = layer->getModel();
446 445
447 #ifdef DEBUG_DOCUMENT 446 #ifdef DEBUG_DOCUMENT
448 SVDEBUG << "Document::setMainModel: inspecting model " 447 SVDEBUG << "Document::setMainModel: inspecting model "
449 << (model ? model->objectName(): "(null)") << " in layer " 448 << (model ? model->objectName(): "(null)") << " in layer "
878 } else { 877 } else {
879 return; 878 return;
880 } 879 }
881 } 880 }
882 881
883 if (m_layers.find(layer) == m_layers.end()) { 882 bool found = false;
883 for (auto itr = m_layers.begin(); itr != m_layers.end(); ++itr) {
884 if (*itr == layer) {
885 found = true;
886 m_layers.erase(itr);
887 break;
888 }
889 }
890 if (!found) {
884 SVDEBUG << "Document::deleteLayer: Layer " 891 SVDEBUG << "Document::deleteLayer: Layer "
885 << layer << " (" << typeid(layer).name() << 892 << layer << " (" << typeid(layer).name() <<
886 ") does not exist, or has already been deleted " 893 ") does not exist, or has already been deleted "
887 << "(this may not be as serious as it sounds)" << endl; 894 << "(this may not be as serious as it sounds)" << endl;
888 return; 895 return;
889 } 896 }
890
891 m_layers.erase(layer);
892 897
893 #ifdef DEBUG_DOCUMENT 898 #ifdef DEBUG_DOCUMENT
894 SVDEBUG << "Document::deleteLayer: Removing, now have " 899 SVDEBUG << "Document::deleteLayer: Removing, now have "
895 << m_layers.size() << " layers" << endl; 900 << m_layers.size() << " layers" << endl;
896 #endif 901 #endif
1028 (count > 1 ? QString("%1 <%2>").arg(candidate).arg(count) : 1033 (count > 1 ? QString("%1 <%2>").arg(candidate).arg(count) :
1029 candidate); 1034 candidate);
1030 1035
1031 bool duplicate = false; 1036 bool duplicate = false;
1032 1037
1033 for (LayerSet::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 1038 for (auto i = m_layers.begin(); i != m_layers.end(); ++i) {
1034 if ((*i)->objectName() == adjusted) { 1039 if ((*i)->objectName() == adjusted) {
1035 duplicate = true; 1040 duplicate = true;
1036 break; 1041 break;
1037 } 1042 }
1038 } 1043 }
1457 if (!alignment) continue; 1462 if (!alignment) continue;
1458 1463
1459 alignment->toXml(out, indent + " "); 1464 alignment->toXml(out, indent + " ");
1460 } 1465 }
1461 1466
1462 for (LayerSet::const_iterator i = m_layers.begin(); 1467 for (auto i = m_layers.begin(); i != m_layers.end(); ++i) {
1463 i != m_layers.end(); ++i) {
1464
1465 (*i)->toXml(out, indent + " "); 1468 (*i)->toXml(out, indent + " ");
1466 } 1469 }
1467 1470
1468 out << indent + "</data>\n"; 1471 out << indent + "</data>\n";
1469 } 1472 }