Skip to content
Permalink
Browse files
[composer] Show missing image graphic if picture item source is invalid
  • Loading branch information
nyalldawson committed May 15, 2014
1 parent a1aa980 commit df37e89300b8d36108d2d32e68a400df570c2e75
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="489.33719"
height="492.18411"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="New document 1">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-328.91036"
inkscape:cy="61.821883"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1215"
inkscape:window-height="776"
inkscape:window-x="65"
inkscape:window-y="24"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-86.767507,-101.99995)">
<path
style="fill:none;stroke:#e1270a;stroke-width:37.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="M 105.71429,120.93361 557.14286,575.21933"
id="path2987"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#e1270a;stroke-width:37.5;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="M 557.14286,126.6479 105.71429,575.21933"
id="path2989"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:19.60000038;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="M 105.71429,120.93361 557.14286,575.21933"
id="path2987-0"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#ffffff;stroke-width:19.60000038;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="M 557.14286,126.6479 105.71429,575.21933"
id="path2989-7"
inkscape:connector-curvature="0" />
</g>
</svg>
@@ -43,6 +43,7 @@
<file>north_arrows/gpsarrow.svg</file>
<file>north_arrows/gpsarrow2.svg</file>
<file>splash/splash.png</file>
<file>composer/missing_image.svg</file>
<file>themes/default/cap_flat.png</file>
<file>themes/default/cap_round.png</file>
<file>themes/default/cap_square.png</file>
@@ -110,12 +110,6 @@ void QgsComposerPictureWidget::on_mPictureLineEdit_editingFinished()
//check if file exists
QFileInfo fileInfo( filePath );

if ( !fileInfo.exists() || !fileInfo.isReadable() )
{
QMessageBox::critical( 0, "Invalid file", "Error, file does not exist or is not readable" );
return;
}

mPicture->beginCommand( tr( "Picture changed" ) );
mPicture->setPictureFile( filePath );
mPicture->update();
@@ -357,47 +357,66 @@ void QgsComposerPicture::refreshPicture()

void QgsComposerPicture::loadPicture( const QFile& file )
{
if ( !file.exists() )
if ( !file.exists()
|| ( mUseSourceExpression && mPictureExpr->hasEvalError() ) )
{
mMode = Unknown;
}

QFileInfo sourceFileInfo( file );
QString sourceFileSuffix = sourceFileInfo.suffix();
if ( sourceFileSuffix.compare( "svg", Qt::CaseInsensitive ) == 0 )
{
//try to open svg
mSVG.load( file.fileName() );
if ( mSVG.isValid() )
{
mMode = SVG;
QRect viewBox = mSVG.viewBox(); //take width/height ratio from view box instead of default size
mDefaultSvgSize.setWidth( viewBox.width() );
mDefaultSvgSize.setHeight( viewBox.height() );
}
else
{
mMode = Unknown;
}
}
else
{
//try to open raster with QImageReader
QImageReader imageReader( file.fileName() );
if ( imageReader.read( &mImage ) )
QFileInfo sourceFileInfo( file );
QString sourceFileSuffix = sourceFileInfo.suffix();
if ( sourceFileSuffix.compare( "svg", Qt::CaseInsensitive ) == 0 )
{
mMode = RASTER;
//try to open svg
mSVG.load( file.fileName() );
if ( mSVG.isValid() )
{
mMode = SVG;
QRect viewBox = mSVG.viewBox(); //take width/height ratio from view box instead of default size
mDefaultSvgSize.setWidth( viewBox.width() );
mDefaultSvgSize.setHeight( viewBox.height() );
}
else
{
mMode = Unknown;
}
}
else
{
mMode = Unknown;
//try to open raster with QImageReader
QImageReader imageReader( file.fileName() );
if ( imageReader.read( &mImage ) )
{
mMode = RASTER;
}
else
{
mMode = Unknown;
}
}
}

if ( mMode != Unknown ) //make sure we start with a new QImage
{
recalculateSize();
}
else if ( !( file.fileName().isEmpty() ) || ( mUseSourceExpression && mPictureExpr->hasEvalError() ) )
{
//trying to load an invalid file or bad expression, show cross picture
mMode = SVG;
QString badFile = QString( ":/images/composer/missing_image.svg" );
mSVG.load( badFile );
if ( mSVG.isValid() )
{
mMode = SVG;
QRect viewBox = mSVG.viewBox(); //take width/height ratio from view box instead of default size
mDefaultSvgSize.setWidth( viewBox.width() );
mDefaultSvgSize.setHeight( viewBox.height() );
recalculateSize();
}
}

emit itemChanged();
}

0 comments on commit df37e89

Please sign in to comment.