LayerFactory.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_LAYER_FACTORY_H
17 #define SV_LAYER_FACTORY_H
18 
19 #include <QString>
20 #include <set>
21 
22 #include "data/model/Model.h"
23 
24 class Layer;
25 class Clipboard;
26 
28 {
29 public:
30  enum LayerType {
31 
32  // Standard layers
47 
48  // Layers with different initial parameters
51 
52  // Not-a-layer-type
54  };
55 
56  static LayerFactory *getInstance();
57 
58  virtual ~LayerFactory();
59 
60  typedef std::set<LayerType> LayerTypeSet;
61  LayerTypeSet getValidLayerTypes(ModelId modelId);
62 
67  LayerTypeSet getValidEmptyLayerTypes();
68 
69  LayerType getLayerType(const Layer *);
70 
72 
79  void setLayerDefaultProperties(LayerType type, Layer *layer);
80 
85  void setLayerProperties(Layer *layer, QString xmlString);
86 
87  QString getLayerPresentationName(LayerType type);
88 
89  bool isLayerSliceable(const Layer *);
90 
91  void setModel(Layer *layer, ModelId model);
92  std::shared_ptr<Model> createEmptyModel(LayerType type, ModelId baseModel);
93 
94  int getChannel(Layer *layer);
95  void setChannel(Layer *layer, int channel);
96 
97  QString getLayerIconName(LayerType);
98  QString getLayerTypeName(LayerType);
100 
101  LayerType getLayerTypeForClipboardContents(const Clipboard &);
102 
103 protected:
104  template <typename LayerClass, typename ModelClass>
105  bool trySetModel(Layer *layerBase, ModelId modelId) {
106  LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
107  if (!layer) return false;
108  if (!modelId.isNone()) {
109  auto model = ModelById::getAs<ModelClass>(modelId);
110  if (!model) return false;
111  }
112  layer->setModel(modelId);
113  return true;
114  }
115 
117 };
118 
119 #endif
120 
static LayerFactory * getInstance()
QString getLayerIconName(LayerType)
The base class for visual representations of the data found in a Model.
Definition: Layer.h:54
LayerTypeSet getValidLayerTypes(ModelId modelId)
bool isLayerSliceable(const Layer *)
LayerType getLayerTypeForName(QString)
void setModel(Layer *layer, ModelId model)
LayerTypeSet getValidEmptyLayerTypes()
Return the set of layer types that an end user should be allowed to create, empty, for subsequent editing.
int getChannel(Layer *layer)
QString getLayerPresentationName(LayerType type)
static LayerFactory * m_instance
Definition: LayerFactory.h:116
void setChannel(Layer *layer, int channel)
Layer * createLayer(LayerType type)
void setLayerProperties(Layer *layer, QString xmlString)
Set the properties of a layer, from the XML string provided.
std::set< LayerType > LayerTypeSet
Definition: LayerFactory.h:60
LayerType getLayerType(const Layer *)
LayerType getLayerTypeForClipboardContents(const Clipboard &)
QString getLayerTypeName(LayerType)
virtual ~LayerFactory()
bool trySetModel(Layer *layerBase, ModelId modelId)
Definition: LayerFactory.h:105
std::shared_ptr< Model > createEmptyModel(LayerType type, ModelId baseModel)
void setLayerDefaultProperties(LayerType type, Layer *layer)
Set the default properties of a layer, from the XML string contained in the LayerDefaults settings gr...