Update to freeze/thaw label tool

Added ability to hide label(s), i.e. set font size to 0, by holding Ctl (Cmd on Mac) modifier key.
This is a temporary convenience function, until there is a specifically mapped field for showing/hiding a label.
Silently fails if no font size field is mapped.

Dropped What's This? text in favor of concise tool tip for freeze/thaw tool.

Added self to CONTRIBUTORS. Stripped trailing whitespace from that file.
This commit is contained in:
Larry Shaffer 2012-07-20 04:11:30 -06:00
parent b6380b7f32
commit 28021ef0c5
4 changed files with 65 additions and 13 deletions

View File

@ -29,9 +29,10 @@ Giuseppe Sucameli
Horst Duester
Hyao (IRC nickname)
Ivan Lucena
Jean-Denis Giguere
Jean-Denis Giguere
Jeremy Palmer
Jerrit Collord
Larry Shaffer
Luiz Motta
Magnus Homann
Marco Pasetti
@ -53,5 +54,5 @@ Tamas Szekeres
Tom Russo
Tyler Mitchell
Vita Cizek
Yann Chemin
Yann Chemin
Includes Map icons CC-0 from SJJB Management

View File

@ -258,6 +258,7 @@ void QgsMapToolFreezeLabels::freezeThawLabels( const QgsRectangle& ext, QMouseEv
bool doThaw = e->modifiers() & Qt::ShiftModifier ? true : false;
bool toggleThawOrFreeze = e->modifiers() & Qt::AltModifier ? true : false;
bool doHide = e->modifiers() & Qt::ControlModifier ? true : false;
// get list of all drawn labels from all layers within, or touching, chosen extent
bool labelChanged = false;
@ -314,9 +315,8 @@ void QgsMapToolFreezeLabels::freezeThawLabels( const QgsRectangle& ext, QMouseEv
QString labelStringID = QString("%0|%1").arg(mCurrentLabelPos.layerID, QString::number( mCurrentLabelPos.featureId ) );
// thaw label
if ( mCurrentLabelPos.isFrozen && ( doThaw || toggleThawOrFreeze ) )
if ( mCurrentLabelPos.isFrozen && !doHide && ( doThaw || toggleThawOrFreeze ) )
{
// thaw previously frozen label (set attribute table fields to NULL)
if ( freezeThawLabel( vlayer, mCurrentLabelPos, false ) )
{
@ -329,9 +329,8 @@ void QgsMapToolFreezeLabels::freezeThawLabels( const QgsRectangle& ext, QMouseEv
}
// freeze label
if ( !mCurrentLabelPos.isFrozen && ( !doThaw || toggleThawOrFreeze ) )
if ( !mCurrentLabelPos.isFrozen && !doHide && ( !doThaw || toggleThawOrFreeze ) )
{
// freeze label's location, and optionally rotation, to attribute table
if ( freezeThawLabel( vlayer, mCurrentLabelPos, true ) )
{
@ -342,6 +341,20 @@ void QgsMapToolFreezeLabels::freezeThawLabels( const QgsRectangle& ext, QMouseEv
QgsDebugMsg( QString( "Freeze 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 )
@ -479,3 +492,42 @@ bool QgsMapToolFreezeLabels::freezeThawLabel( QgsVectorLayer* vlayer,
}
return true;
}
bool QgsMapToolFreezeLabels::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;
}

View File

@ -95,6 +95,9 @@ class QgsMapToolFreezeLabels: public QgsMapToolLabel
bool freezeThawLabel( QgsVectorLayer* vlayer,
const QgsLabelPosition& labelpos,
bool freeze );
//! Hide chosen label by setting font size to 0
bool hideLabel( QgsVectorLayer* vlayer, const QgsLabelPosition& labelpos );
};
#endif // QGSMAPTOOLFREEZELABELS_H

View File

@ -1716,13 +1716,9 @@
<property name="text">
<string>Freeze or Thaw Labels</string>
</property>
<property name="whatsThis">
<string>Freeze (write label location and optionally rotation) to attribute table.
Click on individual labels, or draw a marquee (labels touching will be included). Actions on in-memory attribute table fields are immediate.
Hold Shift key down to Thaw (write NULLs to attribute table), reverting label to dynamic.
Hold Alt key down to toggle selected labels between Frozen and Thawed states.</string>
<property name="toolTip">
<string>Freeze or Thaw Labels
Shift thaws, Alt toggles, Ctl (Cmd) hides</string>
</property>
</action>
<action name="mActionShowFrozenLabels">