@@ -637,6 +637,15 @@ unsigned char* QgsLabel::labelPoint ( QgsPoint& point, unsigned char* geom)
637
637
return nextFeature;
638
638
}
639
639
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
+
640
649
void QgsLabel::readXML ( const QDomNode& node )
641
650
{
642
651
QgsDebugMsg (" called for layer label properties, got node " + node.nodeName ());
@@ -658,7 +667,7 @@ void QgsLabel::readXML( const QDomNode& node )
658
667
{
659
668
el = scratchNode.toElement ();
660
669
mLabelAttributes ->setText ( el.attribute (" text" ," " ) );
661
- setLabelField ( Text, el. attribute ( " field " , " " ). toInt ( ) );
670
+ setLabelField ( Text, _elementFieldIndex (el ) );
662
671
}
663
672
664
673
/* Family */
@@ -672,7 +681,7 @@ void QgsLabel::readXML( const QDomNode& node )
672
681
{
673
682
el = scratchNode.toElement ();
674
683
mLabelAttributes ->setFamily ( el.attribute (" name" ," " ) );
675
- setLabelField ( Family, el. attribute ( " field " , " " ). toInt ( ) );
684
+ setLabelField ( Family, _elementFieldIndex (el ) );
676
685
}
677
686
678
687
/* Size */
@@ -687,7 +696,7 @@ void QgsLabel::readXML( const QDomNode& node )
687
696
el = scratchNode.toElement ();
688
697
type = QgsLabelAttributes::unitsCode ( el.attribute (" units" ," " ) );
689
698
mLabelAttributes ->setSize ( el.attribute (" value" , " 0.0" ).toDouble (), type );
690
- setLabelField ( Size , el. attribute ( " field " , " " ). toInt ( ) );
699
+ setLabelField ( Size , _elementFieldIndex (el ) );
691
700
}
692
701
693
702
/* Bold */
@@ -701,7 +710,7 @@ void QgsLabel::readXML( const QDomNode& node )
701
710
{
702
711
el = scratchNode.toElement ();
703
712
mLabelAttributes ->setBold ( (bool )el.attribute (" on" ," 0" ).toInt () );
704
- setLabelField ( Bold, el. attribute ( " field " , " " ). toInt ( ) );
713
+ setLabelField ( Bold, _elementFieldIndex (el ) );
705
714
}
706
715
707
716
/* Italic */
@@ -715,7 +724,7 @@ void QgsLabel::readXML( const QDomNode& node )
715
724
{
716
725
el = scratchNode.toElement ();
717
726
mLabelAttributes ->setItalic ( (bool )el.attribute (" on" ," 0" ).toInt () );
718
- setLabelField ( Italic, el. attribute ( " field " , " " ). toInt ( ) );
727
+ setLabelField ( Italic, _elementFieldIndex (el ) );
719
728
}
720
729
721
730
/* Underline */
@@ -729,7 +738,7 @@ void QgsLabel::readXML( const QDomNode& node )
729
738
{
730
739
el = scratchNode.toElement ();
731
740
mLabelAttributes ->setUnderline ( (bool )el.attribute (" on" ," 0" ).toInt () );
732
- setLabelField ( Underline, el. attribute ( " field " , " " ). toInt ( ) );
741
+ setLabelField ( Underline, _elementFieldIndex (el ) );
733
742
}
734
743
735
744
/* Color */
@@ -749,7 +758,7 @@ void QgsLabel::readXML( const QDomNode& node )
749
758
750
759
mLabelAttributes ->setColor ( QColor (red, green, blue) );
751
760
752
- setLabelField ( Color, el. attribute ( " field " , " " ). toInt ( ) );
761
+ setLabelField ( Color, _elementFieldIndex (el ) );
753
762
}
754
763
755
764
/* X */
@@ -762,7 +771,7 @@ void QgsLabel::readXML( const QDomNode& node )
762
771
else
763
772
{
764
773
el = scratchNode.toElement ();
765
- setLabelField ( XCoordinate, el. attribute ( " field " , " " ). toInt ( ) );
774
+ setLabelField ( XCoordinate, _elementFieldIndex (el ) );
766
775
}
767
776
768
777
/* Y */
@@ -775,7 +784,7 @@ void QgsLabel::readXML( const QDomNode& node )
775
784
else
776
785
{
777
786
el = scratchNode.toElement ();
778
- setLabelField ( YCoordinate, el. attribute ( " field " , " " ). toInt ( ) );
787
+ setLabelField ( YCoordinate, _elementFieldIndex (el ) );
779
788
}
780
789
781
790
@@ -812,7 +821,7 @@ void QgsLabel::readXML( const QDomNode& node )
812
821
{
813
822
el = scratchNode.toElement ();
814
823
mLabelAttributes ->setAngle ( el.attribute (" value" ," 0.0" ).toDouble () );
815
- setLabelField ( Angle, el. attribute ( " field " , " 0 " ). toInt ( ) );
824
+ setLabelField ( Angle, _elementFieldIndex (el ) );
816
825
}
817
826
818
827
/* Alignment */
@@ -826,7 +835,7 @@ void QgsLabel::readXML( const QDomNode& node )
826
835
{
827
836
el = scratchNode.toElement ();
828
837
mLabelAttributes ->setAlignment ( QgsLabelAttributes::alignmentCode (el.attribute (" value" ," " )) );
829
- setLabelField ( Alignment, el. attribute ( " field " , " " ). toInt ( ) );
838
+ setLabelField ( Alignment, _elementFieldIndex (el ) );
830
839
}
831
840
832
841
@@ -846,7 +855,7 @@ void QgsLabel::readXML( const QDomNode& node )
846
855
blue = el.attribute (" blue" ," 0" ).toInt ();
847
856
848
857
mLabelAttributes ->setBufferColor ( QColor (red, green, blue) );
849
- setLabelField ( BufferColor, el. attribute ( " field " , " " ). toInt ( ) );
858
+ setLabelField ( BufferColor, _elementFieldIndex (el ) );
850
859
}
851
860
852
861
scratchNode = node.namedItem (" buffersize" );
@@ -861,7 +870,7 @@ void QgsLabel::readXML( const QDomNode& node )
861
870
862
871
type = QgsLabelAttributes::unitsCode ( el.attribute (" units" ," " ) );
863
872
mLabelAttributes ->setBufferSize ( el.attribute (" value" ," 0.0" ).toDouble (), type );
864
- setLabelField ( BufferSize, el. attribute ( " field " , " " ). toInt ( ) );
873
+ setLabelField ( BufferSize, _elementFieldIndex (el ) );
865
874
}
866
875
867
876
scratchNode = node.namedItem (" bufferenabled" );
@@ -875,7 +884,7 @@ void QgsLabel::readXML( const QDomNode& node )
875
884
el = scratchNode.toElement ();
876
885
877
886
mLabelAttributes ->setBufferEnabled ( (bool )el.attribute (" on" ," 0" ).toInt () );
878
- setLabelField ( BufferEnabled, el. attribute ( " field " , " " ). toInt ( ) );
887
+ setLabelField ( BufferEnabled, _elementFieldIndex (el ) );
879
888
}
880
889
881
890
} // QgsLabel::readXML()
0 commit comments