Skip to content

Commit f4a7fcb

Browse files
committed
render missing SVG symbol (?) if SVG file does not exist
1 parent 55727f7 commit f4a7fcb

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/core/symbology-ng/qgssvgcache.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ QgsSvgCache::QgsSvgCache( QObject *parent )
9393
, mLeastRecentEntry( 0 )
9494
, mMostRecentEntry( 0 )
9595
{
96+
mMissingSvg = QString( "<svg width='10' height='10'><text x='5' y='10' font-size='10' text-anchor='middle'>?</text></svg>" ).toAscii();
9697
}
9798

9899
QgsSvgCache::~QgsSvgCache()
@@ -246,20 +247,20 @@ QByteArray QgsSvgCache::getImageData( const QString &path ) const
246247
}
247248
else
248249
{
249-
return QByteArray();
250+
return mMissingSvg;
250251
}
251252
}
252253

253254
// maybe it's a url...
254255
if ( !path.contains( "://" ) ) // otherwise short, relative SVG paths might be considered URLs
255256
{
256-
return QByteArray();
257+
return mMissingSvg;
257258
}
258259

259260
QUrl svgUrl( path );
260261
if ( !svgUrl.isValid() )
261262
{
262-
return QByteArray();
263+
return mMissingSvg;
263264
}
264265

265266
// check whether it's a url pointing to a local file
@@ -275,7 +276,7 @@ QByteArray QgsSvgCache::getImageData( const QString &path ) const
275276
}
276277

277278
// not found...
278-
return QByteArray();
279+
return mMissingSvg;
279280
}
280281

281282
// the url points to a remote resource, download it!
@@ -331,15 +332,15 @@ QByteArray QgsSvgCache::getImageData( const QString &path ) const
331332
QgsMessageLog::logMessage( tr( "SVG request error [status: %1 - reason phrase: %2]" ).arg( status.toInt() ).arg( phrase.toString() ), tr( "SVG" ) );
332333

333334
reply->deleteLater();
334-
return QByteArray();
335+
return mMissingSvg;
335336
}
336337

337338
QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
338339
QgsDebugMsg( "contentType: " + contentType );
339340
if ( !contentType.startsWith( "image/svg+xml", Qt::CaseInsensitive ) )
340341
{
341342
reply->deleteLater();
342-
return QByteArray();
343+
return mMissingSvg;
343344
}
344345

345346
// read the image data

src/core/symbology-ng/qgssvgcache.h

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ class CORE_EXPORT QgsSvgCache : public QObject
147147

148148
/**For debugging*/
149149
void printEntryList();
150+
151+
/** SVG content to be rendered if SVG file was not found. */
152+
QByteArray mMissingSvg;
150153
};
151154

152155
#endif // QGSSVGCACHE_H

0 commit comments

Comments
 (0)