Skip to content
Permalink
Browse files
[FEATURE] label only selected features (implements #2717)
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 ff37ae312bda728068222b39c9fa15fd3bc9b10c
@@ -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 );
};

@@ -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() );

@@ -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;
@@ -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;
@@ -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 );
@@ -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()


@@ -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 );
}

@@ -81,7 +81,7 @@ class CORE_EXPORT QgsLabel
BorderColor,
BorderStyle,
MultilineEnabled,
StrikeOut, // added in 1.5
StrikeOut, // added in 1.5
LabelFieldCount
};

@@ -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
@@ -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 )
{
@@ -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;
@@ -242,6 +248,9 @@ class CORE_EXPORT QgsLabelAttributes

/** Multiline enablement */
bool mMultilineEnabledFlag;

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

#endif
@@ -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">
@@ -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">
@@ -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>
@@ -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">
@@ -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>

0 comments on commit ff37ae3

Please sign in to comment.