Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 ad6c964
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 62 deletions.
58 changes: 2 additions & 56 deletions src/app/qgsmaptoolpinlabels.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 )
Expand Down Expand Up @@ -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;
}
3 changes: 0 additions & 3 deletions src/app/qgsmaptoolpinlabels.h
Expand Up @@ -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
17 changes: 14 additions & 3 deletions src/ui/qgisapp.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand All @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit ad6c964

Please sign in to comment.