Skip to content

Commit

Permalink
Merge pull request #43144 from nirvn/external_resource_image_fix
Browse files Browse the repository at this point in the history
External resource image fixes
  • Loading branch information
3nids committed May 10, 2021
2 parents 1b69cef + d3fa9cb commit e2e469d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgspixmaplabel.sip.in
Expand Up @@ -45,9 +45,16 @@ determined from the width with the given aspect ratio.
%End

public slots:

void setPixmap( const QPixmap & );
virtual void resizeEvent( QResizeEvent * );


void clear();
%Docstring
Clears any label contents.
%End

};

/************************************************************************
Expand Down
1 change: 0 additions & 1 deletion src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp
Expand Up @@ -249,7 +249,6 @@ void QgsExternalResourceWidgetWrapper::updateValues( const QVariant &value, cons
mQgsWidget->setDocumentPath( value.toString() );
}
}

}

void QgsExternalResourceWidgetWrapper::setEnabled( bool enabled )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsexternalresourcewidget.cpp
Expand Up @@ -245,9 +245,13 @@ void QgsExternalResourceWidget::loadDocument( const QString &path )
ir.setAutoTransform( true );
QPixmap pm = QPixmap::fromImage( ir.read() );
if ( !pm.isNull() )
{
mPixmapLabel->setPixmap( pm );
}
else
{
mPixmapLabel->clear();
}
updateDocumentViewer();
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/gui/qgspixmaplabel.cpp
Expand Up @@ -32,8 +32,7 @@ void QgsPixmapLabel::setPixmap( const QPixmap &p )
updateGeometry();
}

QLabel::setPixmap( mPixmap.scaled( this->size(),
Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
QLabel::setPixmap( mPixmap.scaled( this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
}

int QgsPixmapLabel::heightForWidth( int width ) const
Expand All @@ -56,6 +55,15 @@ QSize QgsPixmapLabel::sizeHint() const
void QgsPixmapLabel::resizeEvent( QResizeEvent *e )
{
QLabel::resizeEvent( e );
QLabel::setPixmap( mPixmap.scaled( this->size(),
Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
if ( !mPixmap.isNull() )
{
// Avoid infinite resize loop by setting a pixmap that'll always have a width and height less or equal to the label size
QLabel::setPixmap( mPixmap.scaled( this->size() -= QSize( 1, 1 ), Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
}
}

void QgsPixmapLabel::clear()
{
mPixmap = QPixmap();
QLabel::clear();
}
6 changes: 6 additions & 0 deletions src/gui/qgspixmaplabel.h
Expand Up @@ -50,9 +50,15 @@ class GUI_EXPORT QgsPixmapLabel : public QLabel
QSize sizeHint() const override;

public slots:

void setPixmap( const QPixmap & );
void resizeEvent( QResizeEvent * ) override;

//! Clears any label contents.
void clear();

private:

QPixmap mPixmap;
};

Expand Down

0 comments on commit e2e469d

Please sign in to comment.