Skip to content
Permalink
Browse files

applied patch for extended data defined labels provided by Juergen

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7297 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Oct 24, 2007
1 parent 09a075b commit fa1a8bc323bbd1d9dcd5fb5922a007dc9cc2b29f
Showing with 323 additions and 134 deletions.
  1. +5 −0 src/app/qgslabeldialog.cpp
  2. +53 −24 src/core/qgslabel.cpp
  3. +1 −0 src/core/qgslabel.h
  4. +264 −110 src/ui/qgslabeldialogbase.ui
@@ -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));
@@ -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()) );
@@ -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() )
@@ -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 )
@@ -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 */
@@ -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
{
@@ -55,6 +55,7 @@ class CORE_EXPORT QgsLabel
Text = 0,
Family,
Size,
SizeType,
Bold,
Italic,
Underline,

0 comments on commit fa1a8bc

Please sign in to comment.
You can’t perform that action at this time.