Skip to content

Commit

Permalink
[FEATURE] label only selected features (implements #2717)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13510 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 16, 2010
1 parent 3bba708 commit ff37ae3
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 44 deletions.
6 changes: 6 additions & 0 deletions python/core/qgslabelattributes.sip
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,11 @@ public:

bool multilineEnabled() const;
void setMultilineEnabled( bool useMultiline );

/* label only selected features
* added in 1.5
*/
bool selectedOnly() const;
void setSelectedOnly( bool selectedonly );
};

3 changes: 3 additions & 0 deletions src/app/qgslabeldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ void QgsLabelDialog::init( )
}
//set the state of the multiline enabled checkbox
chkUseMultiline->setChecked( myLabelAttributes->multilineEnabled() );
//set the state of the selected features only checkbox
chkSelectedOnly->setChecked( myLabelAttributes->selectedOnly() );
//set the state of the buffer enabled checkbox
chkUseBuffer->setChecked( myLabelAttributes->bufferEnabled() );

Expand Down Expand Up @@ -373,6 +375,7 @@ void QgsLabelDialog::apply()
if ( radioOver->isChecked() ) myLabelAttributes->setAlignment( Qt::AlignCenter );

myLabelAttributes->setMultilineEnabled( chkUseMultiline->isChecked() );
myLabelAttributes->setSelectedOnly( chkSelectedOnly->isChecked() );
myLabelAttributes->setBufferEnabled( chkUseBuffer->isChecked() );
myLabelAttributes->setBufferColor( mBufferColor );
myTypeInt = cboBufferSizeUnits->currentIndex() == 0 ? QgsLabelAttributes::PointUnits : QgsLabelAttributes::MapUnits;
Expand Down
27 changes: 26 additions & 1 deletion src/core/qgslabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ void QgsLabel::renderLabel( QgsRenderContext &renderContext,
QgsFeature &feature, bool selected,
QgsLabelAttributes *classAttributes )
{
if ( mLabelAttributes->selectedOnly() && !selected )
return;

QPen pen;
QFont font;
QString value;
Expand Down Expand Up @@ -414,7 +417,6 @@ void QgsLabel::renderLabel( QgsRenderContext &renderContext,
x = x + xoffset * cos( rad ) - yoffset * sin( rad );
y = y - xoffset * sin( rad ) - yoffset * cos( rad );


painter->save();
painter->setFont( font );
painter->translate( x, y );
Expand Down Expand Up @@ -1017,6 +1019,18 @@ void QgsLabel::readXML( const QDomNode& node )
readLabelField( el, MultilineEnabled );
}

scratchNode = node.namedItem( "selectedonly" );

if ( scratchNode.isNull() )
{
QgsDebugMsg( "couldn't find QgsLabel ``selectedonly'' attribute" );
}
else
{
el = scratchNode.toElement();
mLabelAttributes->setSelectedOnly(( bool )el.attribute( "on", "0" ).toInt() );
}

} // QgsLabel::readXML()


Expand Down Expand Up @@ -1357,6 +1371,17 @@ void QgsLabel::writeXML( QDomNode & layer_node, QDomDocument & document ) const
}
labelattributes.appendChild( multilineenabled );

QDomElement selectedonly = document.createElement( "selectedonly" );
if ( mLabelAttributes->selectedOnly() )
{
selectedonly.setAttribute( "on", mLabelAttributes->selectedOnly() );
}
else
{
selectedonly.setAttribute( "on", "" );
}
labelattributes.appendChild( selectedonly );

layer_node.appendChild( labelattributes );
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgslabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CORE_EXPORT QgsLabel
BorderColor,
BorderStyle,
MultilineEnabled,
StrikeOut, // added in 1.5
StrikeOut, // added in 1.5
LabelFieldCount
};

Expand Down
69 changes: 40 additions & 29 deletions src/core/qgslabelattributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,36 @@
#include "qgslogger.h"

QgsLabelAttributes::QgsLabelAttributes( bool def )
: mTextIsSet( false ),
mFamilyIsSet( false ),
mBoldIsSet( false ),
mItalicIsSet( false ),
mUnderlineIsSet( false ),
mStrikeOutIsSet( false ),
mSizeType( 0 ),
mSize( 0.0 ),
mSizeIsSet( false ),
mColorIsSet( false ),
mOffsetType( 0 ),
mXOffset( 0 ),
mYOffset( 0 ),
mOffsetIsSet( false ),
mAngle( 0.0 ),
mAngleIsSet( false ),
mAngleIsAuto( false ),
mAlignment( 0 ),
mAlignmentIsSet( false ),
mBufferEnabledFlag( false ),
mBufferSizeType( 0 ),
mBufferSize( 0.0 ),
mBufferSizeIsSet( false ),
mBufferColorIsSet( false ),
mBufferStyleIsSet( false ),
mBorderColorIsSet( false ),
mBorderWidthIsSet( false ),
mBorderStyleIsSet( false ),
mMultilineEnabledFlag( false )
: mTextIsSet( false )
, mFamilyIsSet( false )
, mBoldIsSet( false )
, mItalicIsSet( false )
, mUnderlineIsSet( false )
, mStrikeOutIsSet( false )
, mSizeType( 0 )
, mSize( 0.0 )
, mSizeIsSet( false )
, mColorIsSet( false )
, mOffsetType( 0 )
, mXOffset( 0 )
, mYOffset( 0 )
, mOffsetIsSet( false )
, mAngle( 0.0 )
, mAngleIsSet( false )
, mAngleIsAuto( false )
, mAlignment( 0 )
, mAlignmentIsSet( false )
, mBufferEnabledFlag( false )
, mBufferSizeType( 0 )
, mBufferSize( 0.0 )
, mBufferSizeIsSet( false )
, mBufferColorIsSet( false )
, mBufferStyleIsSet( false )
, mBorderColorIsSet( false )
, mBorderWidthIsSet( false )
, mBorderStyleIsSet( false )
, mMultilineEnabledFlag( false )
, mSelectedOnly( false )
{

if ( def ) // set defaults
Expand Down Expand Up @@ -429,6 +430,16 @@ void QgsLabelAttributes::setMultilineEnabled( bool useMultilineFlag )
mMultilineEnabledFlag = useMultilineFlag;
}

/* selected only */
bool QgsLabelAttributes::selectedOnly() const
{
return mSelectedOnly;
}
void QgsLabelAttributes::setSelectedOnly( bool selectedOnly )
{
mSelectedOnly = selectedOnly;
}

/* units */
QString QgsLabelAttributes::unitsName( int units )
{
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgslabelattributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ class CORE_EXPORT QgsLabelAttributes
bool multilineEnabled() const;
void setMultilineEnabled( bool useMultiline );

/* label only selected features
* added in 1.5
*/
bool selectedOnly() const;
void setSelectedOnly( bool selectedonly );

protected:
/* Text */
QString mText;
Expand Down Expand Up @@ -242,6 +248,9 @@ class CORE_EXPORT QgsLabelAttributes

/** Multiline enablement */
bool mMultilineEnabledFlag;

/** Label only selected */
bool mSelectedOnly;
};

#endif
32 changes: 19 additions & 13 deletions src/ui/qgslabeldialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<x>0</x>
<y>0</y>
<width>525</width>
<height>512</height>
<height>510</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
Expand Down Expand Up @@ -420,16 +420,6 @@
</item>
</widget>
</item>
<item row="6" column="2">
<widget class="QCheckBox" name="chkUseMultiline">
<property name="text">
<string>Multiline labels?</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="btnDefaultFont">
<property name="sizePolicy">
Expand All @@ -456,6 +446,23 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="chkUseMultiline">
<property name="text">
<string>Multiline labels?</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="2" colspan="2">
<widget class="QCheckBox" name="chkSelectedOnly">
<property name="text">
<string>Label only selected features</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -484,7 +491,7 @@
<x>0</x>
<y>0</y>
<width>525</width>
<height>623</height>
<height>592</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
Expand Down Expand Up @@ -886,7 +893,6 @@
<tabstop>cboFontSizeUnits</tabstop>
<tabstop>btnDefaultFont</tabstop>
<tabstop>spinAngle</tabstop>
<tabstop>chkUseMultiline</tabstop>
<tabstop>pbnDefaultFontColor</tabstop>
<tabstop>radioOver</tabstop>
<tabstop>radioAboveLeft</tabstop>
Expand Down

0 comments on commit ff37ae3

Please sign in to comment.