comparison layer/Layer.cpp @ 0:fc9323a41f5a

start base : Sonic Visualiser sv1-1.0rc1
author lbajardsilogic
date Fri, 11 May 2007 09:08:14 +0000
parents
children d8e6709e9075
comparison
equal deleted inserted replaced
-1:000000000000 0:fc9323a41f5a
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 and QMUL.
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 #include "Layer.h"
17 #include "view/View.h"
18 #include "data/model/Model.h"
19
20 #include <iostream>
21
22 #include <QMutexLocker>
23
24 #include "LayerFactory.h"
25 #include "base/PlayParameterRepository.h"
26
27 Layer::Layer()
28 {
29 }
30
31 Layer::~Layer()
32 {
33 // std::cerr << "Layer::~Layer(" << this << ")" << std::endl;
34 }
35
36 QString
37 Layer::getPropertyContainerIconName() const
38 {
39 return LayerFactory::getInstance()->getLayerIconName
40 (LayerFactory::getInstance()->getLayerType(this));
41 }
42
43 QString
44 Layer::getLayerPresentationName() const
45 {
46 // QString layerName = objectName();
47
48 LayerFactory *factory = LayerFactory::getInstance();
49 QString layerName = factory->getLayerPresentationName
50 (factory->getLayerType(this));
51
52 QString modelName;
53 if (getModel()) modelName = getModel()->objectName();
54
55 QString text;
56 if (modelName != "") {
57 text = QString("%1: %2").arg(modelName).arg(layerName);
58 } else {
59 text = layerName;
60 }
61
62 return text;
63 }
64
65 void
66 Layer::setObjectName(const QString &name)
67 {
68 QObject::setObjectName(name);
69 emit layerNameChanged();
70 }
71
72 QString
73 Layer::toXmlString(QString indent, QString extraAttributes) const
74 {
75 QString s;
76
77 s += indent;
78
79 s += QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n")
80 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
81 (LayerFactory::getInstance()->getLayerType(this))))
82 .arg(getObjectExportId(this))
83 .arg(encodeEntities(objectName()))
84 .arg(getObjectExportId(getModel()))
85 .arg(extraAttributes);
86
87 return s;
88 }
89
90 PlayParameters *
91 Layer::getPlayParameters()
92 {
93 // std::cerr << "Layer (" << this << ", " << objectName().toStdString() << ")::getPlayParameters: model is "<< getModel() << std::endl;
94 const Model *model = getModel();
95 if (model) {
96 return PlayParameterRepository::getInstance()->getPlayParameters(model);
97 }
98 return 0;
99 }
100
101 void
102 Layer::setLayerDormant(const View *v, bool dormant)
103 {
104 const void *vv = (const void *)v;
105 QMutexLocker locker(&m_dormancyMutex);
106 m_dormancy[vv] = dormant;
107 }
108
109 bool
110 Layer::isLayerDormant(const View *v) const
111 {
112 const void *vv = (const void *)v;
113 QMutexLocker locker(&m_dormancyMutex);
114 if (m_dormancy.find(vv) == m_dormancy.end()) return false;
115 return m_dormancy.find(vv)->second;
116 }
117
118 void
119 Layer::showLayer(View *view, bool show)
120 {
121 setLayerDormant(view, !show);
122 emit layerParametersChanged();
123 }
124