comparison widgets/LayerTree.cpp @ 1477:0769eaacc6bf by-id

Further ModelId updates
author Chris Cannam
date Tue, 02 Jul 2019 19:05:45 +0100
parents c8a6fd3f9dff
children 232262e38051
comparison
equal deleted inserted replaced
1476:c268fe2ad597 1477:0769eaacc6bf
75 } 75 }
76 76
77 void 77 void
78 ModelMetadataModel::rebuildModelSet() 78 ModelMetadataModel::rebuildModelSet()
79 { 79 {
80 std::set<Model *> unfound = m_models; 80 std::set<ModelId> unfound = m_models;
81 81
82 for (int i = 0; i < m_stack->getPaneCount(); ++i) { 82 for (int i = 0; i < m_stack->getPaneCount(); ++i) {
83 83
84 Pane *pane = m_stack->getPane(i); 84 Pane *pane = m_stack->getPane(i);
85 if (!pane) continue; 85 if (!pane) continue;
87 for (int j = 0; j < pane->getLayerCount(); ++j) { 87 for (int j = 0; j < pane->getLayerCount(); ++j) {
88 88
89 Layer *layer = pane->getLayer(j); 89 Layer *layer = pane->getLayer(j);
90 if (!layer) continue; 90 if (!layer) continue;
91 91
92 Model *model = layer->getModel(); 92 ModelId modelId = layer->getModel();
93 if (!model) continue; 93 if (modelId.isNone()) continue;
94 94
95 if (m_waveModelsOnly) { 95 if (m_waveModelsOnly) {
96 if (!dynamic_cast<WaveFileModel *>(model)) continue; 96 if (!ModelById::getAs<WaveFileModel>(modelId)) continue;
97 } 97 }
98 98
99 if (m_models.find(model) == m_models.end()) { 99 if (m_models.find(modelId) == m_models.end()) {
100 connect(model, SIGNAL(aboutToBeDeleted()), 100 m_models.insert(modelId);
101 this, SLOT(rebuildModelSet()));
102 m_models.insert(model);
103 } else { 101 } else {
104 unfound.erase(model); 102 unfound.erase(modelId);
105 } 103 }
106 } 104 }
107 } 105 }
108 106
109 for (std::set<Model *>::iterator i = unfound.begin(); 107 for (ModelId m: unfound) {
110 i != unfound.end(); ++i) { 108 m_models.erase(m);
111 m_models.erase(*i);
112 } 109 }
113 110
114 SVDEBUG << "ModelMetadataModel::rebuildModelSet: " << m_models.size() << " models" << endl; 111 SVDEBUG << "ModelMetadataModel::rebuildModelSet: " << m_models.size() << " models" << endl;
115 } 112 }
116 113
171 168
172 // QObject *obj = static_cast<QObject *>(index.internalPointer()); 169 // QObject *obj = static_cast<QObject *>(index.internalPointer());
173 int row = index.row(), col = index.column(); 170 int row = index.row(), col = index.column();
174 171
175 //!!! not exactly the ideal use of a std::set 172 //!!! not exactly the ideal use of a std::set
176 std::set<Model *>::iterator itr = m_models.begin(); 173 std::set<ModelId>::iterator itr = m_models.begin();
177 for (int i = 0; i < row && itr != m_models.end(); ++i, ++itr); 174 for (int i = 0; i < row && itr != m_models.end(); ++i, ++itr);
178 if (itr == m_models.end()) return QVariant(); 175 if (itr == m_models.end()) return QVariant();
179 176
180 Model *model = *itr; 177 auto model = ModelById::get(*itr);
178 if (!model) return QVariant();
181 179
182 if (role != Qt::DisplayRole) { 180 if (role != Qt::DisplayRole) {
183 if (m_waveModelsOnly && col == m_modelNameColumn && 181 if (m_waveModelsOnly && col == m_modelNameColumn &&
184 role == Qt::DecorationRole) { 182 role == Qt::DecorationRole) {
185 // There is no meaningful icon for a model, in general -- 183 // There is no meaningful icon for a model, in general --
442 else return QVariant(); 440 else return QVariant();
443 } else if (role == Qt::TextAlignmentRole) { 441 } else if (role == Qt::TextAlignmentRole) {
444 return QVariant(Qt::AlignHCenter); 442 return QVariant(Qt::AlignHCenter);
445 } 443 }
446 } else if (col == m_modelNameColumn) { 444 } else if (col == m_modelNameColumn) {
447 Model *model = layer->getModel(); 445 auto model = ModelById::get(layer->getModel());
448 if (model && role == Qt::DisplayRole) { 446 if (model && role == Qt::DisplayRole) {
449 return QVariant(model->objectName()); 447 return QVariant(model->objectName());
450 } 448 }
451 } 449 }
452 } 450 }