@@ -157,9 +157,11 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
157
157
158
158
// This block is needed because item->setCheckState triggers dataChanged gets back to value()
159
159
// and iterate over all items again! This can be extremely slow on large items sets.
160
- mTableWidget ->blockSignals ( true );
161
160
for ( int j = 0 ; j < mTableWidget ->rowCount (); j++ )
162
161
{
162
+ auto signalBlockedTableWidget = whileBlocking ( mTableWidget );
163
+ Q_UNUSED ( signalBlockedTableWidget )
164
+
163
165
for ( int i = 0 ; i < nofColumns; ++i )
164
166
{
165
167
QTableWidgetItem *item = mTableWidget ->item ( j, i );
@@ -170,7 +172,6 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
170
172
}
171
173
}
172
174
}
173
- mTableWidget ->blockSignals ( false );
174
175
// let's trigger the signal now, once and for all
175
176
if ( lastChangedItem )
176
177
lastChangedItem->setCheckState ( checkList.contains ( lastChangedItem->data ( Qt::UserRole ).toString () ) ? Qt::Checked : Qt::Unchecked );
@@ -222,14 +223,14 @@ void QgsValueRelationWidgetWrapper::setFeature( const QgsFeature &feature )
222
223
// and signals unblocked (we want this to propagate to the feature itself)
223
224
if ( formFeature ().isValid ()
224
225
&& ! formFeature ().attribute ( fieldIdx () ).isValid ()
225
- && mCache .size () > 0
226
+ && ! mCache .empty ()
226
227
&& ! config ( QStringLiteral ( " AllowNull" ) ).toBool ( ) )
227
228
{
228
229
// This is deferred because at the time the feature is set in one widget it is not
229
230
// set in the next, which is typically the "down" in a drill-down
230
231
QTimer::singleShot ( 0 , [ = ]
231
232
{
232
- setValue ( mCache .at ( 0 ).key );
233
+ setValue ( mCache .first ( ).key );
233
234
} );
234
235
}
235
236
}
@@ -246,7 +247,7 @@ void QgsValueRelationWidgetWrapper::populate( )
246
247
{
247
248
mCache = QgsValueRelationFieldFormatter::createCache ( config ( ), formFeature () );
248
249
}
249
- else if ( mCache .isEmpty () )
250
+ else if ( mCache .empty () )
250
251
{
251
252
mCache = QgsValueRelationFieldFormatter::createCache ( config ( ) );
252
253
}
@@ -268,7 +269,7 @@ void QgsValueRelationWidgetWrapper::populate( )
268
269
{
269
270
const int nofColumns = columnCount ();
270
271
271
- if ( mCache .size () > 0 )
272
+ if ( ! mCache .empty () )
272
273
{
273
274
mTableWidget ->setRowCount ( ( mCache .size () + nofColumns - 1 ) / nofColumns );
274
275
}
@@ -277,7 +278,8 @@ void QgsValueRelationWidgetWrapper::populate( )
277
278
mTableWidget ->setColumnCount ( nofColumns );
278
279
279
280
whileBlocking ( mTableWidget )->clear ();
280
- int row = 0 , column = 0 ;
281
+ int row = 0 ;
282
+ int column = 0 ;
281
283
for ( const QgsValueRelationFieldFormatter::ValueRelationItem &element : qgis::as_const ( mCache ) )
282
284
{
283
285
if ( column == nofColumns )
@@ -340,7 +342,9 @@ void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
340
342
341
343
if ( mTableWidget )
342
344
{
343
- mTableWidget ->blockSignals ( true );
345
+ auto signalBlockedTableWidget = whileBlocking ( mTableWidget );
346
+ Q_UNUSED ( signalBlockedTableWidget )
347
+
344
348
for ( int j = 0 ; j < mTableWidget ->rowCount (); j++ )
345
349
{
346
350
for ( int i = 0 ; i < mTableWidget ->columnCount (); ++i )
@@ -355,7 +359,6 @@ void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
355
359
}
356
360
}
357
361
}
358
- mTableWidget ->blockSignals ( false );
359
362
}
360
363
else
361
364
QgsEditorWidgetWrapper::setEnabled ( enabled );
0 commit comments