annotate layer/LayerFactory.h @ 1537:4f8c72adbf43

Clarify naming of some view-related methods. Rename LayerGeometryProvider::getValueExtents to getVisibleExtentsForUnit, and View::getTextLabelHeight to getTextLabelYCoord. Add View::getVisibleExtentsForAnyUnit to be used to determine which unit to adopt in a new e.g. box layer.
author Chris Cannam
date Tue, 15 Oct 2019 11:40:56 +0100
parents 2e94c268f7a0
children
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@1471 22 #include "data/model/Model.h"
Chris@1471 23
Chris@0 24 class Layer;
Chris@360 25 class Clipboard;
Chris@0 26
Chris@0 27 class LayerFactory
Chris@0 28 {
Chris@0 29 public:
Chris@0 30 enum LayerType {
Chris@0 31
Chris@1266 32 // Standard layers
Chris@1266 33 Waveform,
Chris@1266 34 Spectrogram,
Chris@1266 35 TimeRuler,
Chris@1266 36 TimeInstants,
Chris@1266 37 TimeValues,
Chris@1266 38 Notes,
Chris@1266 39 FlexiNotes,
Chris@1266 40 Regions,
Chris@1518 41 Boxes,
Chris@1266 42 Text,
Chris@303 43 Image,
Chris@1266 44 Colour3DPlot,
Chris@133 45 Spectrum,
Chris@193 46 Slice,
Chris@0 47
Chris@1266 48 // Layers with different initial parameters
Chris@1266 49 MelodicRangeSpectrogram,
Chris@1266 50 PeakFrequencySpectrogram,
Chris@0 51
Chris@1266 52 // Not-a-layer-type
Chris@1266 53 UnknownLayer = 255
Chris@0 54 };
Chris@0 55
Chris@125 56 static LayerFactory *getInstance();
Chris@0 57
Chris@0 58 virtual ~LayerFactory();
Chris@0 59
Chris@0 60 typedef std::set<LayerType> LayerTypeSet;
Chris@1471 61 LayerTypeSet getValidLayerTypes(ModelId modelId);
Chris@962 62
Chris@962 63 /**
Chris@962 64 * Return the set of layer types that an end user should be
Chris@962 65 * allowed to create, empty, for subsequent editing.
Chris@962 66 */
Chris@17 67 LayerTypeSet getValidEmptyLayerTypes();
Chris@0 68
Chris@6 69 LayerType getLayerType(const Layer *);
Chris@0 70
Chris@53 71 Layer *createLayer(LayerType type);
Chris@0 72
Chris@1455 73 /**
Chris@1455 74 * Set the default properties of a layer, from the XML string
Chris@1455 75 * contained in the LayerDefaults settings group for the given
Chris@1455 76 * layer type. Leave unchanged any properties not mentioned in the
Chris@1455 77 * settings.
Chris@1455 78 */
Chris@326 79 void setLayerDefaultProperties(LayerType type, Layer *layer);
Chris@326 80
Chris@1455 81 /**
Chris@1455 82 * Set the properties of a layer, from the XML string
Chris@1455 83 * provided. Leave unchanged any properties not mentioned.
Chris@1455 84 */
Chris@1455 85 void setLayerProperties(Layer *layer, QString xmlString);
Chris@1455 86
Chris@0 87 QString getLayerPresentationName(LayerType type);
Chris@0 88
Chris@193 89 bool isLayerSliceable(const Layer *);
Chris@193 90
Chris@1471 91 void setModel(Layer *layer, ModelId model);
Chris@1471 92 std::shared_ptr<Model> createEmptyModel(LayerType type, ModelId baseModel);
Chris@0 93
Chris@53 94 int getChannel(Layer *layer);
Chris@53 95 void setChannel(Layer *layer, int channel);
Chris@53 96
Chris@17 97 QString getLayerIconName(LayerType);
Chris@6 98 QString getLayerTypeName(LayerType);
Chris@6 99 LayerType getLayerTypeForName(QString);
Chris@6 100
Chris@360 101 LayerType getLayerTypeForClipboardContents(const Clipboard &);
Chris@360 102
Chris@0 103 protected:
Chris@0 104 template <typename LayerClass, typename ModelClass>
Chris@1471 105 bool trySetModel(Layer *layerBase, ModelId modelId) {
Chris@1266 106 LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
Chris@1266 107 if (!layer) return false;
Chris@1484 108 if (!modelId.isNone()) {
Chris@1484 109 auto model = ModelById::getAs<ModelClass>(modelId);
Chris@1484 110 if (!model) return false;
Chris@1484 111 }
Chris@1471 112 layer->setModel(modelId);
Chris@1266 113 return true;
Chris@0 114 }
Chris@0 115
Chris@0 116 static LayerFactory *m_instance;
Chris@0 117 };
Chris@0 118
Chris@0 119 #endif
Chris@0 120