annotate base/PropertyContainer.cpp @ 49:39ae3dee27b9

* Set indent-tabs-mode to nil in Emacs mode direction
author Chris Cannam
date Mon, 20 Mar 2006 11:40:39 +0000
parents bac8b14ab355
children d397ea0a79f5
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@2 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 #include "PropertyContainer.h"
Chris@46 11 #include "CommandHistory.h"
Chris@46 12
Chris@46 13 #include <iostream>
Chris@0 14
Chris@0 15 PropertyContainer::PropertyList
Chris@0 16 PropertyContainer::getProperties() const
Chris@0 17 {
Chris@0 18 return PropertyList();
Chris@0 19 }
Chris@0 20
Chris@0 21 PropertyContainer::PropertyType
Chris@0 22 PropertyContainer::getPropertyType(const PropertyName &) const
Chris@0 23 {
Chris@0 24 return InvalidProperty;
Chris@0 25 }
Chris@0 26
Chris@0 27 QString
Chris@0 28 PropertyContainer::getPropertyGroupName(const PropertyName &) const
Chris@0 29 {
Chris@0 30 return QString();
Chris@0 31 }
Chris@0 32
Chris@0 33 int
Chris@0 34 PropertyContainer::getPropertyRangeAndValue(const PropertyName &, int *min, int *max) const
Chris@0 35 {
Chris@0 36 if (min) *min = 0;
Chris@0 37 if (max) *max = 0;
Chris@0 38 return 0;
Chris@0 39 }
Chris@0 40
Chris@0 41 QString
Chris@0 42 PropertyContainer::getPropertyValueLabel(const PropertyName &, int) const
Chris@0 43 {
Chris@0 44 return QString();
Chris@0 45 }
Chris@0 46
Chris@0 47 void
Chris@46 48 PropertyContainer::setProperty(const PropertyName &name, int)
Chris@46 49 {
Chris@46 50 std::cerr << "WARNING: PropertyContainer[" << getPropertyContainerName().toStdString() << "]::setProperty(" << name.toStdString() << "): no implementation in subclass!" << std::endl;
Chris@46 51 }
Chris@46 52
Chris@46 53 void
Chris@46 54 PropertyContainer::setPropertyWithCommand(const PropertyName &name, int value)
Chris@46 55 {
Chris@46 56 int currentValue = getPropertyRangeAndValue(name, 0, 0);
Chris@46 57 if (value == currentValue) return;
Chris@46 58
Chris@46 59 CommandHistory::getInstance()->addCommand
Chris@47 60 (new SetPropertyCommand(this, name, value), true, true); // bundled
Chris@46 61 }
Chris@46 62
Chris@46 63 PropertyContainer::SetPropertyCommand::SetPropertyCommand(PropertyContainer *pc,
Chris@46 64 const PropertyName &pn,
Chris@46 65 int value) :
Chris@46 66 m_pc(pc),
Chris@46 67 m_pn(pn),
Chris@46 68 m_value(value),
Chris@46 69 m_oldValue(0)
Chris@0 70 {
Chris@0 71 }
Chris@0 72
Chris@46 73 void
Chris@46 74 PropertyContainer::SetPropertyCommand::execute()
Chris@46 75 {
Chris@46 76 m_oldValue = m_pc->getPropertyRangeAndValue(m_pn, 0, 0);
Chris@46 77 m_pc->setProperty(m_pn, m_value);
Chris@46 78 }
Chris@46 79
Chris@46 80 void
Chris@46 81 PropertyContainer::SetPropertyCommand::unexecute()
Chris@46 82 {
Chris@46 83 m_pc->setProperty(m_pn, m_oldValue);
Chris@46 84 }
Chris@46 85
Chris@46 86 QString
Chris@46 87 PropertyContainer::SetPropertyCommand::getName() const
Chris@46 88 {
Chris@46 89 return m_pc->tr("Set %1 Property").arg(m_pn);
Chris@46 90 }
Chris@46 91