Mercurial > hg > svgui
comparison layer/LayerFactory.cpp @ 374:64e84e5efb76 spectrogram-cache-rejig
* Merge from trunk
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 11:59:42 +0000 |
parents | 29fcf125f98b |
children |
comparison
equal
deleted
inserted
replaced
332:6440e280122e | 374:64e84e5efb76 |
---|---|
25 #include "ImageLayer.h" | 25 #include "ImageLayer.h" |
26 #include "Colour3DPlotLayer.h" | 26 #include "Colour3DPlotLayer.h" |
27 #include "SpectrumLayer.h" | 27 #include "SpectrumLayer.h" |
28 #include "SliceLayer.h" | 28 #include "SliceLayer.h" |
29 #include "SliceableLayer.h" | 29 #include "SliceableLayer.h" |
30 | |
31 #include "base/Clipboard.h" | |
30 | 32 |
31 #include "data/model/RangeSummarisableTimeValueModel.h" | 33 #include "data/model/RangeSummarisableTimeValueModel.h" |
32 #include "data/model/DenseTimeValueModel.h" | 34 #include "data/model/DenseTimeValueModel.h" |
33 #include "data/model/SparseOneDimensionalModel.h" | 35 #include "data/model/SparseOneDimensionalModel.h" |
34 #include "data/model/SparseTimeValueModel.h" | 36 #include "data/model/SparseTimeValueModel.h" |
348 } | 350 } |
349 if (dynamic_cast<SpectrogramLayer *>(layer)) { | 351 if (dynamic_cast<SpectrogramLayer *>(layer)) { |
350 dynamic_cast<SpectrogramLayer *>(layer)->setChannel(channel); | 352 dynamic_cast<SpectrogramLayer *>(layer)->setChannel(channel); |
351 return; | 353 return; |
352 } | 354 } |
355 if (dynamic_cast<SpectrumLayer *>(layer)) { | |
356 dynamic_cast<SpectrumLayer *>(layer)->setChannel(channel); | |
357 return; | |
358 } | |
353 } | 359 } |
354 | 360 |
355 Layer * | 361 Layer * |
356 LayerFactory::createLayer(LayerType type) | 362 LayerFactory::createLayer(LayerType type) |
357 { | 363 { |
416 | 422 |
417 if (!layer) { | 423 if (!layer) { |
418 std::cerr << "LayerFactory::createLayer: Unknown layer type " | 424 std::cerr << "LayerFactory::createLayer: Unknown layer type " |
419 << type << std::endl; | 425 << type << std::endl; |
420 } else { | 426 } else { |
421 std::cerr << "LayerFactory::createLayer: Setting object name " | 427 // std::cerr << "LayerFactory::createLayer: Setting object name " |
422 << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl; | 428 // << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl; |
423 layer->setObjectName(getLayerPresentationName(type)); | 429 layer->setObjectName(getLayerPresentationName(type)); |
424 setLayerDefaultProperties(type, layer); | 430 setLayerDefaultProperties(type, layer); |
425 } | 431 } |
426 | 432 |
427 return layer; | 433 return layer; |
428 } | 434 } |
429 | 435 |
430 void | 436 void |
431 LayerFactory::setLayerDefaultProperties(LayerType type, Layer *layer) | 437 LayerFactory::setLayerDefaultProperties(LayerType type, Layer *layer) |
432 { | 438 { |
433 std::cerr << "LayerFactory::setLayerDefaultProperties: type " << type << " (name \"" << getLayerTypeName(type).toStdString() << "\"" << std::endl; | 439 // std::cerr << "LayerFactory::setLayerDefaultProperties: type " << type << " (name \"" << getLayerTypeName(type).toStdString() << "\")" << std::endl; |
434 | 440 |
435 QSettings settings; | 441 QSettings settings; |
436 settings.beginGroup("LayerDefaults"); | 442 settings.beginGroup("LayerDefaults"); |
437 QString defaults = settings.value(getLayerTypeName(type), "").toString(); | 443 QString defaults = settings.value(getLayerTypeName(type), "").toString(); |
438 if (defaults == "") return; | 444 if (defaults == "") return; |
439 | 445 |
440 std::cerr << "defaults=\"" << defaults.toStdString() << "\"" << std::endl; | 446 // std::cerr << "defaults=\"" << defaults.toStdString() << "\"" << std::endl; |
441 | 447 |
442 QString xml = layer->toXmlString(); | 448 QString xml = layer->toXmlString(); |
443 QDomDocument docOld, docNew; | 449 QDomDocument docOld, docNew; |
444 | 450 |
445 if (docOld.setContent(xml, false) && | 451 if (docOld.setContent(xml, false) && |
451 QDomNamedNodeMap attrNodes = layerElt.attributes(); | 457 QDomNamedNodeMap attrNodes = layerElt.attributes(); |
452 | 458 |
453 for (unsigned int i = 0; i < attrNodes.length(); ++i) { | 459 for (unsigned int i = 0; i < attrNodes.length(); ++i) { |
454 QDomAttr attr = attrNodes.item(i).toAttr(); | 460 QDomAttr attr = attrNodes.item(i).toAttr(); |
455 if (attr.isNull()) continue; | 461 if (attr.isNull()) continue; |
456 std::cerr << "append \"" << attr.name().toStdString() | 462 // std::cerr << "append \"" << attr.name().toStdString() |
457 << "\" -> \"" << attr.value().toStdString() << "\"" | 463 // << "\" -> \"" << attr.value().toStdString() << "\"" |
458 << std::endl; | 464 // << std::endl; |
459 attrs.append(attr.name(), "", "", attr.value()); | 465 attrs.append(attr.name(), "", "", attr.value()); |
460 } | 466 } |
461 | 467 |
462 layerElt = docOld.firstChildElement("layer"); | 468 layerElt = docOld.firstChildElement("layer"); |
463 attrNodes = layerElt.attributes(); | 469 attrNodes = layerElt.attributes(); |
464 for (unsigned int i = 0; i < attrNodes.length(); ++i) { | 470 for (unsigned int i = 0; i < attrNodes.length(); ++i) { |
465 QDomAttr attr = attrNodes.item(i).toAttr(); | 471 QDomAttr attr = attrNodes.item(i).toAttr(); |
466 if (attr.isNull()) continue; | 472 if (attr.isNull()) continue; |
467 if (attrs.value(attr.name()) == "") { | 473 if (attrs.value(attr.name()) == "") { |
468 std::cerr << "append \"" << attr.name().toStdString() | 474 // std::cerr << "append \"" << attr.name().toStdString() |
469 << "\" -> \"" << attr.value().toStdString() << "\"" | 475 // << "\" -> \"" << attr.value().toStdString() << "\"" |
470 << std::endl; | 476 // << std::endl; |
471 attrs.append(attr.name(), "", "", attr.value()); | 477 attrs.append(attr.name(), "", "", attr.value()); |
472 } | 478 } |
473 } | 479 } |
474 | 480 |
475 layer->setProperties(attrs); | 481 layer->setProperties(attrs); |
476 } | 482 } |
477 | 483 |
478 settings.endGroup(); | 484 settings.endGroup(); |
479 } | 485 } |
480 | 486 |
487 LayerFactory::LayerType | |
488 LayerFactory::getLayerTypeForClipboardContents(const Clipboard &clip) | |
489 { | |
490 const Clipboard::PointList &contents = clip.getPoints(); | |
491 | |
492 bool haveFrame = false; | |
493 bool haveValue = false; | |
494 bool haveDuration = false; | |
495 | |
496 for (Clipboard::PointList::const_iterator i = contents.begin(); | |
497 i != contents.end(); ++i) { | |
498 if (i->haveFrame()) haveFrame = true; | |
499 if (i->haveValue()) haveValue = true; | |
500 if (i->haveDuration()) haveDuration = true; | |
501 } | |
502 | |
503 if (haveFrame && haveValue && haveDuration) return Notes; | |
504 if (haveFrame && haveValue) return TimeValues; | |
505 return TimeInstants; | |
506 } | |
507 |