Skip to content

Commit

Permalink
[needs-docs][labeling] When using the Show/Hide Label tool, a single
Browse files Browse the repository at this point in the history
click on a label toggles this label

Unlike in marquee mode, where users must hold ctrl while dragging
over labels to hide them, when only a click on an existing label
is made we trigger a toggle of the label. It's a more intuitive
UX.
  • Loading branch information
nyalldawson committed Jul 23, 2019
1 parent 45b23fd commit d8a3031
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/app/qgsmaptoolshowhidelabels.cpp
Expand Up @@ -136,7 +136,39 @@ void QgsMapToolShowHideLabels::showHideLabels( QMouseEvent *e )
vlayer->beginEditCommand( editTxt );

bool labelChanged = false;
if ( doHide )
if ( !mDragging )
{
// if single click only, clicking on an existing label hides it, while clicking on a feature shows it
QList<QgsLabelPosition> positions;
if ( selectedLabelFeatures( vlayer, positions ) )
{
// clicked on a label
if ( showHide( positions.at( 0 ), false ) )
labelChanged = true;
}
else
{
// clicked on a feature
QgsFeatureIds fids;
if ( selectedFeatures( vlayer, fids ) )
{
QgsLabelPosition pos;
pos.featureId = *fids.constBegin();
pos.layerID = vlayer->id();

// we want to show labels...
pos.isDiagram = false;
if ( showHide( pos, true ) )
labelChanged = true;

// ... and diagrams
pos.isDiagram = true;
if ( showHide( pos, true ) )
labelChanged = true;
}
}
}
else if ( doHide )
{
QList<QgsLabelPosition> positions;
if ( selectedLabelFeatures( vlayer, positions ) )
Expand Down Expand Up @@ -228,7 +260,7 @@ bool QgsMapToolShowHideLabels::selectedFeatures( QgsVectorLayer *vlayer,

QApplication::restoreOverrideCursor();

return true;
return !selectedFeatIds.empty();
}

bool QgsMapToolShowHideLabels::selectedLabelFeatures( QgsVectorLayer *vlayer,
Expand Down Expand Up @@ -265,7 +297,7 @@ bool QgsMapToolShowHideLabels::selectedLabelFeatures( QgsVectorLayer *vlayer,

QApplication::restoreOverrideCursor();

return true;
return !listPos.empty();
}

bool QgsMapToolShowHideLabels::showHide( const QgsLabelPosition &pos, bool show )
Expand Down

0 comments on commit d8a3031

Please sign in to comment.