comparison base/PropertyContainer.cpp @ 387:7aa1de571880

* juggle some files around in order to free audioio, base, and system libraries from dependency on QtGui
author Chris Cannam
date Wed, 12 Mar 2008 17:42:56 +0000
parents 516819f2b97b
children 57857a57a03a
comparison
equal deleted inserted replaced
386:e6d11871e4c9 387:7aa1de571880
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "PropertyContainer.h" 16 #include "PropertyContainer.h"
17 #include "CommandHistory.h"
18 #include "RangeMapper.h" 17 #include "RangeMapper.h"
19 #include "UnitDatabase.h" 18 #include "UnitDatabase.h"
20 #include "ColourDatabase.h"
21
22 #include <QColor>
23 19
24 #include <iostream> 20 #include <iostream>
25 21
26 PropertyContainer::PropertyList 22 PropertyContainer::PropertyList
27 PropertyContainer::getProperties() const 23 PropertyContainer::getProperties() const
58 } 54 }
59 55
60 QString 56 QString
61 PropertyContainer::getPropertyValueLabel(const PropertyName &name, int value) const 57 PropertyContainer::getPropertyValueLabel(const PropertyName &name, int value) const
62 { 58 {
63 if (getPropertyType(name) == ColourProperty) {
64 ColourDatabase *db = ColourDatabase::getInstance();
65 if (value >= 0 && size_t(value) < db->getColourCount()) {
66 return db->getColourName(value);
67 }
68 }
69
70 return QString(); 59 return QString();
71 } 60 }
72 61
73 RangeMapper * 62 RangeMapper *
74 PropertyContainer::getNewPropertyRangeMapper(const PropertyName &) const 63 PropertyContainer::getNewPropertyRangeMapper(const PropertyName &) const
80 PropertyContainer::setProperty(const PropertyName &name, int) 69 PropertyContainer::setProperty(const PropertyName &name, int)
81 { 70 {
82 std::cerr << "WARNING: PropertyContainer[" << getPropertyContainerName().toStdString() << "]::setProperty(" << name.toStdString() << "): no implementation in subclass!" << std::endl; 71 std::cerr << "WARNING: PropertyContainer[" << getPropertyContainerName().toStdString() << "]::setProperty(" << name.toStdString() << "): no implementation in subclass!" << std::endl;
83 } 72 }
84 73
85 void 74 Command *
86 PropertyContainer::setPropertyWithCommand(const PropertyName &name, int value) 75 PropertyContainer::getSetPropertyCommand(const PropertyName &name, int value)
87 { 76 {
88 int currentValue = getPropertyRangeAndValue(name, 0, 0, 0); 77 int currentValue = getPropertyRangeAndValue(name, 0, 0, 0);
89 if (value == currentValue) return; 78 if (value == currentValue) return 0;
90 79 return new SetPropertyCommand(this, name, value);
91 CommandHistory::getInstance()->addCommand
92 (new SetPropertyCommand(this, name, value), true, true); // bundled
93 } 80 }
94 81
95 void 82 void
96 PropertyContainer::setProperty(QString nameString, QString valueString) 83 PropertyContainer::setProperty(QString nameString, QString valueString)
97 { 84 {
105 return; 92 return;
106 } 93 }
107 setProperty(name, value); 94 setProperty(name, value);
108 } 95 }
109 96
110 void 97 Command *
111 PropertyContainer::setPropertyWithCommand(QString nameString, QString valueString) 98 PropertyContainer::getSetPropertyCommand(QString nameString, QString valueString)
112 { 99 {
113 PropertyName name; 100 PropertyName name;
114 int value; 101 int value;
115 if (!convertPropertyStrings(nameString, valueString, name, value)) { 102 if (!convertPropertyStrings(nameString, valueString, name, value)) {
116 std::cerr << "WARNING: PropertyContainer::setPropertyWithCommand(\"" 103 std::cerr << "WARNING: PropertyContainer::getSetPropertyCommand(\""
117 << nameString.toStdString() << "\", \"" 104 << nameString.toStdString() << "\", \""
118 << valueString.toStdString() 105 << valueString.toStdString()
119 << "\"): Name and value conversion failed" << std::endl; 106 << "\"): Name and value conversion failed" << std::endl;
120 return; 107 return 0;
121 } 108 }
122 setPropertyWithCommand(name, value); 109 return getSetPropertyCommand(name, value);
123 } 110 }
124 111
125 bool 112 bool
126 PropertyContainer::convertPropertyStrings(QString nameString, QString valueString, 113 PropertyContainer::convertPropertyStrings(QString nameString, QString valueString,
127 PropertyName &name, int &value) 114 PropertyName &name, int &value)
182 } 169 }
183 } 170 }
184 break; 171 break;
185 172
186 case ValueProperty: 173 case ValueProperty:
174 case ColourProperty:
187 { 175 {
188 int min, max; 176 int min, max;
189 getPropertyRangeAndValue(name, &min, &max, 0); 177 getPropertyRangeAndValue(name, &min, &max, 0);
190 for (int i = min; i <= max; ++i) { 178 for (int i = min; i <= max; ++i) {
191 if (valueString == getPropertyValueLabel(name, i)) { 179 if (valueString == getPropertyValueLabel(name, i)) {
194 break; 182 break;
195 } 183 }
196 } 184 }
197 break; 185 break;
198 } 186 }
199
200 case ColourProperty:
201 value = ColourDatabase::getInstance()->getColourIndex(valueString);
202 if (value >= 0) success = true;
203 else value = 0;
204 break;
205 187
206 case UnitsProperty: 188 case UnitsProperty:
207 value = UnitDatabase::getInstance()->getUnitId(valueString, false); 189 value = UnitDatabase::getInstance()->getUnitId(valueString, false);
208 if (value >= 0) success = true; 190 if (value >= 0) success = true;
209 else value = 0; 191 else value = 0;