Skip to content

Commit 15aaf24

Browse files
author
wonder
committed
Fixed a problem with incorrectly loaded labeling attributes.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@7123 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent bb90021 commit 15aaf24

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/core/qgslabel.cpp

+23-14
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,15 @@ unsigned char* QgsLabel::labelPoint ( QgsPoint& point, unsigned char* geom)
637637
return nextFeature;
638638
}
639639

640+
static int _elementFieldIndex(QDomElement& el)
641+
{
642+
QString str = el.attribute("field","");
643+
if (str == "")
644+
return -1;
645+
else
646+
return str.toInt();
647+
}
648+
640649
void QgsLabel::readXML( const QDomNode& node )
641650
{
642651
QgsDebugMsg(" called for layer label properties, got node " + node.nodeName());
@@ -658,7 +667,7 @@ void QgsLabel::readXML( const QDomNode& node )
658667
{
659668
el = scratchNode.toElement();
660669
mLabelAttributes->setText ( el.attribute("text","") );
661-
setLabelField ( Text, el.attribute("field","").toInt() );
670+
setLabelField ( Text, _elementFieldIndex(el) );
662671
}
663672

664673
/* Family */
@@ -672,7 +681,7 @@ void QgsLabel::readXML( const QDomNode& node )
672681
{
673682
el = scratchNode.toElement();
674683
mLabelAttributes->setFamily ( el.attribute("name","") );
675-
setLabelField ( Family, el.attribute("field","").toInt() );
684+
setLabelField ( Family, _elementFieldIndex(el) );
676685
}
677686

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

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

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

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

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

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

752-
setLabelField ( Color, el.attribute("field","").toInt() );
761+
setLabelField ( Color, _elementFieldIndex(el) );
753762
}
754763

755764
/* X */
@@ -762,7 +771,7 @@ void QgsLabel::readXML( const QDomNode& node )
762771
else
763772
{
764773
el = scratchNode.toElement();
765-
setLabelField ( XCoordinate, el.attribute("field","").toInt() );
774+
setLabelField ( XCoordinate, _elementFieldIndex(el) );
766775
}
767776

768777
/* Y */
@@ -775,7 +784,7 @@ void QgsLabel::readXML( const QDomNode& node )
775784
else
776785
{
777786
el = scratchNode.toElement();
778-
setLabelField ( YCoordinate, el.attribute("field","").toInt() );
787+
setLabelField ( YCoordinate, _elementFieldIndex(el) );
779788
}
780789

781790

@@ -812,7 +821,7 @@ void QgsLabel::readXML( const QDomNode& node )
812821
{
813822
el = scratchNode.toElement();
814823
mLabelAttributes->setAngle ( el.attribute("value","0.0").toDouble() );
815-
setLabelField ( Angle, el.attribute("field","0").toInt() );
824+
setLabelField ( Angle, _elementFieldIndex(el) );
816825
}
817826

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

832841

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

848857
mLabelAttributes->setBufferColor( QColor(red, green, blue) );
849-
setLabelField ( BufferColor, el.attribute("field","").toInt() );
858+
setLabelField ( BufferColor, _elementFieldIndex(el) );
850859
}
851860

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

862871
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
863872
mLabelAttributes->setBufferSize ( el.attribute("value","0.0").toDouble(), type );
864-
setLabelField ( BufferSize, el.attribute("field","").toInt() );
873+
setLabelField ( BufferSize, _elementFieldIndex(el) );
865874
}
866875

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

877886
mLabelAttributes->setBufferEnabled ( (bool)el.attribute("on","0").toInt() );
878-
setLabelField ( BufferEnabled, el.attribute("field","").toInt() );
887+
setLabelField ( BufferEnabled, _elementFieldIndex(el) );
879888
}
880889

881890
} // QgsLabel::readXML()

0 commit comments

Comments
 (0)