Skip to content

Commit

Permalink
applied patch for extended data defined labels provided by Juergen
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@7297 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Oct 24, 2007
1 parent bced26a commit 50ba0c7
Show file tree
Hide file tree
Showing 4 changed files with 323 additions and 134 deletions.
5 changes: 5 additions & 0 deletions src/app/qgslabeldialog.cpp
Expand Up @@ -114,6 +114,10 @@ void QgsLabelDialog::init ( )
cboFontSizeField->insertStringList(myFieldStringList);
cboFontSizeField->setCurrentItem(itemNoForField(mLabel->labelField(QgsLabel::Size),myFieldStringList));

cboFontSizeTypeField->clear();
cboFontSizeTypeField->insertStringList(myFieldStringList);
cboFontSizeTypeField->setCurrentItem(itemNoForField(mLabel->labelField(QgsLabel::SizeType),myFieldStringList));

cboFontTransparencyField->clear();
cboFontTransparencyField->insertStringList(myFieldStringList);
//cboFontTransparencyField->setCurrentItem(itemNoForField(mLabel->labelField(QgsLabel::FontTransparency),myFieldStringList));
Expand Down Expand Up @@ -392,6 +396,7 @@ void QgsLabelDialog::apply()
mLabel->setLabelField( QgsLabel::Italic, fieldIndexFromName(cboItalicField->currentText()) );
mLabel->setLabelField( QgsLabel::Underline, fieldIndexFromName(cboUnderlineField->currentText()) );
mLabel->setLabelField( QgsLabel::Size, fieldIndexFromName(cboFontSizeField->currentText()) );
mLabel->setLabelField( QgsLabel::SizeType, fieldIndexFromName(cboFontSizeTypeField->currentText()) );
mLabel->setLabelField( QgsLabel::BufferSize, fieldIndexFromName(cboBufferSizeField->currentText()) );
//mLabel->setLabelField( QgsLabel::BufferTransparency, cboBufferTransparencyField->currentText() );
mLabel->setLabelField( QgsLabel::XCoordinate, fieldIndexFromName(cboXCoordinateField->currentText()) );
Expand Down
77 changes: 53 additions & 24 deletions src/core/qgslabel.cpp
Expand Up @@ -135,13 +135,26 @@ void QgsLabel::renderLabel( QPainter * painter, QgsRect &viewExtent,
{
size = value.toDouble();
}
if ( mLabelAttributes->sizeType() == QgsLabelAttributes::MapUnits )
int sizeType;
value = fieldValue ( SizeType, feature );
if( value.isEmpty() )
sizeType = mLabelAttributes->sizeType();
else
{
value = value.lower();
if( value.compare("mapunits") == 0 )
sizeType = QgsLabelAttributes::MapUnits;
else
sizeType = QgsLabelAttributes::PointUnits;
}
if ( sizeType == QgsLabelAttributes::MapUnits )
{
size *= scale;
} else {
size *= sizeScale;
}
font.setPointSizeFloat ( size );
if(size>0.0)
font.setPointSizeFloat ( size );

value = fieldValue ( Color, feature );
if ( value.isEmpty() )
Expand Down Expand Up @@ -215,23 +228,22 @@ void QgsLabel::renderLabel( QPainter * painter, QgsRect &viewExtent,
else
{
value = value.lower();
alignment = Qt::AlignCenter;
if ( value.compare("left") == 0 )
{
alignment = Qt::AlignLeft | Qt::AlignVCenter;
}
else if ( value.compare("right") == 0 )
{
alignment = Qt::AlignRight | Qt::AlignVCenter;
}
else if ( value.compare("bottom") == 0 )
{
alignment = Qt::AlignBottom | Qt::AlignHCenter;
}
else if ( value.compare("top") == 0 )
{
alignment = Qt::AlignTop | Qt::AlignHCenter;
}

alignment=0;

if ( value.contains("left") )
alignment |= Qt::AlignLeft;
else if( value.contains("right") )
alignment |= Qt::AlignRight;
else
alignment |= Qt::AlignHCenter;

if( value.contains("bottom") )
alignment |= Qt::AlignBottom;
else if( value.contains("top") )
alignment |= Qt::AlignTop;
else
alignment |= Qt::AlignVCenter;
}

if ( alignment & Qt::AlignLeft )
Expand Down Expand Up @@ -689,14 +701,22 @@ void QgsLabel::readXML( const QDomNode& node )

if ( scratchNode.isNull() )
{
QgsDebugMsg("couldn't find QgsLabel ``size'' attribute");
QgsDebugMsg("couldn't find QgsLabel ``size'' attribute");
}
else
{
el = scratchNode.toElement();
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
mLabelAttributes->setSize ( el.attribute("value", "0.0").toDouble(), type );
setLabelField ( Size, _elementFieldIndex(el) );
el = scratchNode.toElement();
if( !el.hasAttribute("unitfield") )
{
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
mLabelAttributes->setSize ( el.attribute("value", "0.0").toDouble(), type );
}
else
{
QString str = el.attribute("unitfield","");
setLabelField( SizeType, str=="" ? -1 : str.toInt() );
}
setLabelField ( Size, _elementFieldIndex(el) );
}

/* Bold */
Expand Down Expand Up @@ -940,9 +960,18 @@ void QgsLabel::writeXML(std::ostream& xml)
{
if (mLabelFieldIdx[Size] != -1)
{
if (mLabelFieldIdx[SizeType] != -1)
{
xml << "\t\t\t<size value=\"" << mLabelAttributes->size()
<< "\" unitfield=\"" << mLabelFieldIdx[SizeType]
<< "\" field=\"" << mLabelFieldIdx[Size] << "\" />\n";
}
else
{
xml << "\t\t\t<size value=\"" << mLabelAttributes->size()
<< "\" units=\"" << (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->sizeType()).utf8()
<< "\" field=\"" << mLabelFieldIdx[Size] << "\" />\n";
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/core/qgslabel.h
Expand Up @@ -55,6 +55,7 @@ class CORE_EXPORT QgsLabel
Text = 0,
Family,
Size,
SizeType,
Bold,
Italic,
Underline,
Expand Down

0 comments on commit 50ba0c7

Please sign in to comment.