Skip to content
Permalink
Browse files

Various fixes for photo editor and external resource widgets

- Clear picture when changing from a feature with a picture to
a feature with no picture set
- Don't try to load "NULL" as a filename
- Fix calculation of widget size so that widget can collapse
its size to nothing when it doesn't have a picture set
- Avoid incorrect scaling and cropping of pictures
  • Loading branch information
nyalldawson committed Apr 5, 2016
1 parent e571885 commit 0c161950a9974aa1cf165ed6151ff854c924665a
@@ -56,6 +56,18 @@ void QgsPhotoWidgetWrapper::selectFileName()

void QgsPhotoWidgetWrapper::loadPixmap( const QString& fileName )
{
if ( fileName.isEmpty() )
{
#ifdef WITH_QTWEBKIT
if ( mWebView )
{
mWebView->setUrl( QString() );
}
#endif
clearPicture();
return;
}

QString filePath = fileName;

if ( QUrl( fileName ).isRelative() )
@@ -98,6 +110,24 @@ void QgsPhotoWidgetWrapper::loadPixmap( const QString& fileName )
mPhotoLabel->setPixmap( pm );
}
}
else
{
clearPicture();
}
}

void QgsPhotoWidgetWrapper::clearPicture()
{
if ( mPhotoLabel )
{
mPhotoLabel->clear();
mPhotoLabel->setMinimumSize( QSize( 0, 0 ) );

if ( mPhotoPixmapLabel )
mPhotoPixmapLabel->setPixmap( QPixmap() );
else
mPhotoLabel->setPixmap( QPixmap() );
}
}

QVariant QgsPhotoWidgetWrapper::value() const
@@ -212,7 +242,10 @@ void QgsPhotoWidgetWrapper::setValue( const QVariant& value )
if ( mLineEdit )
{
if ( value.isNull() )
mLineEdit->setText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
{
whileBlocking( mLineEdit )->setText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
clearPicture();
}
else
mLineEdit->setText( value.toString() );
}
@@ -78,6 +78,8 @@ class GUI_EXPORT QgsPhotoWidgetWrapper : public QgsEditorWidgetWrapper
QLineEdit* mLineEdit;
//! The button to open the file chooser dialog
QPushButton* mButton;

void clearPicture();
};

#endif // QGSPHOTOWIDGETWRAPPER_H
@@ -142,7 +142,11 @@ void QgsExternalResourceWidget::updateDocumentViewer()
{
const QPixmap* pm = mPixmapLabel->pixmap();

if ( pm )
if ( !pm || pm->isNull() )
{
mPixmapLabel->setMinimumSize( QSize( 0, 0 ) );
}
else
{
QSize size( mDocumentViewerWidth, mDocumentViewerHeight );
if ( size.width() == 0 && size.height() > 0 )
@@ -165,7 +169,7 @@ void QgsExternalResourceWidget::updateDocumentViewer()

void QgsExternalResourceWidget::loadDocument( const QString& path )
{
if ( path.isNull() )
if ( path.isEmpty() )
{
#ifdef WITH_QTWEBKIT
if ( mDocumentViewerContent == Web )
@@ -176,6 +180,7 @@ void QgsExternalResourceWidget::loadDocument( const QString& path )
if ( mDocumentViewerContent == Image )
{
mPixmapLabel->clear();
updateDocumentViewer();
}
}

@@ -190,12 +195,8 @@ void QgsExternalResourceWidget::loadDocument( const QString& path )
if ( mDocumentViewerContent == Image )
{
QPixmap pm( path );
if ( !pm.isNull() )
{
mPixmapLabel->setPixmap( pm );

updateDocumentViewer();
}
mPixmapLabel->setPixmap( pm );
updateDocumentViewer();
}
}

@@ -24,17 +24,31 @@ QgsPixmapLabel::QgsPixmapLabel( QWidget *parent ) :

void QgsPixmapLabel::setPixmap( const QPixmap & p )
{
bool sizeChanged = ( p.size() != mPixmap.size() );
mPixmap = p;
QLabel::setPixmap( p );

if ( sizeChanged )
{
updateGeometry();
}

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

int QgsPixmapLabel::heightForWidth( int width ) const
{
if ( mPixmap.isNull() )
return 0;

return (( qreal )mPixmap.height()*width ) / mPixmap.width();
}

QSize QgsPixmapLabel::sizeHint() const
{
if ( mPixmap.isNull() )
return QSize( 0, 0 );

int w = this->width();
return QSize( w, heightForWidth( w ) );
}

0 comments on commit 0c16195

Please sign in to comment.
You can’t perform that action at this time.