Skip to content

Commit

Permalink
[layouts] When dropping an SVG onto layouts, treat it as such
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and nyalldawson committed May 5, 2020
1 parent 1b08f4c commit 9e91eb5
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/app/layout/qgslayoutimagedrophandler.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgslayout.h"
#include "qgslayoutview.h"
#include "qgslayoutitempicture.h"

#include <QImageReader>

QgsLayoutImageDropHandler::QgsLayoutImageDropHandler( QObject *parent )
Expand All @@ -29,19 +30,27 @@ QgsLayoutImageDropHandler::QgsLayoutImageDropHandler( QObject *parent )
bool QgsLayoutImageDropHandler::handleFileDrop( QgsLayoutDesignerInterface *iface, QPointF point, const QString &file )
{
QFileInfo fi( file );

bool matched = false;
const QList<QByteArray> formats = QImageReader::supportedImageFormats();
for ( const QByteArray &format : formats )
bool svg = false;
if ( fi.suffix().compare( "svg", Qt::CaseInsensitive ) == 0 )
{
matched = true;
svg = true;
}
else
{
if ( fi.suffix().compare( format, Qt::CaseInsensitive ) == 0 )
const QList<QByteArray> formats = QImageReader::supportedImageFormats();
for ( const QByteArray &format : formats )
{
matched = true;
break;
if ( fi.suffix().compare( format, Qt::CaseInsensitive ) == 0 )
{
matched = true;
break;
}
}
}
if ( !matched )

if ( !matched )
return false;

if ( !iface->layout() )
Expand All @@ -51,7 +60,7 @@ bool QgsLayoutImageDropHandler::handleFileDrop( QgsLayoutDesignerInterface *ifac

QgsLayoutPoint layoutPoint = iface->layout()->convertFromLayoutUnits( point, iface->layout()->units() );

item->setPicturePath( file, QgsLayoutItemPicture::FormatRaster );
item->setPicturePath( file, svg ? QgsLayoutItemPicture::FormatSVG : QgsLayoutItemPicture::FormatRaster );

// force a resize to the image's actual size
item->setResizeMode( QgsLayoutItemPicture::FrameToImageSize );
Expand Down

0 comments on commit 9e91eb5

Please sign in to comment.