6#include "QskGraphicProvider.h"
7#include "QskGraphicProviderMap.h"
9#include "QskSkinManager.h"
16#include <qglobalstatic.h>
20class QskGraphicProvider::PrivateData
24 QCache< QString, const QskGraphic > cache;
28QskGraphicProvider::QskGraphicProvider( QObject* parent )
30 , m_data( new PrivateData() )
34QskGraphicProvider::~QskGraphicProvider()
38void QskGraphicProvider::setCacheSize(
int size )
43 QMutexLocker locker( &m_data->mutex );
44 m_data->cache.setMaxCost( size );
47int QskGraphicProvider::cacheSize()
const
49 QMutexLocker locker( &m_data->mutex );
50 return m_data->cache.maxCost();
53void QskGraphicProvider::clearCache()
55 QMutexLocker locker( &m_data->mutex );
56 m_data->cache.clear();
59const QskGraphic* QskGraphicProvider::requestGraphic(
const QString&
id )
const
64 QMutexLocker locker( &m_data->mutex );
65 graphic = m_data->cache.object(
id );
68 if ( graphic ==
nullptr )
70 graphic = loadGraphic(
id );
72 if ( graphic ==
nullptr )
74 qWarning() <<
"QskGraphicProvider: can't load" << id;
79 QMutexLocker locker( &m_data->mutex );
81 if(
auto cached = m_data->cache.object(
id ) )
89 m_data->cache.insert(
id, graphic, cost );
97void Qsk::addGraphicProvider(
100 if ( qskGraphicProviders )
101 qskGraphicProviders->insert( providerId, provider );
106 if (
auto skin = qskSkinManager->skin() )
108 if (
auto provider = skin->graphicProvider( providerId ) )
112 if ( qskGraphicProviders )
113 return qskGraphicProviders->provider( providerId );
118QskGraphic Qsk::loadGraphic(
const char* source )
120 return loadGraphic( QUrl( source ) );
127 QString imageId = url.toString( QUrl::RemoveScheme |
128 QUrl::RemoveAuthority | QUrl::NormalizePathSegments );
130 if ( imageId.isEmpty() )
133 if ( imageId[ 0 ] ==
'/' )
134 imageId = imageId.mid( 1 );
136 const QString providerId = url.host();
140 if (
const auto provider = Qsk::graphicProvider( providerId ) )
141 graphic = provider->requestGraphic( imageId );
143 return graphic ? *graphic : nullGraphic;
146#include "moc_QskGraphicProvider.cpp"
A paint device for scalable graphics.