Skip to content
Permalink
Browse files
Fix Show/Hide Labels to allow NULL values in table to work for show v…
…alue
  • Loading branch information
dakcarto committed Feb 9, 2013
1 parent 3676a38 commit 5967db9bd6e858cbd1677372d893514fd7cad8e6
Showing with 15 additions and 14 deletions.
  1. +5 −1 src/app/qgslabelpropertydialog.cpp
  2. +10 −13 src/app/qgsmaptoolshowhidelabels.cpp
@@ -120,9 +120,13 @@ void QgsLabelPropertyDialog::init( const QString& layerId, int featureId, const
switch ( propIt.key() )
{
case QgsPalLayerSettings::Show:
{ // new scope to assign variables
mShowLabelChkbx->setEnabled( true );
mShowLabelChkbx->setChecked( mCurLabelFeat.attribute( propIt.value() ).toInt() != 0 );
bool showSuccess;
int showLabel = mCurLabelFeat.attribute( propIt.value() ).toInt( &showSuccess );
mShowLabelChkbx->setChecked( !showSuccess || showLabel != 0 );
break;
}
case QgsPalLayerSettings::AlwaysShow:
mAlwaysShowChkbx->setEnabled( true );
mAlwaysShowChkbx->setChecked( mCurLabelFeat.attribute( propIt.value() ).toBool() );
@@ -271,35 +271,32 @@ bool QgsMapToolShowHideLabels::showHideLabel( QgsVectorLayer* vlayer,
// verify attribute table has proper field setup
bool showSuccess;
int showCol;
int show;
int showVal;

if ( !dataDefinedShowHide( vlayer, fid, show, showSuccess, showCol ) )
if ( !dataDefinedShowHide( vlayer, fid, showVal, showSuccess, showCol ) )
{
return false;
}

int curVal = hide ? 0 : 1;

// check if attribute value is already the same
QgsFeature f;
if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) )
if ( showSuccess && showVal == curVal )
{
return false;
}

int colVal = hide ? 0 : 1;
QVariant fQVal = f.attributes()[showCol];
bool convToInt;
int fVal = fQVal.toInt( &convToInt );

if ( !convToInt || fVal == colVal )
// allow NULL (maybe default) value to stand for show label (i.e. 1)
// skip NULL attributes if trying to show label
if ( !showSuccess && curVal == 1 )
{
return false;
}

// different attribute value, edit table
QString labelText = currentLabelText( 24 );
QString editTxt = hide ? tr( "Hid label" ) : tr( "Showed label" );
vlayer->beginEditCommand( editTxt + QString( " '%1'" ).arg( labelText ) );
if ( !vlayer->changeAttributeValue( fid, showCol, colVal, true ) )
vlayer->beginEditCommand( editTxt );
if ( !vlayer->changeAttributeValue( fid, showCol, curVal, false ) )
{
QgsDebugMsg( "Failed write to attribute table" );
vlayer->endEditCommand();

0 comments on commit 5967db9

Please sign in to comment.