comparison layer/LayerFactory.h @ 1471:f2525e6cbdf1 by-id

More layer updates
author Chris Cannam
date Mon, 01 Jul 2019 14:17:13 +0100
parents 9e846af73f3e
children b43ff1abdc02
comparison
equal deleted inserted replaced
1470:696e569ff21b 1471:f2525e6cbdf1
17 #define SV_LAYER_FACTORY_H 17 #define SV_LAYER_FACTORY_H
18 18
19 #include <QString> 19 #include <QString>
20 #include <set> 20 #include <set>
21 21
22 #include "data/model/Model.h"
23
22 class Layer; 24 class Layer;
23 class Model;
24 class Clipboard; 25 class Clipboard;
25 26
26 class LayerFactory 27 class LayerFactory
27 { 28 {
28 public: 29 public:
54 static LayerFactory *getInstance(); 55 static LayerFactory *getInstance();
55 56
56 virtual ~LayerFactory(); 57 virtual ~LayerFactory();
57 58
58 typedef std::set<LayerType> LayerTypeSet; 59 typedef std::set<LayerType> LayerTypeSet;
59 LayerTypeSet getValidLayerTypes(Model *model); 60 LayerTypeSet getValidLayerTypes(ModelId modelId);
60 61
61 /** 62 /**
62 * Return the set of layer types that an end user should be 63 * Return the set of layer types that an end user should be
63 * allowed to create, empty, for subsequent editing. 64 * allowed to create, empty, for subsequent editing.
64 */ 65 */
84 85
85 QString getLayerPresentationName(LayerType type); 86 QString getLayerPresentationName(LayerType type);
86 87
87 bool isLayerSliceable(const Layer *); 88 bool isLayerSliceable(const Layer *);
88 89
89 void setModel(Layer *layer, Model *model); 90 void setModel(Layer *layer, ModelId model);
90 Model *createEmptyModel(LayerType type, Model *baseModel); 91 std::shared_ptr<Model> createEmptyModel(LayerType type, ModelId baseModel);
91 92
92 int getChannel(Layer *layer); 93 int getChannel(Layer *layer);
93 void setChannel(Layer *layer, int channel); 94 void setChannel(Layer *layer, int channel);
94 95
95 QString getLayerIconName(LayerType); 96 QString getLayerIconName(LayerType);
98 99
99 LayerType getLayerTypeForClipboardContents(const Clipboard &); 100 LayerType getLayerTypeForClipboardContents(const Clipboard &);
100 101
101 protected: 102 protected:
102 template <typename LayerClass, typename ModelClass> 103 template <typename LayerClass, typename ModelClass>
103 bool trySetModel(Layer *layerBase, Model *modelBase) { 104 bool trySetModel(Layer *layerBase, ModelId modelId) {
104 LayerClass *layer = dynamic_cast<LayerClass *>(layerBase); 105 LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
105 if (!layer) return false; 106 if (!layer) return false;
106 ModelClass *model = dynamic_cast<ModelClass *>(modelBase); 107 auto model = ModelById::getAs<ModelClass>(modelId);
107 if (!model) return false; 108 if (!model) return false;
108 layer->setModel(model); 109 layer->setModel(modelId);
109 return true; 110 return true;
110 } 111 }
111 112
112 static LayerFactory *m_instance; 113 static LayerFactory *m_instance;
113 }; 114 };