Skip to content

Commit

Permalink
Fixed a problem with incorrectly loaded labeling attributes.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@7123 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Aug 5, 2007
1 parent 4ee8f44 commit 591cceb
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/core/qgslabel.cpp
Expand Up @@ -637,6 +637,15 @@ unsigned char* QgsLabel::labelPoint ( QgsPoint& point, unsigned char* geom)
return nextFeature;
}

static int _elementFieldIndex(QDomElement& el)
{
QString str = el.attribute("field","");
if (str == "")
return -1;
else
return str.toInt();
}

void QgsLabel::readXML( const QDomNode& node )
{
QgsDebugMsg(" called for layer label properties, got node " + node.nodeName());
Expand All @@ -658,7 +667,7 @@ void QgsLabel::readXML( const QDomNode& node )
{
el = scratchNode.toElement();
mLabelAttributes->setText ( el.attribute("text","") );
setLabelField ( Text, el.attribute("field","").toInt() );
setLabelField ( Text, _elementFieldIndex(el) );
}

/* Family */
Expand All @@ -672,7 +681,7 @@ void QgsLabel::readXML( const QDomNode& node )
{
el = scratchNode.toElement();
mLabelAttributes->setFamily ( el.attribute("name","") );
setLabelField ( Family, el.attribute("field","").toInt() );
setLabelField ( Family, _elementFieldIndex(el) );
}

/* Size */
Expand All @@ -687,7 +696,7 @@ void QgsLabel::readXML( const QDomNode& node )
el = scratchNode.toElement();
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
mLabelAttributes->setSize ( el.attribute("value", "0.0").toDouble(), type );
setLabelField ( Size, el.attribute("field","").toInt() );
setLabelField ( Size, _elementFieldIndex(el) );
}

/* Bold */
Expand All @@ -701,7 +710,7 @@ void QgsLabel::readXML( const QDomNode& node )
{
el = scratchNode.toElement();
mLabelAttributes->setBold ( (bool)el.attribute("on","0").toInt() );
setLabelField ( Bold, el.attribute("field","").toInt() );
setLabelField ( Bold, _elementFieldIndex(el) );
}

/* Italic */
Expand All @@ -715,7 +724,7 @@ void QgsLabel::readXML( const QDomNode& node )
{
el = scratchNode.toElement();
mLabelAttributes->setItalic ( (bool)el.attribute("on","0").toInt() );
setLabelField ( Italic, el.attribute("field","").toInt() );
setLabelField ( Italic, _elementFieldIndex(el) );
}

/* Underline */
Expand All @@ -729,7 +738,7 @@ void QgsLabel::readXML( const QDomNode& node )
{
el = scratchNode.toElement();
mLabelAttributes->setUnderline ( (bool)el.attribute("on","0").toInt() );
setLabelField ( Underline, el.attribute("field","").toInt() );
setLabelField ( Underline, _elementFieldIndex(el) );
}

/* Color */
Expand All @@ -749,7 +758,7 @@ void QgsLabel::readXML( const QDomNode& node )

mLabelAttributes->setColor( QColor(red, green, blue) );

setLabelField ( Color, el.attribute("field","").toInt() );
setLabelField ( Color, _elementFieldIndex(el) );
}

/* X */
Expand All @@ -762,7 +771,7 @@ void QgsLabel::readXML( const QDomNode& node )
else
{
el = scratchNode.toElement();
setLabelField ( XCoordinate, el.attribute("field","").toInt() );
setLabelField ( XCoordinate, _elementFieldIndex(el) );
}

/* Y */
Expand All @@ -775,7 +784,7 @@ void QgsLabel::readXML( const QDomNode& node )
else
{
el = scratchNode.toElement();
setLabelField ( YCoordinate, el.attribute("field","").toInt() );
setLabelField ( YCoordinate, _elementFieldIndex(el) );
}


Expand Down Expand Up @@ -812,7 +821,7 @@ void QgsLabel::readXML( const QDomNode& node )
{
el = scratchNode.toElement();
mLabelAttributes->setAngle ( el.attribute("value","0.0").toDouble() );
setLabelField ( Angle, el.attribute("field","0").toInt() );
setLabelField ( Angle, _elementFieldIndex(el) );
}

/* Alignment */
Expand All @@ -826,7 +835,7 @@ void QgsLabel::readXML( const QDomNode& node )
{
el = scratchNode.toElement();
mLabelAttributes->setAlignment ( QgsLabelAttributes::alignmentCode(el.attribute("value","")) );
setLabelField ( Alignment, el.attribute("field","").toInt() );
setLabelField ( Alignment, _elementFieldIndex(el) );
}


Expand All @@ -846,7 +855,7 @@ void QgsLabel::readXML( const QDomNode& node )
blue = el.attribute("blue","0").toInt();

mLabelAttributes->setBufferColor( QColor(red, green, blue) );
setLabelField ( BufferColor, el.attribute("field","").toInt() );
setLabelField ( BufferColor, _elementFieldIndex(el) );
}

scratchNode = node.namedItem("buffersize");
Expand All @@ -861,7 +870,7 @@ void QgsLabel::readXML( const QDomNode& node )

type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
mLabelAttributes->setBufferSize ( el.attribute("value","0.0").toDouble(), type );
setLabelField ( BufferSize, el.attribute("field","").toInt() );
setLabelField ( BufferSize, _elementFieldIndex(el) );
}

scratchNode = node.namedItem("bufferenabled");
Expand All @@ -875,7 +884,7 @@ void QgsLabel::readXML( const QDomNode& node )
el = scratchNode.toElement();

mLabelAttributes->setBufferEnabled ( (bool)el.attribute("on","0").toInt() );
setLabelField ( BufferEnabled, el.attribute("field","").toInt() );
setLabelField ( BufferEnabled, _elementFieldIndex(el) );
}

} // QgsLabel::readXML()
Expand Down

0 comments on commit 591cceb

Please sign in to comment.