Skip to content
Permalink
Browse files

Merge pull request #7274 from m-kuhn/raii

Code cleanup
  • Loading branch information
m-kuhn committed Jun 20, 2018
2 parents 77d2284 + bf4604f commit 2778266be9e764596a1ae665b4ba108104fa38dc
Showing with 12 additions and 9 deletions.
  1. +12 −9 src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
@@ -157,9 +157,11 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )

// This block is needed because item->setCheckState triggers dataChanged gets back to value()
// and iterate over all items again! This can be extremely slow on large items sets.
mTableWidget->blockSignals( true );
for ( int j = 0; j < mTableWidget->rowCount(); j++ )
{
auto signalBlockedTableWidget = whileBlocking( mTableWidget );
Q_UNUSED( signalBlockedTableWidget )

for ( int i = 0; i < nofColumns; ++i )
{
QTableWidgetItem *item = mTableWidget->item( j, i );
@@ -170,7 +172,6 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant &value )
}
}
}
mTableWidget->blockSignals( false );
// let's trigger the signal now, once and for all
if ( lastChangedItem )
lastChangedItem->setCheckState( checkList.contains( lastChangedItem->data( Qt::UserRole ).toString() ) ? Qt::Checked : Qt::Unchecked );
@@ -222,12 +223,12 @@ void QgsValueRelationWidgetWrapper::setFeature( const QgsFeature &feature )
// and signals unblocked (we want this to propagate to the feature itself)
if ( formFeature().isValid()
&& ! formFeature().attribute( fieldIdx() ).isValid()
&& mCache.size() > 0
&& ! mCache.empty()
&& ! config( QStringLiteral( "AllowNull" ) ).toBool( ) )
{
// This is deferred because at the time the feature is set in one widget it is not
// set in the next, which is typically the "down" in a drill-down
QTimer::singleShot( 0, [ = ]
QTimer::singleShot( 0, [ this ]
{
setValue( mCache.at( 0 ).key );
} );
@@ -246,7 +247,7 @@ void QgsValueRelationWidgetWrapper::populate( )
{
mCache = QgsValueRelationFieldFormatter::createCache( config( ), formFeature() );
}
else if ( mCache.isEmpty() )
else if ( mCache.empty() )
{
mCache = QgsValueRelationFieldFormatter::createCache( config( ) );
}
@@ -268,7 +269,7 @@ void QgsValueRelationWidgetWrapper::populate( )
{
const int nofColumns = columnCount();

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

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

if ( mTableWidget )
{
mTableWidget->blockSignals( true );
auto signalBlockedTableWidget = whileBlocking( mTableWidget );
Q_UNUSED( signalBlockedTableWidget )

for ( int j = 0; j < mTableWidget->rowCount(); j++ )
{
for ( int i = 0; i < mTableWidget->columnCount(); ++i )
@@ -355,7 +359,6 @@ void QgsValueRelationWidgetWrapper::setEnabled( bool enabled )
}
}
}
mTableWidget->blockSignals( false );
}
else
QgsEditorWidgetWrapper::setEnabled( enabled );

0 comments on commit 2778266

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