Skip to content
Permalink
Browse files

Remove hide label function from pin/unpin label tool

- More informative tool tips for labeling tools
  • Loading branch information
dakcarto committed Aug 13, 2012
1 parent 3dd05e6 commit ad6c9641612fa8011cf02cc9e07269371232ddbb
Showing with 16 additions and 62 deletions.
  1. +2 −56 src/app/qgsmaptoolpinlabels.cpp
  2. +0 −3 src/app/qgsmaptoolpinlabels.h
  3. +14 −3 src/ui/qgisapp.ui
@@ -258,7 +258,6 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent *

bool doUnpin = e->modifiers() & Qt::ShiftModifier ? true : false;
bool toggleUnpinOrPin = e->modifiers() & Qt::ControlModifier ? true : false;
bool doHide = ( doUnpin && toggleUnpinOrPin );

// get list of all drawn labels from all layers within, or touching, chosen extent
bool labelChanged = false;
@@ -315,7 +314,7 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent *
QString labelStringID = QString( "%0|%1" ).arg( mCurrentLabelPos.layerID, QString::number( mCurrentLabelPos.featureId ) );

// unpin label
if ( mCurrentLabelPos.isPinned && !doHide && ( doUnpin || toggleUnpinOrPin ) )
if ( mCurrentLabelPos.isPinned && ( doUnpin || toggleUnpinOrPin ) )
{
// unpin previously pinned label (set attribute table fields to NULL)
if ( pinUnpinLabel( vlayer, mCurrentLabelPos, false ) )
@@ -329,7 +328,7 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent *
}

// pin label
if ( !mCurrentLabelPos.isPinned && !doHide && ( !doUnpin || toggleUnpinOrPin ) )
if ( !mCurrentLabelPos.isPinned && ( !doUnpin || toggleUnpinOrPin ) )
{
// pin label's location, and optionally rotation, to attribute table
if ( pinUnpinLabel( vlayer, mCurrentLabelPos, true ) )
@@ -341,20 +340,6 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent *
QgsDebugMsg( QString( "Pin failed for layer, label: %0, %1" ).arg( labellyr, labeltxt ) );
}
}

// hide label
if ( doHide )
{
// write 0 font size to attribute table
if ( hideLabel( vlayer, mCurrentLabelPos ) )
{
labelChanged = true;
}
else
{
QgsDebugMsg( QString( "Hide failed for layer, label: %0, %1" ).arg( labellyr, labeltxt ) );
}
}
}

if ( labelChanged )
@@ -477,42 +462,3 @@ bool QgsMapToolPinLabels::pinUnpinLabel( QgsVectorLayer* vlayer,
}
return true;
}

bool QgsMapToolPinLabels::hideLabel( QgsVectorLayer* vlayer,
const QgsLabelPosition& labelpos )
{
// skip diagrams
if ( labelpos.isDiagram )
{
QgsDebugMsg( QString( "Label is diagram, skipping" ) );
return false;
}
// verify attribute table has proper fields setup
bool sizeColOk;
int sizeCol;

QVariant sizeColumn = vlayer->customProperty( "labeling/dataDefinedProperty0" );
if ( !sizeColumn.isValid() )
{
QgsDebugMsg( QString( "Size column not set" ) );
return false;
}
sizeCol = sizeColumn.toInt( &sizeColOk );
if ( !sizeColOk )
{
QgsDebugMsg( QString( "Size column not convertible to integer" ) );
return false;
}

// edit attribute table
int fid = labelpos.featureId;

vlayer->beginEditCommand( tr( "Label hidden" ) );
if ( !vlayer->changeAttributeValue( fid, sizeCol, 0, false ) )
{
QgsDebugMsg( QString( "Failed write to attribute table" ) );
return false;
}
vlayer->endEditCommand();
return true;
}
@@ -95,9 +95,6 @@ class QgsMapToolPinLabels: public QgsMapToolLabel
bool pinUnpinLabel( QgsVectorLayer* vlayer,
const QgsLabelPosition& labelpos,
bool pin );

//! Hide chosen label by setting font size to 0
bool hideLabel( QgsVectorLayer* vlayer, const QgsLabelPosition& labelpos );
};

#endif // QGSMAPTOOLPINLABELS_H
@@ -1087,6 +1087,9 @@
<property name="text">
<string>Labeling</string>
</property>
<property name="toolTip">
<string>Layer Labeling Options</string>
</property>
</action>
<action name="mActionNewVectorLayer">
<property name="icon">
@@ -1475,6 +1478,9 @@
<property name="text">
<string>Move Label</string>
</property>
<property name="toolTip">
<string>Move Label</string>
</property>
</action>
<action name="mActionRotateLabel">
<property name="checkable">
@@ -1487,6 +1493,10 @@
<property name="text">
<string>Rotate Label</string>
</property>
<property name="toolTip">
<string>Rotate Label
Ctl (Cmd) increments by 15 deg.</string>
</property>
</action>
<action name="mActionChangeLabelProperties">
<property name="checkable">
@@ -1722,8 +1732,8 @@
<property name="toolTip">
<string>Pin/Unpin Labels
Click or marquee on label to pin
Hold Shift to unpin
Hold Ctl (Cmd) to toggle pin/unpin state</string>
Shift unpins, Ctl (Cmd) toggles state
Acts on all editable layers</string>
</property>
</action>
<action name="mActionShowPinnedLabels">
@@ -1791,7 +1801,8 @@ Hold Ctl (Cmd) to toggle pin/unpin state</string>
<property name="toolTip">
<string>Show/Hide Labels
Click or marquee on feature to show label
Hold Shift+click or marquee on label to hide it</string>
Shift+click or marquee on label to hide it
Acts on currently active editable layer</string>
</property>
</action>
</widget>

0 comments on commit ad6c964

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