view sv/filter/Filter.cpp @ 282:d9319859a4cf tip

(none)
author benoitrigolleau
date Fri, 31 Oct 2008 11:00:24 +0000
parents 3200ed3fc957
children
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*	Sound Access	
		EASAIER client application.	
		Silogic 2007. Laure Bajard. 
	
	This program is free software; you can redistribute it and/or    
	modify it under the terms of the GNU General Public License as    
	published by the Free Software Foundation; either version 2 of the    
	License, or (at your option) any later version.  See the file    
	COPYING included with this distribution for more information.
*/
 
#include "Filter.h"

Filter::Filter() : QObject(),
	m_sourceChannelCount(0),
	filterEnabled(false)
{}

Filter::~Filter()
{
	while (!m_filterCollection.empty())
	{
		std::vector<PropertyContainer*>::iterator iter = m_filterCollection.begin();
		PropertyContainer* filterElt = *(iter);
		if (filterElt)
		{
			emit propertyContainerRemoved(filterElt->objectName());
			delete filterElt;
			filterElt = 0;
		}
		m_filterCollection.erase(iter);
	} 
}

bool Filter::isFilterEnabled() const {
	return filterEnabled;
}


void Filter::setFilterEnabled(bool b){
	filterEnabled=b;
}

void Filter::setFilterEnabled(int b){
	filterEnabled=(bool)b;
	
}

QString Filter::toEasaierXmlString(QString indent, QString extraAttributes) const
{
    QString s;

	std::vector<PropertyContainer*>::const_iterator iter;
	for (iter=m_filterCollection.begin(); iter!=m_filterCollection.end(); iter++)
	{
		PropertyContainer* filterElt = *(iter);

		s += indent + QString("<filter groupname=\"%1\" name=\"%2\" ").arg(objectName()).arg(filterElt->objectName());

		PropertyContainer::PropertyList propertyList = filterElt->getProperties();
		for(int i=0; i< ((int) propertyList.size());i++)
		{
			int min, max, deflt;
			int value = filterElt->getPropertyRangeAndValue(propertyList[i], &min, &max, &deflt);
			s += propertyList[i] + QString("=\"%1\" ").arg(value);
		}
	
		s += QString(" %1 />\n").arg(extraAttributes);
	}

    return s;
}

void Filter::setProperties(const QXmlAttributes &attributes)
{
	QString name = attributes.value("name");
	
	std::vector<PropertyContainer*>::const_iterator iter;
	for (iter=m_filterCollection.begin(); iter!=m_filterCollection.end(); iter++)
	{
		PropertyContainer* filterElt = *(iter);

		if (filterElt->objectName() == name)
		{
			PropertyContainer::PropertyList propertyList = filterElt->getProperties();
			int value;
			for(int i=0; i< ((int) propertyList.size());i++)
			{
				 value = attributes.value(propertyList[i]).toInt(); 
				 filterElt->setProperty(propertyList[i], value);
			}
			filterElt->emitPropertiesChanged();
		}
	}
}