Skip to content

Commit c5825aa

Browse files
committed
Code cleanup
1 parent 4059c9b commit c5825aa

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
157157

158158
// This block is needed because item->setCheckState triggers dataChanged gets back to value()
159159
// and iterate over all items again! This can be extremely slow on large items sets.
160-
mTableWidget->blockSignals( true );
161160
for ( int j = 0; j < mTableWidget->rowCount(); j++ )
162161
{
162+
auto signalBlockedTableWidget = whileBlocking( mTableWidget );
163+
Q_UNUSED( signalBlockedTableWidget )
164+
163165
for ( int i = 0; i < nofColumns; ++i )
164166
{
165167
QTableWidgetItem *item = mTableWidget->item( j, i );
@@ -170,7 +172,6 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
170172
}
171173
}
172174
}
173-
mTableWidget->blockSignals( false );
174175
// let's trigger the signal now, once and for all
175176
if ( lastChangedItem )
176177
lastChangedItem->setCheckState( checkList.contains( lastChangedItem->data( Qt::UserRole ).toString() ) ? Qt::Checked : Qt::Unchecked );
@@ -222,14 +223,14 @@ void QgsValueRelationWidgetWrapper::setFeature( const QgsFeature &feature )
222223
// and signals unblocked (we want this to propagate to the feature itself)
223224
if ( formFeature().isValid()
224225
&& ! formFeature().attribute( fieldIdx() ).isValid()
225-
&& mCache.size() > 0
226+
&& ! mCache.empty()
226227
&& ! config( QStringLiteral( "AllowNull" ) ).toBool( ) )
227228
{
228229
// This is deferred because at the time the feature is set in one widget it is not
229230
// set in the next, which is typically the "down" in a drill-down
230231
QTimer::singleShot( 0, [ = ]
231232
{
232-
setValue( mCache.at( 0 ).key );
233+
setValue( mCache.first().key );
233234
} );
234235
}
235236
}
@@ -246,7 +247,7 @@ void QgsValueRelationWidgetWrapper::populate( )
246247
{
247248
mCache = QgsValueRelationFieldFormatter::createCache( config( ), formFeature() );
248249
}
249-
else if ( mCache.isEmpty() )
250+
else if ( mCache.empty() )
250251
{
251252
mCache = QgsValueRelationFieldFormatter::createCache( config( ) );
252253
}
@@ -268,7 +269,7 @@ void QgsValueRelationWidgetWrapper::populate( )
268269
{
269270
const int nofColumns = columnCount();
270271

271-
if ( mCache.size() > 0 )
272+
if ( ! mCache.empty() )
272273
{
273274
mTableWidget->setRowCount( ( mCache.size() + nofColumns - 1 ) / nofColumns );
274275
}
@@ -277,7 +278,8 @@ void QgsValueRelationWidgetWrapper::populate( )
277278
mTableWidget->setColumnCount( nofColumns );
278279

279280
whileBlocking( mTableWidget )->clear();
280-
int row = 0, column = 0;
281+
int row = 0;
282+
int column = 0;
281283
for ( const QgsValueRelationFieldFormatter::ValueRelationItem &element : qgis::as_const( mCache ) )
282284
{
283285
if ( column == nofColumns )
@@ -340,7 +342,9 @@ void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
340342

341343
if ( mTableWidget )
342344
{
343-
mTableWidget->blockSignals( true );
345+
auto signalBlockedTableWidget = whileBlocking( mTableWidget );
346+
Q_UNUSED( signalBlockedTableWidget )
347+
344348
for ( int j = 0; j < mTableWidget->rowCount(); j++ )
345349
{
346350
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
@@ -355,7 +359,6 @@ void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
355359
}
356360
}
357361
}
358-
mTableWidget->blockSignals( false );
359362
}
360363
else
361364
QgsEditorWidgetWrapper::setEnabled( enabled );

0 commit comments

Comments
 (0)