changeset 1477:0769eaacc6bf by-id

Further ModelId updates
author Chris Cannam
date Tue, 02 Jul 2019 19:05:45 +0100
parents c268fe2ad597
children d39db4673676
files widgets/LayerTree.cpp widgets/LayerTree.h
diffstat 2 files changed, 16 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/LayerTree.cpp	Tue Jul 02 15:38:37 2019 +0100
+++ b/widgets/LayerTree.cpp	Tue Jul 02 19:05:45 2019 +0100
@@ -77,7 +77,7 @@
 void
 ModelMetadataModel::rebuildModelSet()
 {
-    std::set<Model *> unfound = m_models;
+    std::set<ModelId> unfound = m_models;
 
     for (int i = 0; i < m_stack->getPaneCount(); ++i) {
 
@@ -89,26 +89,23 @@
             Layer *layer = pane->getLayer(j);
             if (!layer) continue;
 
-            Model *model = layer->getModel();
-            if (!model) continue;
+            ModelId modelId = layer->getModel();
+            if (modelId.isNone()) continue;
 
             if (m_waveModelsOnly) {
-                if (!dynamic_cast<WaveFileModel *>(model)) continue;
+                if (!ModelById::getAs<WaveFileModel>(modelId)) continue;
             }
 
-            if (m_models.find(model) == m_models.end()) {
-                connect(model, SIGNAL(aboutToBeDeleted()),
-                        this, SLOT(rebuildModelSet()));
-                m_models.insert(model);
+            if (m_models.find(modelId) == m_models.end()) {
+                m_models.insert(modelId);
             } else {
-                unfound.erase(model);
+                unfound.erase(modelId);
             }
         }
     }
 
-    for (std::set<Model *>::iterator i = unfound.begin();
-         i != unfound.end(); ++i) {
-        m_models.erase(*i);
+    for (ModelId m: unfound) {
+        m_models.erase(m);
     }
 
     SVDEBUG << "ModelMetadataModel::rebuildModelSet: " << m_models.size() << " models" << endl;
@@ -173,11 +170,12 @@
     int row = index.row(), col = index.column();
 
     //!!! not exactly the ideal use of a std::set
-    std::set<Model *>::iterator itr = m_models.begin();
+    std::set<ModelId>::iterator itr = m_models.begin();
     for (int i = 0; i < row && itr != m_models.end(); ++i, ++itr);
     if (itr == m_models.end()) return QVariant();
 
-    Model *model = *itr;
+    auto model = ModelById::get(*itr);
+    if (!model) return QVariant();
 
     if (role != Qt::DisplayRole) {
         if (m_waveModelsOnly && col == m_modelNameColumn &&
@@ -444,7 +442,7 @@
                     return QVariant(Qt::AlignHCenter);
                 }
             } else if (col == m_modelNameColumn) {
-                Model *model = layer->getModel();
+                auto model = ModelById::get(layer->getModel());
                 if (model && role == Qt::DisplayRole) {
                     return QVariant(model->objectName());
                 }
--- a/widgets/LayerTree.h	Tue Jul 02 15:38:37 2019 +0100
+++ b/widgets/LayerTree.h	Tue Jul 02 19:05:45 2019 +0100
@@ -19,6 +19,8 @@
 
 #include <QAbstractItemModel>
 
+#include "data/model/Model.h"
+
 #include <set>
 
 class PaneStack;
@@ -26,7 +28,6 @@
 class Pane;
 class Layer;
 class PropertyContainer;
-class Model;
 
 class ModelMetadataModel : public QAbstractItemModel
 {
@@ -73,7 +74,7 @@
     int m_modelSourceColumn;
     int m_columnCount;
 
-    std::set<Model *> m_models;
+    std::set<ModelId> m_models;
 };
 
 class LayerTreeModel : public QAbstractItemModel