annotate base/PropertyContainer.cpp @ 76:af2725b5d6fe

* Implement harmonic cursor in spectrogram * Implement layer export. This doesn't quite do the right thing for the SV XML layer export yet -- it doesn't include layer display information, so when imported, it only creates an invisible model. Could also do with fixing CSV file import so as to work correctly for note and text layers.
author Chris Cannam
date Mon, 10 Apr 2006 17:22:59 +0000
parents d397ea0a79f5
children 5b8392e80ed6
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@0 27 PropertyContainer::PropertyType
Chris@0 28 PropertyContainer::getPropertyType(const PropertyName &) const
Chris@0 29 {
Chris@0 30 return InvalidProperty;
Chris@0 31 }
Chris@0 32
Chris@0 33 QString
Chris@0 34 PropertyContainer::getPropertyGroupName(const PropertyName &) const
Chris@0 35 {
Chris@0 36 return QString();
Chris@0 37 }
Chris@0 38
Chris@0 39 int
Chris@0 40 PropertyContainer::getPropertyRangeAndValue(const PropertyName &, int *min, int *max) const
Chris@0 41 {
Chris@0 42 if (min) *min = 0;
Chris@0 43 if (max) *max = 0;
Chris@0 44 return 0;
Chris@0 45 }
Chris@0 46
Chris@0 47 QString
Chris@0 48 PropertyContainer::getPropertyValueLabel(const PropertyName &, int) const
Chris@0 49 {
Chris@0 50 return QString();
Chris@0 51 }
Chris@0 52
Chris@0 53 void
Chris@46 54 PropertyContainer::setProperty(const PropertyName &name, int)
Chris@46 55 {
Chris@46 56 std::cerr << "WARNING: PropertyContainer[" << getPropertyContainerName().toStdString() << "]::setProperty(" << name.toStdString() << "): no implementation in subclass!" << std::endl;
Chris@46 57 }
Chris@46 58
Chris@46 59 void
Chris@46 60 PropertyContainer::setPropertyWithCommand(const PropertyName &name, int value)
Chris@46 61 {
Chris@46 62 int currentValue = getPropertyRangeAndValue(name, 0, 0);
Chris@46 63 if (value == currentValue) return;
Chris@46 64
Chris@46 65 CommandHistory::getInstance()->addCommand
Chris@47 66 (new SetPropertyCommand(this, name, value), true, true); // bundled
Chris@46 67 }
Chris@46 68
Chris@46 69 PropertyContainer::SetPropertyCommand::SetPropertyCommand(PropertyContainer *pc,
Chris@46 70 const PropertyName &pn,
Chris@46 71 int value) :
Chris@46 72 m_pc(pc),
Chris@46 73 m_pn(pn),
Chris@46 74 m_value(value),
Chris@46 75 m_oldValue(0)
Chris@0 76 {
Chris@0 77 }
Chris@0 78
Chris@46 79 void
Chris@46 80 PropertyContainer::SetPropertyCommand::execute()
Chris@46 81 {
Chris@46 82 m_oldValue = m_pc->getPropertyRangeAndValue(m_pn, 0, 0);
Chris@46 83 m_pc->setProperty(m_pn, m_value);
Chris@46 84 }
Chris@46 85
Chris@46 86 void
Chris@46 87 PropertyContainer::SetPropertyCommand::unexecute()
Chris@46 88 {
Chris@46 89 m_pc->setProperty(m_pn, m_oldValue);
Chris@46 90 }
Chris@46 91
Chris@46 92 QString
Chris@46 93 PropertyContainer::SetPropertyCommand::getName() const
Chris@46 94 {
Chris@46 95 return m_pc->tr("Set %1 Property").arg(m_pn);
Chris@46 96 }
Chris@46 97