29#include <QTemporaryDir>
31#include "moc_qgssourcecache.cpp"
33using namespace Qt::StringLiterals;
37QgsSourceCacheEntry::QgsSourceCacheEntry(
const QString &path )
44 const QgsSourceCacheEntry *otherSource =
dynamic_cast< const QgsSourceCacheEntry *
>( other );
46 if ( !otherSource || otherSource->filePath != filePath )
52int QgsSourceCacheEntry::dataSize()
const
54 return filePath.size();
57void QgsSourceCacheEntry::dump()
const
67 temporaryDir = std::make_unique<QTemporaryDir>( );
74 const QString file = path.trimmed();
78 const QMutexLocker locker( &
mMutex );
80 QgsSourceCacheEntry *currentEntry =
findExistingEntry(
new QgsSourceCacheEntry( file ) );
83 if ( currentEntry->filePath.isEmpty() )
86 const QString filePath = fetchSource( file, isBroken, blocking );
87 currentEntry->filePath = filePath;
90 return currentEntry->filePath;
93QString QgsSourceCache::fetchSource(
const QString &path,
bool &isBroken,
bool blocking )
const
97 if ( !path.startsWith(
"base64:"_L1 ) && QFile::exists( path ) )
103 const QByteArray ba =
getContent( path, QByteArray(
"broken" ), QByteArray(
"fetching" ), blocking );
105 if ( ba ==
"broken" )
112 filePath = temporaryDir->filePath( QString::number(
id ) );
113 while ( QFile::exists( filePath ) )
114 filePath = temporaryDir->filePath( QString::number( ++
id ) );
116 QFile file( filePath );
117 if ( !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
QgsSourceCacheEntry * findExistingEntry(QgsSourceCacheEntry *entryTemplate)
QgsAbstractContentCache(QObject *parent=nullptr, const QString &typeString=QString(), long maxCacheSize=20000000, int fileModifiedCheckTimeout=30000)
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)
#define QgsDebugError(str)