Skip to content

Commit

Permalink
Fix Show/Hide Labels to allow NULL values in table to work for show v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
dakcarto committed Feb 9, 2013
1 parent 3676a38 commit 5967db9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/app/qgslabelpropertydialog.cpp
Expand Up @@ -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() );
Expand Down
23 changes: 10 additions & 13 deletions src/app/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -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();
Expand Down

0 comments on commit 5967db9

Please sign in to comment.