comparison 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
comparison
equal deleted inserted replaced
1468:de41a11cabc2 1486:ac0a8addabcf
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 if (!modelId.isNone()) {
107 if (!model) return false; 108 auto model = ModelById::getAs<ModelClass>(modelId);
108 layer->setModel(model); 109 if (!model) return false;
110 }
111 layer->setModel(modelId);
109 return true; 112 return true;
110 } 113 }
111 114
112 static LayerFactory *m_instance; 115 static LayerFactory *m_instance;
113 }; 116 };