Skip to content
Permalink
Browse files

render missing SVG symbol (?) if SVG file does not exist

  • Loading branch information
blazek committed Jan 26, 2014
1 parent 55727f7 commit f4a7fcb769125a9243d59b9e44a3489e9163c654
Showing with 10 additions and 6 deletions.
  1. +7 −6 src/core/symbology-ng/qgssvgcache.cpp
  2. +3 −0 src/core/symbology-ng/qgssvgcache.h
@@ -93,6 +93,7 @@ QgsSvgCache::QgsSvgCache( QObject *parent )
, mLeastRecentEntry( 0 )
, mMostRecentEntry( 0 )
{
mMissingSvg = QString( "<svg width='10' height='10'><text x='5' y='10' font-size='10' text-anchor='middle'>?</text></svg>" ).toAscii();
}

QgsSvgCache::~QgsSvgCache()
@@ -246,20 +247,20 @@ QByteArray QgsSvgCache::getImageData( const QString &path ) const
}
else
{
return QByteArray();
return mMissingSvg;
}
}

// maybe it's a url...
if ( !path.contains( "://" ) ) // otherwise short, relative SVG paths might be considered URLs
{
return QByteArray();
return mMissingSvg;
}

QUrl svgUrl( path );
if ( !svgUrl.isValid() )
{
return QByteArray();
return mMissingSvg;
}

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

// not found...
return QByteArray();
return mMissingSvg;
}

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

reply->deleteLater();
return QByteArray();
return mMissingSvg;
}

QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
QgsDebugMsg( "contentType: " + contentType );
if ( !contentType.startsWith( "image/svg+xml", Qt::CaseInsensitive ) )
{
reply->deleteLater();
return QByteArray();
return mMissingSvg;
}

// read the image data
@@ -147,6 +147,9 @@ class CORE_EXPORT QgsSvgCache : public QObject

/**For debugging*/
void printEntryList();

/** SVG content to be rendered if SVG file was not found. */
QByteArray mMissingSvg;
};

#endif // QGSSVGCACHE_H

1 comment on commit f4a7fcb

@pcav

This comment has been minimized.

Copy link
Member

@pcav pcav commented on f4a7fcb Mar 7, 2014

Work done for Regione Toscana - SITA (CIG ZB10C90E5A)

Please sign in to comment.