Skip to content
Permalink
Browse files
Use new vector edit macro support to batch Show/Hide Label tool's ope…
…ration
  • Loading branch information
dakcarto committed Feb 11, 2013
1 parent 2de2f23 commit dd1bb457d2bc0a7f281f1ae97bae6b309e49179d
Showing with 11 additions and 4 deletions.
  1. +11 −4 src/app/qgsmaptoolshowhidelabels.cpp
@@ -156,9 +156,15 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )

QgsDebugMsg( "Number of selected labels or features: " + QString::number( selectedFeatIds.size() ) );

if ( selectedFeatIds.isEmpty() )
{
return;
}

bool labelChanged = false;
QString editTxt = doHide ? tr( "Hid labels" ) : tr( "Showed labels" );

vlayer->beginEditCommand( editTxt );
foreach ( const QgsFeatureId &fid, selectedFeatIds )
{
if ( showHideLabel( vlayer, fid, doHide ) )
@@ -167,11 +173,16 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent * e )
labelChanged = true;
}
}
vlayer->endEditCommand();

if ( labelChanged )
{
mCanvas->refresh();
}
else
{
vlayer->destroyEditCommand();
}
}

bool QgsMapToolShowHideLabels::selectedFeatures( QgsVectorLayer* vlayer,
@@ -294,14 +305,10 @@ bool QgsMapToolShowHideLabels::showHideLabel( QgsVectorLayer* vlayer,
}

// different attribute value, edit table
QString editTxt = hide ? tr( "Hid label" ) : tr( "Showed label" );
vlayer->beginEditCommand( editTxt );
if ( !vlayer->changeAttributeValue( fid, showCol, curVal, false ) )
{
QgsDebugMsg( "Failed write to attribute table" );
vlayer->endEditCommand();
return false;
}
vlayer->endEditCommand();
return true;
}

0 comments on commit dd1bb45

Please sign in to comment.