svgui  1.9
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 _LAYER_FACTORY_H_
17 #define _LAYER_FACTORY_H_
18 
19 #include <QString>
20 #include <set>
21 
22 class Layer;
23 class Model;
24 class Clipboard;
25 
27 {
28 public:
29  enum LayerType {
30 
31  // Standard layers
45 
46  // Layers with different initial parameters
49 
50  // Not-a-layer-type
52  };
53 
54  static LayerFactory *getInstance();
55 
56  virtual ~LayerFactory();
57 
58  typedef std::set<LayerType> LayerTypeSet;
59  LayerTypeSet getValidLayerTypes(Model *model);
61 
62  LayerType getLayerType(const Layer *);
63 
65 
66  void setLayerDefaultProperties(LayerType type, Layer *layer);
67 
68  QString getLayerPresentationName(LayerType type);
69 
70  bool isLayerSliceable(const Layer *);
71 
72  void setModel(Layer *layer, Model *model);
73  Model *createEmptyModel(LayerType type, Model *baseModel);
74 
75  int getChannel(Layer *layer);
76  void setChannel(Layer *layer, int channel);
77 
78  QString getLayerIconName(LayerType);
79  QString getLayerTypeName(LayerType);
81 
83 
84 protected:
85  template <typename LayerClass, typename ModelClass>
86  bool trySetModel(Layer *layerBase, Model *modelBase) {
87  LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
88  if (!layer) return false;
89  ModelClass *model = dynamic_cast<ModelClass *>(modelBase);
90  if (!model) return false;
91  layer->setModel(model);
92  return true;
93  }
94 
96 };
97 
98 #endif
99 
static LayerFactory * getInstance()
QString getLayerIconName(LayerType)
The base class for visual representations of the data found in a Model.
Definition: Layer.h:52
bool isLayerSliceable(const Layer *)
bool trySetModel(Layer *layerBase, Model *modelBase)
Definition: LayerFactory.h:86
LayerType getLayerTypeForName(QString)
LayerTypeSet getValidLayerTypes(Model *model)
Model * createEmptyModel(LayerType type, Model *baseModel)
LayerTypeSet getValidEmptyLayerTypes()
int getChannel(Layer *layer)
void setModel(Layer *layer, Model *model)
QString getLayerPresentationName(LayerType type)
static LayerFactory * m_instance
Definition: LayerFactory.h:95
void setChannel(Layer *layer, int channel)
Layer * createLayer(LayerType type)
std::set< LayerType > LayerTypeSet
Definition: LayerFactory.h:58
LayerType getLayerType(const Layer *)
LayerType getLayerTypeForClipboardContents(const Clipboard &)
QString getLayerTypeName(LayerType)
virtual ~LayerFactory()
void setLayerDefaultProperties(LayerType type, Layer *layer)