26#include <QTemporaryDir>
30QgsSourceCacheEntry::QgsSourceCacheEntry(
const QString &path )
37 const QgsSourceCacheEntry *otherSource =
dynamic_cast< const QgsSourceCacheEntry *
>( other );
39 if ( !otherSource || otherSource->filePath != filePath )
45int QgsSourceCacheEntry::dataSize()
const
47 return filePath.size();
50void QgsSourceCacheEntry::dump()
const
60 temporaryDir.reset(
new QTemporaryDir() );
67 const QString file = path.trimmed();
71 const QMutexLocker locker( &
mMutex );
73 QgsSourceCacheEntry *currentEntry =
findExistingEntry(
new QgsSourceCacheEntry( file ) );
76 if ( currentEntry->filePath.isEmpty() )
79 const QString filePath = fetchSource( file, isBroken, blocking );
80 currentEntry->filePath = filePath;
83 return currentEntry->filePath;
86QString QgsSourceCache::fetchSource(
const QString &path,
bool &isBroken,
bool blocking )
const
90 if ( !path.startsWith( QLatin1String(
"base64:" ) ) && QFile::exists( path ) )
96 const QByteArray ba =
getContent( path, QByteArray(
"broken" ), QByteArray(
"fetching" ), blocking );
105 filePath = temporaryDir->filePath( QString::number(
id ) );
106 while ( QFile::exists( filePath ) )
107 filePath = temporaryDir->filePath( QString::number( ++
id ) );
109 QFile file( filePath );
110 file.open( QIODevice::WriteOnly );
void remoteContentFetched(const QString &url)
Emitted when the cache has finished retrieving content from a remote url.
Base class for entries in a QgsAbstractContentCache.
Abstract base class for file content caches, such as SVG or raster image caches.
QByteArray getContent(const QString &path, const QByteArray &missingContent, const QByteArray &fetchingContent, bool blocking=false) const
Gets the file content corresponding to the given path.
QgsSourceCacheEntry * findExistingEntry(QgsSourceCacheEntry *entryTemplate)
Returns the existing entry from the cache which matches entryTemplate (deleting entryTemplate when do...
QgsSourceCache(QObject *parent=nullptr)
Constructor for QgsSourceCache, with the specified parent object.
void remoteSourceFetched(const QString &url)
Emitted when the cache has finished retrieving a 3D model from a remote url.
QString localFilePath(const QString &path, bool blocking=false)
Returns a local file path reflecting the content of a specified source path.
#define QgsDebugMsgLevel(str, level)