Commit 0c16195 1 parent e571885 commit 0c16195 Copy full SHA for 0c16195
File tree 4 files changed +60
-10
lines changed
4 files changed +60
-10
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,18 @@ void QgsPhotoWidgetWrapper::selectFileName()
56
56
57
57
void QgsPhotoWidgetWrapper::loadPixmap ( const QString& fileName )
58
58
{
59
+ if ( fileName.isEmpty () )
60
+ {
61
+ #ifdef WITH_QTWEBKIT
62
+ if ( mWebView )
63
+ {
64
+ mWebView ->setUrl ( QString () );
65
+ }
66
+ #endif
67
+ clearPicture ();
68
+ return ;
69
+ }
70
+
59
71
QString filePath = fileName;
60
72
61
73
if ( QUrl ( fileName ).isRelative () )
@@ -98,6 +110,24 @@ void QgsPhotoWidgetWrapper::loadPixmap( const QString& fileName )
98
110
mPhotoLabel ->setPixmap ( pm );
99
111
}
100
112
}
113
+ else
114
+ {
115
+ clearPicture ();
116
+ }
117
+ }
118
+
119
+ void QgsPhotoWidgetWrapper::clearPicture ()
120
+ {
121
+ if ( mPhotoLabel )
122
+ {
123
+ mPhotoLabel ->clear ();
124
+ mPhotoLabel ->setMinimumSize ( QSize ( 0 , 0 ) );
125
+
126
+ if ( mPhotoPixmapLabel )
127
+ mPhotoPixmapLabel ->setPixmap ( QPixmap () );
128
+ else
129
+ mPhotoLabel ->setPixmap ( QPixmap () );
130
+ }
101
131
}
102
132
103
133
QVariant QgsPhotoWidgetWrapper::value () const
@@ -212,7 +242,10 @@ void QgsPhotoWidgetWrapper::setValue( const QVariant& value )
212
242
if ( mLineEdit )
213
243
{
214
244
if ( value.isNull () )
215
- mLineEdit ->setText ( QSettings ().value ( " qgis/nullValue" , " NULL" ).toString () );
245
+ {
246
+ whileBlocking ( mLineEdit )->setText ( QSettings ().value ( " qgis/nullValue" , " NULL" ).toString () );
247
+ clearPicture ();
248
+ }
216
249
else
217
250
mLineEdit ->setText ( value.toString () );
218
251
}
Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ class GUI_EXPORT QgsPhotoWidgetWrapper : public QgsEditorWidgetWrapper
78
78
QLineEdit* mLineEdit ;
79
79
// ! The button to open the file chooser dialog
80
80
QPushButton* mButton ;
81
+
82
+ void clearPicture ();
81
83
};
82
84
83
85
#endif // QGSPHOTOWIDGETWRAPPER_H
Original file line number Diff line number Diff line change @@ -142,7 +142,11 @@ void QgsExternalResourceWidget::updateDocumentViewer()
142
142
{
143
143
const QPixmap* pm = mPixmapLabel ->pixmap ();
144
144
145
- if ( pm )
145
+ if ( !pm || pm->isNull () )
146
+ {
147
+ mPixmapLabel ->setMinimumSize ( QSize ( 0 , 0 ) );
148
+ }
149
+ else
146
150
{
147
151
QSize size ( mDocumentViewerWidth , mDocumentViewerHeight );
148
152
if ( size.width () == 0 && size.height () > 0 )
@@ -165,7 +169,7 @@ void QgsExternalResourceWidget::updateDocumentViewer()
165
169
166
170
void QgsExternalResourceWidget::loadDocument ( const QString& path )
167
171
{
168
- if ( path.isNull () )
172
+ if ( path.isEmpty () )
169
173
{
170
174
#ifdef WITH_QTWEBKIT
171
175
if ( mDocumentViewerContent == Web )
@@ -176,6 +180,7 @@ void QgsExternalResourceWidget::loadDocument( const QString& path )
176
180
if ( mDocumentViewerContent == Image )
177
181
{
178
182
mPixmapLabel ->clear ();
183
+ updateDocumentViewer ();
179
184
}
180
185
}
181
186
@@ -190,12 +195,8 @@ void QgsExternalResourceWidget::loadDocument( const QString& path )
190
195
if ( mDocumentViewerContent == Image )
191
196
{
192
197
QPixmap pm ( path );
193
- if ( !pm.isNull () )
194
- {
195
- mPixmapLabel ->setPixmap ( pm );
196
-
197
- updateDocumentViewer ();
198
- }
198
+ mPixmapLabel ->setPixmap ( pm );
199
+ updateDocumentViewer ();
199
200
}
200
201
}
201
202
Original file line number Diff line number Diff line change @@ -24,17 +24,31 @@ QgsPixmapLabel::QgsPixmapLabel( QWidget *parent ) :
24
24
25
25
void QgsPixmapLabel::setPixmap ( const QPixmap & p )
26
26
{
27
+ bool sizeChanged = ( p.size () != mPixmap .size () );
27
28
mPixmap = p;
28
- QLabel::setPixmap ( p );
29
+
30
+ if ( sizeChanged )
31
+ {
32
+ updateGeometry ();
33
+ }
34
+
35
+ QLabel::setPixmap ( mPixmap .scaled ( this ->size (),
36
+ Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
29
37
}
30
38
31
39
int QgsPixmapLabel::heightForWidth ( int width ) const
32
40
{
41
+ if ( mPixmap .isNull () )
42
+ return 0 ;
43
+
33
44
return (( qreal )mPixmap .height ()*width ) / mPixmap .width ();
34
45
}
35
46
36
47
QSize QgsPixmapLabel::sizeHint () const
37
48
{
49
+ if ( mPixmap .isNull () )
50
+ return QSize ( 0 , 0 );
51
+
38
52
int w = this ->width ();
39
53
return QSize ( w, heightForWidth ( w ) );
40
54
}
You can’t perform that action at this time.
0 commit comments