annotate layer/LayerFactory.h @ 1455:9e846af73f3e single-point

Add setLayerProperties (from XML string)
author Chris Cannam
date Fri, 10 May 2019 09:22:20 +0100
parents 43a28a52f8ab
children f2525e6cbdf1
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@59 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@1311 16 #ifndef SV_LAYER_FACTORY_H
Chris@1311 17 #define SV_LAYER_FACTORY_H
Chris@0 18
Chris@0 19 #include <QString>
Chris@0 20 #include <set>
Chris@0 21
Chris@0 22 class Layer;
Chris@0 23 class Model;
Chris@360 24 class Clipboard;
Chris@0 25
Chris@0 26 class LayerFactory
Chris@0 27 {
Chris@0 28 public:
Chris@0 29 enum LayerType {
Chris@0 30
Chris@1266 31 // Standard layers
Chris@1266 32 Waveform,
Chris@1266 33 Spectrogram,
Chris@1266 34 TimeRuler,
Chris@1266 35 TimeInstants,
Chris@1266 36 TimeValues,
Chris@1266 37 Notes,
Chris@1266 38 FlexiNotes,
Chris@1266 39 Regions,
Chris@1266 40 Text,
Chris@303 41 Image,
Chris@1266 42 Colour3DPlot,
Chris@133 43 Spectrum,
Chris@193 44 Slice,
Chris@0 45
Chris@1266 46 // Layers with different initial parameters
Chris@1266 47 MelodicRangeSpectrogram,
Chris@1266 48 PeakFrequencySpectrogram,
Chris@0 49
Chris@1266 50 // Not-a-layer-type
Chris@1266 51 UnknownLayer = 255
Chris@0 52 };
Chris@0 53
Chris@125 54 static LayerFactory *getInstance();
Chris@0 55
Chris@0 56 virtual ~LayerFactory();
Chris@0 57
Chris@0 58 typedef std::set<LayerType> LayerTypeSet;
Chris@0 59 LayerTypeSet getValidLayerTypes(Model *model);
Chris@962 60
Chris@962 61 /**
Chris@962 62 * Return the set of layer types that an end user should be
Chris@962 63 * allowed to create, empty, for subsequent editing.
Chris@962 64 */
Chris@17 65 LayerTypeSet getValidEmptyLayerTypes();
Chris@0 66
Chris@6 67 LayerType getLayerType(const Layer *);
Chris@0 68
Chris@53 69 Layer *createLayer(LayerType type);
Chris@0 70
Chris@1455 71 /**
Chris@1455 72 * Set the default properties of a layer, from the XML string
Chris@1455 73 * contained in the LayerDefaults settings group for the given
Chris@1455 74 * layer type. Leave unchanged any properties not mentioned in the
Chris@1455 75 * settings.
Chris@1455 76 */
Chris@326 77 void setLayerDefaultProperties(LayerType type, Layer *layer);
Chris@326 78
Chris@1455 79 /**
Chris@1455 80 * Set the properties of a layer, from the XML string
Chris@1455 81 * provided. Leave unchanged any properties not mentioned.
Chris@1455 82 */
Chris@1455 83 void setLayerProperties(Layer *layer, QString xmlString);
Chris@1455 84
Chris@0 85 QString getLayerPresentationName(LayerType type);
Chris@0 86
Chris@193 87 bool isLayerSliceable(const Layer *);
Chris@193 88
Chris@0 89 void setModel(Layer *layer, Model *model);
Chris@17 90 Model *createEmptyModel(LayerType type, Model *baseModel);
Chris@0 91
Chris@53 92 int getChannel(Layer *layer);
Chris@53 93 void setChannel(Layer *layer, int channel);
Chris@53 94
Chris@17 95 QString getLayerIconName(LayerType);
Chris@6 96 QString getLayerTypeName(LayerType);
Chris@6 97 LayerType getLayerTypeForName(QString);
Chris@6 98
Chris@360 99 LayerType getLayerTypeForClipboardContents(const Clipboard &);
Chris@360 100
Chris@0 101 protected:
Chris@0 102 template <typename LayerClass, typename ModelClass>
Chris@0 103 bool trySetModel(Layer *layerBase, Model *modelBase) {
Chris@1266 104 LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
Chris@1266 105 if (!layer) return false;
Chris@1266 106 ModelClass *model = dynamic_cast<ModelClass *>(modelBase);
Chris@1266 107 if (!model) return false;
Chris@1266 108 layer->setModel(model);
Chris@1266 109 return true;
Chris@0 110 }
Chris@0 111
Chris@0 112 static LayerFactory *m_instance;
Chris@0 113 };
Chris@0 114
Chris@0 115 #endif
Chris@0 116