1 /* 2 For general Scribus (>=1.3.2) copyright and licensing information please refer 3 to the COPYING file provided with the program. Following this notice may exist 4 a copyright and/or license notice that predates the release of Scribus 1.3.2 5 for which a new license (GPL+exception) is in place. 6 */ 7 8 #include <QSharedPointer> 9 #include "sccolormgmtengine.h" 10 #include "sccolormgmtstructs.h" 11 #include "sccolortransformpool.h" 12 ScColorTransformPool(int engineID)13ScColorTransformPool::ScColorTransformPool(int engineID) : m_engineID(engineID) 14 { 15 16 } 17 clear()18void ScColorTransformPool::clear() 19 { 20 m_pool.clear(); 21 } 22 addTransform(const ScColorTransform & transform,bool force)23void ScColorTransformPool::addTransform(const ScColorTransform& transform, bool force) 24 { 25 // Check engine ID. If different, transform was created by another engine 26 // and we MUST NOT add it to the transform pool 27 if (m_engineID != transform.engine().engineID()) 28 return; 29 ScColorTransform trans; 30 if (!force) 31 trans = findTransform(transform.transformInfo()); 32 if (trans.isNull()) 33 m_pool.append(transform.weakRef()); 34 } 35 removeTransform(const ScColorTransform & transform)36void ScColorTransformPool::removeTransform(const ScColorTransform& transform) 37 { 38 if (m_engineID != transform.engine().engineID()) 39 return; 40 m_pool.removeOne(transform.strongRef()); 41 } 42 removeTransform(const ScColorTransformInfo & info)43void ScColorTransformPool::removeTransform(const ScColorTransformInfo& info) 44 { 45 QList< QWeakPointer<ScColorTransformData> >::Iterator it = m_pool.begin(); 46 while (it != m_pool.end()) 47 { 48 QSharedPointer<ScColorTransformData> ref = it->toStrongRef(); 49 if ((info == ref->transformInfo()) || ref.isNull()) 50 { 51 it = m_pool.erase(it); 52 continue; 53 } 54 ++it; 55 } 56 } 57 findTransform(const ScColorTransformInfo & info) const58ScColorTransform ScColorTransformPool::findTransform(const ScColorTransformInfo& info) const 59 { 60 ScColorTransform transform(nullptr); 61 QList< QWeakPointer<ScColorTransformData> >::ConstIterator it = m_pool.begin(); 62 for ( ; it != m_pool.end(); ++it) 63 { 64 QSharedPointer<ScColorTransformData> ref = it->toStrongRef(); 65 if (!ref.isNull()) 66 { 67 if (info == ref->transformInfo()) 68 { 69 transform = ScColorTransform(ref); 70 break; 71 } 72 } 73 } 74 return transform; 75 } 76