comparison base/PropertyContainer.cpp @ 245:4cd620bd4c61 sv1-1.0pre1

* Make getPropertyRangeAndValue return the default separately from the current value. Previously some contexts were incorrectly treating the current value as a default.
author Chris Cannam
date Fri, 02 Mar 2007 14:00:12 +0000
parents 91fdc752e540
children 21b9b25bff48
comparison
equal deleted inserted replaced
244:85bf384db35f 245:4cd620bd4c61
45 { 45 {
46 return QString(); 46 return QString();
47 } 47 }
48 48
49 int 49 int
50 PropertyContainer::getPropertyRangeAndValue(const PropertyName &, int *min, int *max) const 50 PropertyContainer::getPropertyRangeAndValue(const PropertyName &,
51 int *min, int *max, int *deflt) const
51 { 52 {
52 if (min) *min = 0; 53 if (min) *min = 0;
53 if (max) *max = 0; 54 if (max) *max = 0;
55 if (deflt) *deflt = 0;
54 return 0; 56 return 0;
55 } 57 }
56 58
57 QString 59 QString
58 PropertyContainer::getPropertyValueLabel(const PropertyName &, int) const 60 PropertyContainer::getPropertyValueLabel(const PropertyName &, int) const
73 } 75 }
74 76
75 void 77 void
76 PropertyContainer::setPropertyWithCommand(const PropertyName &name, int value) 78 PropertyContainer::setPropertyWithCommand(const PropertyName &name, int value)
77 { 79 {
78 int currentValue = getPropertyRangeAndValue(name, 0, 0); 80 int currentValue = getPropertyRangeAndValue(name, 0, 0, 0);
79 if (value == currentValue) return; 81 if (value == currentValue) return;
80 82
81 CommandHistory::getInstance()->addCommand 83 CommandHistory::getInstance()->addCommand
82 (new SetPropertyCommand(this, name, value), true, true); // bundled 84 (new SetPropertyCommand(this, name, value), true, true); // bundled
83 } 85 }
174 break; 176 break;
175 177
176 case ValueProperty: 178 case ValueProperty:
177 { 179 {
178 int min, max; 180 int min, max;
179 getPropertyRangeAndValue(name, &min, &max); 181 getPropertyRangeAndValue(name, &min, &max, 0);
180 for (int i = min; i <= max; ++i) { 182 for (int i = min; i <= max; ++i) {
181 if (valueString == getPropertyValueLabel(name, i)) { 183 if (valueString == getPropertyValueLabel(name, i)) {
182 value = i; 184 value = i;
183 success = true; 185 success = true;
184 break; 186 break;
209 } 211 }
210 212
211 if (success) return true; 213 if (success) return true;
212 214
213 int min, max; 215 int min, max;
214 getPropertyRangeAndValue(name, &min, &max); 216 getPropertyRangeAndValue(name, &min, &max, 0);
215 217
216 bool ok = false; 218 bool ok = false;
217 int i = valueString.toInt(&ok); 219 int i = valueString.toInt(&ok);
218 if (!ok) { 220 if (!ok) {
219 std::cerr << "PropertyContainer::convertPropertyStrings: Unable to parse value string \"" << valueString.toStdString() << "\"" << std::endl; 221 std::cerr << "PropertyContainer::convertPropertyStrings: Unable to parse value string \"" << valueString.toStdString() << "\"" << std::endl;
238 } 240 }
239 241
240 void 242 void
241 PropertyContainer::SetPropertyCommand::execute() 243 PropertyContainer::SetPropertyCommand::execute()
242 { 244 {
243 m_oldValue = m_pc->getPropertyRangeAndValue(m_pn, 0, 0); 245 m_oldValue = m_pc->getPropertyRangeAndValue(m_pn, 0, 0, 0);
244 m_pc->setProperty(m_pn, m_value); 246 m_pc->setProperty(m_pn, m_value);
245 } 247 }
246 248
247 void 249 void
248 PropertyContainer::SetPropertyCommand::unexecute() 250 PropertyContainer::SetPropertyCommand::unexecute()