annotate base/PropertyContainer.cpp @ 189:0703252c9fe8

* Add spectrum icon * Start range mapper class for use in mapping between e.g. dial positions and underlying values
author Chris Cannam
date Mon, 16 Oct 2006 13:13:57 +0000
parents 5b8392e80ed6
children 60ba218a54bb
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@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PropertyContainer.h"
Chris@46 17 #include "CommandHistory.h"
Chris@46 18
Chris@46 19 #include <iostream>
Chris@0 20
Chris@0 21 PropertyContainer::PropertyList
Chris@0 22 PropertyContainer::getProperties() const
Chris@0 23 {
Chris@0 24 return PropertyList();
Chris@0 25 }
Chris@0 26
Chris@94 27 //QString
Chris@94 28 //PropertyContainer::getPropertyLabel(const PropertyName &) const
Chris@94 29 //{
Chris@94 30 // return "";
Chris@94 31 //}
Chris@94 32
Chris@0 33 PropertyContainer::PropertyType
Chris@0 34 PropertyContainer::getPropertyType(const PropertyName &) const
Chris@0 35 {
Chris@0 36 return InvalidProperty;
Chris@0 37 }
Chris@0 38
Chris@0 39 QString
Chris@0 40 PropertyContainer::getPropertyGroupName(const PropertyName &) const
Chris@0 41 {
Chris@0 42 return QString();
Chris@0 43 }
Chris@0 44
Chris@0 45 int
Chris@0 46 PropertyContainer::getPropertyRangeAndValue(const PropertyName &, int *min, int *max) const
Chris@0 47 {
Chris@0 48 if (min) *min = 0;
Chris@0 49 if (max) *max = 0;
Chris@0 50 return 0;
Chris@0 51 }
Chris@0 52
Chris@0 53 QString
Chris@0 54 PropertyContainer::getPropertyValueLabel(const PropertyName &, int) const
Chris@0 55 {
Chris@0 56 return QString();
Chris@0 57 }
Chris@0 58
Chris@0 59 void
Chris@46 60 PropertyContainer::setProperty(const PropertyName &name, int)
Chris@46 61 {
Chris@46 62 std::cerr << "WARNING: PropertyContainer[" << getPropertyContainerName().toStdString() << "]::setProperty(" << name.toStdString() << "): no implementation in subclass!" << std::endl;
Chris@46 63 }
Chris@46 64
Chris@46 65 void
Chris@46 66 PropertyContainer::setPropertyWithCommand(const PropertyName &name, int value)
Chris@46 67 {
Chris@46 68 int currentValue = getPropertyRangeAndValue(name, 0, 0);
Chris@46 69 if (value == currentValue) return;
Chris@46 70
Chris@46 71 CommandHistory::getInstance()->addCommand
Chris@47 72 (new SetPropertyCommand(this, name, value), true, true); // bundled
Chris@46 73 }
Chris@46 74
Chris@46 75 PropertyContainer::SetPropertyCommand::SetPropertyCommand(PropertyContainer *pc,
Chris@46 76 const PropertyName &pn,
Chris@46 77 int value) :
Chris@46 78 m_pc(pc),
Chris@46 79 m_pn(pn),
Chris@46 80 m_value(value),
Chris@46 81 m_oldValue(0)
Chris@0 82 {
Chris@0 83 }
Chris@0 84
Chris@46 85 void
Chris@46 86 PropertyContainer::SetPropertyCommand::execute()
Chris@46 87 {
Chris@46 88 m_oldValue = m_pc->getPropertyRangeAndValue(m_pn, 0, 0);
Chris@46 89 m_pc->setProperty(m_pn, m_value);
Chris@46 90 }
Chris@46 91
Chris@46 92 void
Chris@46 93 PropertyContainer::SetPropertyCommand::unexecute()
Chris@46 94 {
Chris@46 95 m_pc->setProperty(m_pn, m_oldValue);
Chris@46 96 }
Chris@46 97
Chris@46 98 QString
Chris@46 99 PropertyContainer::SetPropertyCommand::getName() const
Chris@46 100 {
Chris@46 101 return m_pc->tr("Set %1 Property").arg(m_pn);
Chris@46 102 }
Chris@46 103