00001 /* 00002 * Copyright (c) 2005 Bart Coppens <kde@bartcoppens.be> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 #include "KoHistogramProducer.h" 00020 #include "KoBasicHistogramProducers.h" 00021 //Added by qt3to4: 00022 #include <Q3ValueList> 00023 00024 KoHistogramProducerFactoryRegistry* KoHistogramProducerFactoryRegistry::m_singleton = 0; 00025 00026 KoHistogramProducerFactoryRegistry::KoHistogramProducerFactoryRegistry() { 00027 Q_ASSERT(KoHistogramProducerFactoryRegistry::m_singleton == 0); 00028 } 00029 00030 KoHistogramProducerFactoryRegistry::~KoHistogramProducerFactoryRegistry() { 00031 } 00032 00033 KoHistogramProducerFactoryRegistry* KoHistogramProducerFactoryRegistry::instance() { 00034 if(KoHistogramProducerFactoryRegistry::m_singleton == 0) { 00035 KoHistogramProducerFactoryRegistry::m_singleton 00036 = new KoHistogramProducerFactoryRegistry(); 00037 m_singleton->add( new KoGenericLabHistogramProducerFactory() ); 00038 } 00039 return KoHistogramProducerFactoryRegistry::m_singleton; 00040 } 00041 00042 QList<KoID> KoHistogramProducerFactoryRegistry::listKeysCompatibleWith( 00043 KoColorSpace* colorSpace) const 00044 { 00045 QList<KoID> list; 00046 Q3ValueList<float> preferredList; 00047 storageMap::const_iterator it = m_storage.begin(); 00048 storageMap::const_iterator endit = m_storage.end(); 00049 // O(n^2), can't this be done better? (But preferrably not by looking up the preferredness 00050 // during the sorting... 00051 while( it != endit ) { 00052 if (it->second->isCompatibleWith(colorSpace)) { 00053 float preferred = it->second->preferrednessLevelWith(colorSpace); 00054 Q3ValueList<float>::iterator pit = preferredList.begin(); 00055 Q3ValueList<float>::iterator pend = preferredList.end(); 00056 QList<KoID>::iterator lit = list.begin(); 00057 00058 while (pit != pend && preferred <= *pit) { 00059 ++pit; 00060 ++lit; 00061 } 00062 00063 list.insert(lit, it->first); 00064 preferredList.insert(pit, preferred); 00065 } 00066 ++it; 00067 } 00068 return list; 00069 }