25 #include <QTemporaryDir>
29 QgsSourceCacheEntry::QgsSourceCacheEntry(
const QString &path )
36 const QgsSourceCacheEntry *otherSource =
dynamic_cast< const QgsSourceCacheEntry *
>( other );
38 if ( !otherSource || otherSource->filePath != filePath )
44 int QgsSourceCacheEntry::dataSize()
const
46 return filePath.size();
49 void QgsSourceCacheEntry::dump()
const
59 temporaryDir.reset(
new QTemporaryDir() );
66 const QString file = path.trimmed();
70 QMutexLocker locker( &
mMutex );
72 QgsSourceCacheEntry *currentEntry =
findExistingEntry(
new QgsSourceCacheEntry( file ) );
75 if ( currentEntry->filePath.isEmpty() )
78 QString filePath = fetchSource( file, isBroken, blocking );
79 currentEntry->filePath = filePath;
82 return currentEntry->filePath;
85 QString QgsSourceCache::fetchSource(
const QString &path,
bool &isBroken,
bool blocking )
const
89 if ( !path.startsWith( QLatin1String(
"base64:" ) ) && QFile::exists( path ) )
95 QByteArray ba =
getContent( path, QByteArray(
"broken" ), QByteArray(
"fetching" ), blocking );
104 filePath = temporaryDir->filePath( QString::number(
id ) );
105 while ( QFile::exists( filePath ) )
106 filePath = temporaryDir->filePath( QString::number( ++
id ) );
108 QFile file( filePath );
109 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.
QgsSourceCacheEntry * findExistingEntry(QgsSourceCacheEntry *entryTemplate)
Returns the existing entry from the cache which matches entryTemplate (deleting entryTemplate when do...
QByteArray getContent(const QString &path, const QByteArray &missingContent, const QByteArray &fetchingContent, bool blocking=false) const
Gets the file content corresponding to the given path.
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)