diff layer/LayerFactory.h @ 1486:ac0a8addabcf

Merge from branch by-id
author Chris Cannam
date Wed, 17 Jul 2019 14:25:16 +0100
parents b43ff1abdc02
children 0fa155b84bac
line wrap: on
line diff
--- a/layer/LayerFactory.h	Thu Jun 13 15:35:01 2019 +0100
+++ b/layer/LayerFactory.h	Wed Jul 17 14:25:16 2019 +0100
@@ -19,8 +19,9 @@
 #include <QString>
 #include <set>
 
+#include "data/model/Model.h"
+
 class Layer;
-class Model;
 class Clipboard;
 
 class LayerFactory
@@ -56,7 +57,7 @@
     virtual ~LayerFactory();
 
     typedef std::set<LayerType> LayerTypeSet;
-    LayerTypeSet getValidLayerTypes(Model *model);
+    LayerTypeSet getValidLayerTypes(ModelId modelId);
 
     /**
      * Return the set of layer types that an end user should be
@@ -86,8 +87,8 @@
 
     bool isLayerSliceable(const Layer *);
 
-    void setModel(Layer *layer, Model *model);
-    Model *createEmptyModel(LayerType type, Model *baseModel);
+    void setModel(Layer *layer, ModelId model);
+    std::shared_ptr<Model> createEmptyModel(LayerType type, ModelId baseModel);
 
     int getChannel(Layer *layer);
     void setChannel(Layer *layer, int channel);
@@ -100,12 +101,14 @@
 
 protected:
     template <typename LayerClass, typename ModelClass>
-    bool trySetModel(Layer *layerBase, Model *modelBase) {
+    bool trySetModel(Layer *layerBase, ModelId modelId) {
         LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
         if (!layer) return false;
-        ModelClass *model = dynamic_cast<ModelClass *>(modelBase);
-        if (!model) return false;
-        layer->setModel(model);
+        if (!modelId.isNone()) {
+            auto model = ModelById::getAs<ModelClass>(modelId);
+            if (!model) return false;
+        }
+        layer->setModel(modelId);
         return true;
     }