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@0
|
16 #include "LayerFactory.h"
|
Chris@0
|
17
|
Chris@0
|
18 #include "WaveformLayer.h"
|
Chris@0
|
19 #include "SpectrogramLayer.h"
|
Chris@0
|
20 #include "TimeRulerLayer.h"
|
Chris@0
|
21 #include "TimeInstantLayer.h"
|
Chris@0
|
22 #include "TimeValueLayer.h"
|
Chris@30
|
23 #include "NoteLayer.h"
|
Chris@35
|
24 #include "TextLayer.h"
|
Chris@303
|
25 #include "ImageLayer.h"
|
Chris@0
|
26 #include "Colour3DPlotLayer.h"
|
Chris@133
|
27 #include "SpectrumLayer.h"
|
Chris@193
|
28 #include "SliceLayer.h"
|
Chris@193
|
29 #include "SliceableLayer.h"
|
Chris@0
|
30
|
Chris@360
|
31 #include "base/Clipboard.h"
|
Chris@360
|
32
|
Chris@128
|
33 #include "data/model/RangeSummarisableTimeValueModel.h"
|
Chris@128
|
34 #include "data/model/DenseTimeValueModel.h"
|
Chris@128
|
35 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@128
|
36 #include "data/model/SparseTimeValueModel.h"
|
Chris@128
|
37 #include "data/model/NoteModel.h"
|
Chris@128
|
38 #include "data/model/TextModel.h"
|
Chris@303
|
39 #include "data/model/ImageModel.h"
|
Chris@128
|
40 #include "data/model/DenseThreeDimensionalModel.h"
|
Chris@156
|
41 #include "data/model/WaveFileModel.h"
|
Chris@156
|
42 #include "data/model/WritableWaveFileModel.h"
|
Chris@0
|
43
|
Chris@326
|
44 #include <QDomDocument>
|
Chris@326
|
45 #include <QDomElement>
|
Chris@326
|
46 #include <QDomNamedNodeMap>
|
Chris@326
|
47 #include <QDomAttr>
|
Chris@326
|
48
|
Chris@326
|
49 #include <QSettings>
|
Chris@326
|
50
|
Chris@0
|
51 LayerFactory *
|
Chris@0
|
52 LayerFactory::m_instance = new LayerFactory;
|
Chris@0
|
53
|
Chris@0
|
54 LayerFactory *
|
Chris@125
|
55 LayerFactory::getInstance()
|
Chris@0
|
56 {
|
Chris@0
|
57 return m_instance;
|
Chris@0
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 LayerFactory::~LayerFactory()
|
Chris@0
|
61 {
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 QString
|
Chris@0
|
65 LayerFactory::getLayerPresentationName(LayerType type)
|
Chris@0
|
66 {
|
Chris@0
|
67 switch (type) {
|
Chris@0
|
68 case Waveform: return Layer::tr("Waveform");
|
Chris@0
|
69 case Spectrogram: return Layer::tr("Spectrogram");
|
Chris@0
|
70 case TimeRuler: return Layer::tr("Ruler");
|
Chris@0
|
71 case TimeInstants: return Layer::tr("Time Instants");
|
Chris@0
|
72 case TimeValues: return Layer::tr("Time Values");
|
Chris@30
|
73 case Notes: return Layer::tr("Notes");
|
Chris@35
|
74 case Text: return Layer::tr("Text");
|
Chris@303
|
75 case Image: return Layer::tr("Images");
|
Chris@0
|
76 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
|
Chris@133
|
77 case Spectrum: return Layer::tr("Spectrum");
|
Chris@193
|
78 case Slice: return Layer::tr("Time Slice");
|
Chris@0
|
79
|
Chris@0
|
80 case MelodicRangeSpectrogram:
|
Chris@0
|
81 // The user can change all the parameters of this after the
|
Chris@0
|
82 // fact -- there's nothing permanently melodic-range about it
|
Chris@0
|
83 // that should be encoded in its name
|
Chris@0
|
84 return Layer::tr("Spectrogram");
|
Chris@11
|
85
|
Chris@37
|
86 case PeakFrequencySpectrogram:
|
Chris@37
|
87 // likewise
|
Chris@37
|
88 return Layer::tr("Spectrogram");
|
Chris@37
|
89
|
Chris@11
|
90 default: break;
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@0
|
93 return Layer::tr("Layer");
|
Chris@0
|
94 }
|
Chris@0
|
95
|
Chris@193
|
96 bool
|
Chris@193
|
97 LayerFactory::isLayerSliceable(const Layer *layer)
|
Chris@193
|
98 {
|
Chris@193
|
99 if (dynamic_cast<const SliceableLayer *>(layer)) {
|
Chris@193
|
100 if (dynamic_cast<const SpectrogramLayer *>(layer)) {
|
Chris@193
|
101
|
Chris@193
|
102 //!!! We can create slices of spectrograms, but there's a
|
Chris@193
|
103 // problem managing the models. The source model for the
|
Chris@193
|
104 // slice layer has to be one of the spectrogram's FFT
|
Chris@193
|
105 // models -- that's fine, except that we can't store &
|
Chris@193
|
106 // recall the slice layer with a reference to that model
|
Chris@193
|
107 // because the model is internal to the spectrogram layer
|
Chris@193
|
108 // and the document has no record of it. We would need
|
Chris@193
|
109 // some other way of managing models that are used in this
|
Chris@193
|
110 // way. For the moment we just don't allow slices of
|
Chris@193
|
111 // spectrograms -- and provide a spectrum layer for this
|
Chris@193
|
112 // instead.
|
Chris@193
|
113 //
|
Chris@193
|
114 // This business needs a bit more thought -- either come
|
Chris@193
|
115 // up with a sensible way to deal with that stuff, or
|
Chris@193
|
116 // simplify the existing slice layer logic so that it
|
Chris@193
|
117 // doesn't have to deal with models disappearing on it at
|
Chris@193
|
118 // all (and use the normal Document setModel mechanism to
|
Chris@193
|
119 // set its sliceable model instead of the fancy pants
|
Chris@193
|
120 // nonsense it's doing at the moment).
|
Chris@193
|
121
|
Chris@193
|
122 return false;
|
Chris@193
|
123 }
|
Chris@193
|
124 return true;
|
Chris@193
|
125 }
|
Chris@193
|
126 return false;
|
Chris@193
|
127 }
|
Chris@193
|
128
|
Chris@0
|
129 LayerFactory::LayerTypeSet
|
Chris@0
|
130 LayerFactory::getValidLayerTypes(Model *model)
|
Chris@0
|
131 {
|
Chris@0
|
132 LayerTypeSet types;
|
Chris@0
|
133
|
Chris@0
|
134 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) {
|
Chris@0
|
135 types.insert(Colour3DPlot);
|
Chris@193
|
136 types.insert(Slice);
|
Chris@193
|
137 }
|
Chris@193
|
138
|
Chris@193
|
139 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
|
Chris@193
|
140 types.insert(Waveform);
|
Chris@0
|
141 }
|
Chris@0
|
142
|
Chris@0
|
143 if (dynamic_cast<DenseTimeValueModel *>(model)) {
|
Chris@0
|
144 types.insert(Spectrogram);
|
Chris@0
|
145 types.insert(MelodicRangeSpectrogram);
|
Chris@37
|
146 types.insert(PeakFrequencySpectrogram);
|
Chris@0
|
147 }
|
Chris@0
|
148
|
Chris@0
|
149 if (dynamic_cast<SparseOneDimensionalModel *>(model)) {
|
Chris@0
|
150 types.insert(TimeInstants);
|
Chris@0
|
151 }
|
Chris@0
|
152
|
Chris@0
|
153 if (dynamic_cast<SparseTimeValueModel *>(model)) {
|
Chris@0
|
154 types.insert(TimeValues);
|
Chris@35
|
155
|
Chris@35
|
156 }
|
Chris@35
|
157 if (dynamic_cast<NoteModel *>(model)) {
|
Chris@35
|
158 types.insert(Notes);
|
Chris@0
|
159 }
|
Chris@0
|
160
|
Chris@35
|
161 if (dynamic_cast<TextModel *>(model)) {
|
Chris@35
|
162 types.insert(Text);
|
Chris@30
|
163 }
|
Chris@30
|
164
|
Chris@303
|
165 if (dynamic_cast<ImageModel *>(model)) {
|
Chris@303
|
166 types.insert(Image);
|
Chris@303
|
167 }
|
Chris@303
|
168
|
Chris@133
|
169 if (dynamic_cast<DenseTimeValueModel *>(model)) {
|
Chris@133
|
170 types.insert(Spectrum);
|
Chris@133
|
171 }
|
Chris@133
|
172
|
Chris@0
|
173 // We don't count TimeRuler here as it doesn't actually display
|
Chris@0
|
174 // the data, although it can be backed by any model
|
Chris@0
|
175
|
Chris@0
|
176 return types;
|
Chris@0
|
177 }
|
Chris@0
|
178
|
Chris@17
|
179 LayerFactory::LayerTypeSet
|
Chris@17
|
180 LayerFactory::getValidEmptyLayerTypes()
|
Chris@17
|
181 {
|
Chris@17
|
182 LayerTypeSet types;
|
Chris@17
|
183 types.insert(TimeInstants);
|
Chris@17
|
184 types.insert(TimeValues);
|
Chris@30
|
185 types.insert(Notes);
|
Chris@35
|
186 types.insert(Text);
|
Chris@303
|
187 types.insert(Image);
|
Chris@17
|
188 //!!! and in principle Colour3DPlot -- now that's a challenge
|
Chris@17
|
189 return types;
|
Chris@17
|
190 }
|
Chris@17
|
191
|
Chris@0
|
192 LayerFactory::LayerType
|
Chris@6
|
193 LayerFactory::getLayerType(const Layer *layer)
|
Chris@0
|
194 {
|
Chris@6
|
195 if (dynamic_cast<const WaveformLayer *>(layer)) return Waveform;
|
Chris@6
|
196 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram;
|
Chris@6
|
197 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
|
Chris@6
|
198 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
|
Chris@6
|
199 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
|
Chris@30
|
200 if (dynamic_cast<const NoteLayer *>(layer)) return Notes;
|
Chris@35
|
201 if (dynamic_cast<const TextLayer *>(layer)) return Text;
|
Chris@303
|
202 if (dynamic_cast<const ImageLayer *>(layer)) return Image;
|
Chris@6
|
203 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
|
Chris@133
|
204 if (dynamic_cast<const SpectrumLayer *>(layer)) return Spectrum;
|
Chris@193
|
205 if (dynamic_cast<const SliceLayer *>(layer)) return Slice;
|
Chris@6
|
206 return UnknownLayer;
|
Chris@6
|
207 }
|
Chris@6
|
208
|
Chris@6
|
209 QString
|
Chris@17
|
210 LayerFactory::getLayerIconName(LayerType type)
|
Chris@17
|
211 {
|
Chris@17
|
212 switch (type) {
|
Chris@17
|
213 case Waveform: return "waveform";
|
Chris@17
|
214 case Spectrogram: return "spectrogram";
|
Chris@17
|
215 case TimeRuler: return "timeruler";
|
Chris@17
|
216 case TimeInstants: return "instants";
|
Chris@17
|
217 case TimeValues: return "values";
|
Chris@30
|
218 case Notes: return "notes";
|
Chris@35
|
219 case Text: return "text";
|
Chris@303
|
220 case Image: return "image";
|
Chris@17
|
221 case Colour3DPlot: return "colour3d";
|
Chris@133
|
222 case Spectrum: return "spectrum";
|
Chris@193
|
223 case Slice: return "spectrum";
|
Chris@326
|
224 case MelodicRangeSpectrogram: return "spectrogram";
|
Chris@326
|
225 case PeakFrequencySpectrogram: return "spectrogram";
|
Chris@17
|
226 default: return "unknown";
|
Chris@17
|
227 }
|
Chris@17
|
228 }
|
Chris@17
|
229
|
Chris@17
|
230 QString
|
Chris@6
|
231 LayerFactory::getLayerTypeName(LayerType type)
|
Chris@6
|
232 {
|
Chris@6
|
233 switch (type) {
|
Chris@6
|
234 case Waveform: return "waveform";
|
Chris@6
|
235 case Spectrogram: return "spectrogram";
|
Chris@6
|
236 case TimeRuler: return "timeruler";
|
Chris@6
|
237 case TimeInstants: return "timeinstants";
|
Chris@6
|
238 case TimeValues: return "timevalues";
|
Chris@30
|
239 case Notes: return "notes";
|
Chris@35
|
240 case Text: return "text";
|
Chris@303
|
241 case Image: return "image";
|
Chris@6
|
242 case Colour3DPlot: return "colour3dplot";
|
Chris@133
|
243 case Spectrum: return "spectrum";
|
Chris@193
|
244 case Slice: return "slice";
|
Chris@326
|
245 case MelodicRangeSpectrogram: return "melodicrange";
|
Chris@326
|
246 case PeakFrequencySpectrogram: return "peakfrequency";
|
Chris@6
|
247 default: return "unknown";
|
Chris@6
|
248 }
|
Chris@6
|
249 }
|
Chris@6
|
250
|
Chris@6
|
251 LayerFactory::LayerType
|
Chris@6
|
252 LayerFactory::getLayerTypeForName(QString name)
|
Chris@6
|
253 {
|
Chris@6
|
254 if (name == "waveform") return Waveform;
|
Chris@6
|
255 if (name == "spectrogram") return Spectrogram;
|
Chris@6
|
256 if (name == "timeruler") return TimeRuler;
|
Chris@6
|
257 if (name == "timeinstants") return TimeInstants;
|
Chris@6
|
258 if (name == "timevalues") return TimeValues;
|
Chris@30
|
259 if (name == "notes") return Notes;
|
Chris@35
|
260 if (name == "text") return Text;
|
Chris@303
|
261 if (name == "image") return Image;
|
Chris@6
|
262 if (name == "colour3dplot") return Colour3DPlot;
|
Chris@133
|
263 if (name == "spectrum") return Spectrum;
|
Chris@193
|
264 if (name == "slice") return Slice;
|
Chris@0
|
265 return UnknownLayer;
|
Chris@0
|
266 }
|
Chris@0
|
267
|
Chris@0
|
268 void
|
Chris@0
|
269 LayerFactory::setModel(Layer *layer, Model *model)
|
Chris@0
|
270 {
|
Chris@156
|
271 // if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model))
|
Chris@156
|
272 // return;
|
Chris@156
|
273
|
Chris@156
|
274 if (trySetModel<WaveformLayer, WaveFileModel>(layer, model))
|
Chris@156
|
275 return;
|
Chris@156
|
276
|
Chris@156
|
277 if (trySetModel<WaveformLayer, WritableWaveFileModel>(layer, model))
|
Chris@0
|
278 return;
|
Chris@0
|
279
|
Chris@0
|
280 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
281 return;
|
Chris@0
|
282
|
Chris@0
|
283 if (trySetModel<TimeRulerLayer, Model>(layer, model))
|
Chris@0
|
284 return;
|
Chris@0
|
285
|
Chris@0
|
286 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model))
|
Chris@0
|
287 return;
|
Chris@0
|
288
|
Chris@0
|
289 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
|
Chris@0
|
290 return;
|
Chris@0
|
291
|
Chris@30
|
292 if (trySetModel<NoteLayer, NoteModel>(layer, model))
|
Chris@30
|
293 return;
|
Chris@30
|
294
|
Chris@35
|
295 if (trySetModel<TextLayer, TextModel>(layer, model))
|
Chris@35
|
296 return;
|
Chris@35
|
297
|
Chris@303
|
298 if (trySetModel<ImageLayer, ImageModel>(layer, model))
|
Chris@303
|
299 return;
|
Chris@303
|
300
|
Chris@0
|
301 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
|
Chris@0
|
302 return;
|
Chris@0
|
303
|
Chris@0
|
304 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
|
Chris@0
|
305 return;
|
Chris@133
|
306
|
Chris@133
|
307 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model))
|
Chris@133
|
308 return;
|
Chris@193
|
309
|
Chris@193
|
310 // if (trySetModel<SliceLayer, DenseThreeDimensionalModel>(layer, model))
|
Chris@193
|
311 // return;
|
Chris@0
|
312 }
|
Chris@0
|
313
|
Chris@17
|
314 Model *
|
Chris@17
|
315 LayerFactory::createEmptyModel(LayerType layerType, Model *baseModel)
|
Chris@17
|
316 {
|
Chris@17
|
317 if (layerType == TimeInstants) {
|
Chris@17
|
318 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1);
|
Chris@17
|
319 } else if (layerType == TimeValues) {
|
Chris@245
|
320 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true);
|
Chris@30
|
321 } else if (layerType == Notes) {
|
Chris@245
|
322 return new NoteModel(baseModel->getSampleRate(), 1, true);
|
Chris@35
|
323 } else if (layerType == Text) {
|
Chris@35
|
324 return new TextModel(baseModel->getSampleRate(), 1, true);
|
Chris@303
|
325 } else if (layerType == Image) {
|
Chris@303
|
326 return new ImageModel(baseModel->getSampleRate(), 1, true);
|
Chris@17
|
327 } else {
|
Chris@17
|
328 return 0;
|
Chris@17
|
329 }
|
Chris@17
|
330 }
|
Chris@17
|
331
|
Chris@53
|
332 int
|
Chris@53
|
333 LayerFactory::getChannel(Layer *layer)
|
Chris@53
|
334 {
|
Chris@53
|
335 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@53
|
336 return dynamic_cast<WaveformLayer *>(layer)->getChannel();
|
Chris@53
|
337 }
|
Chris@53
|
338 if (dynamic_cast<SpectrogramLayer *>(layer)) {
|
Chris@53
|
339 return dynamic_cast<SpectrogramLayer *>(layer)->getChannel();
|
Chris@53
|
340 }
|
Chris@53
|
341 return -1;
|
Chris@53
|
342 }
|
Chris@53
|
343
|
Chris@53
|
344 void
|
Chris@53
|
345 LayerFactory::setChannel(Layer *layer, int channel)
|
Chris@53
|
346 {
|
Chris@53
|
347 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@53
|
348 dynamic_cast<WaveformLayer *>(layer)->setChannel(channel);
|
Chris@53
|
349 return;
|
Chris@53
|
350 }
|
Chris@53
|
351 if (dynamic_cast<SpectrogramLayer *>(layer)) {
|
Chris@53
|
352 dynamic_cast<SpectrogramLayer *>(layer)->setChannel(channel);
|
Chris@53
|
353 return;
|
Chris@53
|
354 }
|
Chris@349
|
355 if (dynamic_cast<SpectrumLayer *>(layer)) {
|
Chris@349
|
356 dynamic_cast<SpectrumLayer *>(layer)->setChannel(channel);
|
Chris@349
|
357 return;
|
Chris@349
|
358 }
|
Chris@53
|
359 }
|
Chris@53
|
360
|
Chris@0
|
361 Layer *
|
Chris@53
|
362 LayerFactory::createLayer(LayerType type)
|
Chris@0
|
363 {
|
Chris@0
|
364 Layer *layer = 0;
|
Chris@0
|
365
|
Chris@0
|
366 switch (type) {
|
Chris@0
|
367
|
Chris@0
|
368 case Waveform:
|
Chris@44
|
369 layer = new WaveformLayer;
|
Chris@0
|
370 break;
|
Chris@0
|
371
|
Chris@0
|
372 case Spectrogram:
|
Chris@44
|
373 layer = new SpectrogramLayer;
|
Chris@0
|
374 break;
|
Chris@0
|
375
|
Chris@0
|
376 case TimeRuler:
|
Chris@44
|
377 layer = new TimeRulerLayer;
|
Chris@0
|
378 break;
|
Chris@0
|
379
|
Chris@0
|
380 case TimeInstants:
|
Chris@44
|
381 layer = new TimeInstantLayer;
|
Chris@0
|
382 break;
|
Chris@0
|
383
|
Chris@0
|
384 case TimeValues:
|
Chris@44
|
385 layer = new TimeValueLayer;
|
Chris@0
|
386 break;
|
Chris@0
|
387
|
Chris@30
|
388 case Notes:
|
Chris@44
|
389 layer = new NoteLayer;
|
Chris@30
|
390 break;
|
Chris@30
|
391
|
Chris@35
|
392 case Text:
|
Chris@44
|
393 layer = new TextLayer;
|
Chris@35
|
394 break;
|
Chris@35
|
395
|
Chris@303
|
396 case Image:
|
Chris@303
|
397 layer = new ImageLayer;
|
Chris@303
|
398 break;
|
Chris@303
|
399
|
Chris@0
|
400 case Colour3DPlot:
|
Chris@44
|
401 layer = new Colour3DPlotLayer;
|
Chris@0
|
402 break;
|
Chris@0
|
403
|
Chris@133
|
404 case Spectrum:
|
Chris@133
|
405 layer = new SpectrumLayer;
|
Chris@133
|
406 break;
|
Chris@133
|
407
|
Chris@193
|
408 case Slice:
|
Chris@193
|
409 layer = new SliceLayer;
|
Chris@193
|
410 break;
|
Chris@193
|
411
|
Chris@0
|
412 case MelodicRangeSpectrogram:
|
Chris@44
|
413 layer = new SpectrogramLayer(SpectrogramLayer::MelodicRange);
|
Chris@0
|
414 break;
|
Chris@11
|
415
|
Chris@37
|
416 case PeakFrequencySpectrogram:
|
Chris@44
|
417 layer = new SpectrogramLayer(SpectrogramLayer::MelodicPeaks);
|
Chris@37
|
418 break;
|
Chris@37
|
419
|
Chris@11
|
420 default: break;
|
Chris@0
|
421 }
|
Chris@0
|
422
|
Chris@0
|
423 if (!layer) {
|
Chris@0
|
424 std::cerr << "LayerFactory::createLayer: Unknown layer type "
|
Chris@0
|
425 << type << std::endl;
|
Chris@0
|
426 } else {
|
Chris@336
|
427 // std::cerr << "LayerFactory::createLayer: Setting object name "
|
Chris@336
|
428 // << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl;
|
Chris@0
|
429 layer->setObjectName(getLayerPresentationName(type));
|
Chris@326
|
430 setLayerDefaultProperties(type, layer);
|
Chris@0
|
431 }
|
Chris@0
|
432
|
Chris@0
|
433 return layer;
|
Chris@0
|
434 }
|
Chris@0
|
435
|
Chris@326
|
436 void
|
Chris@326
|
437 LayerFactory::setLayerDefaultProperties(LayerType type, Layer *layer)
|
Chris@326
|
438 {
|
Chris@336
|
439 // std::cerr << "LayerFactory::setLayerDefaultProperties: type " << type << " (name \"" << getLayerTypeName(type).toStdString() << "\")" << std::endl;
|
Chris@327
|
440
|
Chris@326
|
441 QSettings settings;
|
Chris@326
|
442 settings.beginGroup("LayerDefaults");
|
Chris@326
|
443 QString defaults = settings.value(getLayerTypeName(type), "").toString();
|
Chris@326
|
444 if (defaults == "") return;
|
Chris@326
|
445
|
Chris@336
|
446 // std::cerr << "defaults=\"" << defaults.toStdString() << "\"" << std::endl;
|
Chris@327
|
447
|
Chris@326
|
448 QString xml = layer->toXmlString();
|
Chris@326
|
449 QDomDocument docOld, docNew;
|
Chris@326
|
450
|
Chris@326
|
451 if (docOld.setContent(xml, false) &&
|
Chris@326
|
452 docNew.setContent(defaults, false)) {
|
Chris@326
|
453
|
Chris@326
|
454 QXmlAttributes attrs;
|
Chris@326
|
455
|
Chris@326
|
456 QDomElement layerElt = docNew.firstChildElement("layer");
|
Chris@326
|
457 QDomNamedNodeMap attrNodes = layerElt.attributes();
|
Chris@326
|
458
|
Chris@326
|
459 for (unsigned int i = 0; i < attrNodes.length(); ++i) {
|
Chris@326
|
460 QDomAttr attr = attrNodes.item(i).toAttr();
|
Chris@326
|
461 if (attr.isNull()) continue;
|
Chris@336
|
462 // std::cerr << "append \"" << attr.name().toStdString()
|
Chris@336
|
463 // << "\" -> \"" << attr.value().toStdString() << "\""
|
Chris@336
|
464 // << std::endl;
|
Chris@326
|
465 attrs.append(attr.name(), "", "", attr.value());
|
Chris@326
|
466 }
|
Chris@326
|
467
|
Chris@326
|
468 layerElt = docOld.firstChildElement("layer");
|
Chris@326
|
469 attrNodes = layerElt.attributes();
|
Chris@326
|
470 for (unsigned int i = 0; i < attrNodes.length(); ++i) {
|
Chris@326
|
471 QDomAttr attr = attrNodes.item(i).toAttr();
|
Chris@326
|
472 if (attr.isNull()) continue;
|
Chris@326
|
473 if (attrs.value(attr.name()) == "") {
|
Chris@336
|
474 // std::cerr << "append \"" << attr.name().toStdString()
|
Chris@336
|
475 // << "\" -> \"" << attr.value().toStdString() << "\""
|
Chris@336
|
476 // << std::endl;
|
Chris@326
|
477 attrs.append(attr.name(), "", "", attr.value());
|
Chris@326
|
478 }
|
Chris@326
|
479 }
|
Chris@326
|
480
|
Chris@326
|
481 layer->setProperties(attrs);
|
Chris@326
|
482 }
|
Chris@326
|
483
|
Chris@326
|
484 settings.endGroup();
|
Chris@326
|
485 }
|
Chris@326
|
486
|
Chris@360
|
487 LayerFactory::LayerType
|
Chris@360
|
488 LayerFactory::getLayerTypeForClipboardContents(const Clipboard &clip)
|
Chris@360
|
489 {
|
Chris@360
|
490 const Clipboard::PointList &contents = clip.getPoints();
|
Chris@360
|
491
|
Chris@360
|
492 bool haveFrame = false;
|
Chris@360
|
493 bool haveValue = false;
|
Chris@360
|
494 bool haveDuration = false;
|
Chris@360
|
495
|
Chris@360
|
496 for (Clipboard::PointList::const_iterator i = contents.begin();
|
Chris@360
|
497 i != contents.end(); ++i) {
|
Chris@360
|
498 if (i->haveFrame()) haveFrame = true;
|
Chris@360
|
499 if (i->haveValue()) haveValue = true;
|
Chris@360
|
500 if (i->haveDuration()) haveDuration = true;
|
Chris@360
|
501 }
|
Chris@360
|
502
|
Chris@360
|
503 if (haveFrame && haveValue && haveDuration) return Notes;
|
Chris@360
|
504 if (haveFrame && haveValue) return TimeValues;
|
Chris@360
|
505 return TimeInstants;
|
Chris@360
|
506 }
|
Chris@360
|
507
|