Skip to content

Commit

Permalink
render missing SVG symbol (?) if SVG file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jan 26, 2014
1 parent 55727f7 commit f4a7fcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/core/symbology-ng/qgssvgcache.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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!
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssvgcache.h
Expand Up @@ -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
Copy link
Member

@pcav pcav commented on f4a7fcb Mar 7, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work done for Regione Toscana - SITA (CIG ZB10C90E5A)

Please sign in to comment.