28#include <QTemporaryDir>
30#include "moc_qgssourcecache.cpp"
34QgsSourceCacheEntry::QgsSourceCacheEntry(
const QString &path )
41 const QgsSourceCacheEntry *otherSource =
dynamic_cast< const QgsSourceCacheEntry *
>( other );
43 if ( !otherSource || otherSource->filePath != filePath )
49int QgsSourceCacheEntry::dataSize()
const
51 return filePath.size();
54void QgsSourceCacheEntry::dump()
const
64 temporaryDir = std::make_unique<QTemporaryDir>( );
71 const QString file = path.trimmed();
75 const QMutexLocker locker( &
mMutex );
77 QgsSourceCacheEntry *currentEntry =
findExistingEntry(
new QgsSourceCacheEntry( file ) );
80 if ( currentEntry->filePath.isEmpty() )
83 const QString filePath = fetchSource( file, isBroken, blocking );
84 currentEntry->filePath = filePath;
87 return currentEntry->filePath;
90QString QgsSourceCache::fetchSource(
const QString &path,
bool &isBroken,
bool blocking )
const
94 if ( !path.startsWith( QLatin1String(
"base64:" ) ) && QFile::exists( path ) )
100 const QByteArray ba =
getContent( path, QByteArray(
"broken" ), QByteArray(
"fetching" ), blocking );
102 if ( ba ==
"broken" )
109 filePath = temporaryDir->filePath( QString::number(
id ) );
110 while ( QFile::exists( filePath ) )
111 filePath = temporaryDir->filePath( QString::number( ++
id ) );
113 QFile file( filePath );
114 if ( !file.open( QIODevice::WriteOnly ) )
116 QgsDebugError( QStringLiteral(
"Can't open file %1" ).arg( filePath ) );
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)