1
/***************************************************************************
2
qgslabel.cpp - render vector labels
5
copyright : (C) 2004 by Radim Blazek
7
***************************************************************************/
8
/***************************************************************************
10
* This program is free software; you can redistribute it and/or modify *
11
* it under the terms of the GNU General Public License as published by *
12
* the Free Software Foundation; either version 2 of the License, or *
13
* (at your option) any later version. *
15
***************************************************************************/
18
#include <math.h> //needed for win32 build (ts)
22
#include <QFontMetrics>
26
#include <QDomElement>
29
#include "qgsfeature.h"
32
#include "qgsmaptopixel.h"
33
#include "qgscoordinatetransform.h"
35
#include "qgslabelattributes.h"
36
#include "qgslabeldialog.h"
39
// use M_PI define PI 3.141592654
42
#define M_PI 4*atan(1.0)
45
static const char * const ident_ =
46
"$Id: qgslabel.cpp 5686 2006-08-10 16:19:19Z rblazek $";
49
QgsLabel::QgsLabel( std::vector<QgsField> const & fields )
53
mLabelField.resize ( LabelFieldCount );
54
mLabelFieldIdx.resize ( LabelFieldCount );
55
for ( int i = 0; i < LabelFieldCount; i++ )
58
mLabelFieldIdx[i] = -1;
60
mLabelAttributes = new QgsLabelAttributes ( true );
66
QString QgsLabel::fieldValue ( int attr, QgsFeature *feature )
68
if ( mLabelField[attr].isEmpty() )
73
std::vector<QgsFeatureAttribute> fields = feature->attributeMap();
75
for ( unsigned int i = 0; i < fields.size(); i++ )
77
if ( fields[i].fieldName().compare(mLabelField[attr]) == 0 )
79
return fields[i].fieldValue();
85
void QgsLabel::renderLabel( QPainter * painter, QgsRect *viewExtent,
86
const QgsCoordinateTransform& coordTransform,
87
bool doCoordTransform, QgsMapToPixel *transform,
88
QgsFeature *feature, bool selected, QgsLabelAttributes *classAttributes,
92
std::cerr << "QgsLabel::renderLabel()" << std::endl;
100
/* Calc scale (not nice) */
102
point = transform->transform ( 0, 0 );
103
double x1 = point.x();
104
point = transform->transform ( 1000, 0 );
105
double x2 = point.x();
106
double scale = (x2-x1)*0.001;
109
value = fieldValue ( Text, feature );
110
if ( value.isEmpty() )
112
text = mLabelAttributes->text();
120
value = fieldValue ( Family, feature );
121
if ( value.isEmpty() )
123
font.setFamily ( mLabelAttributes->family() );
127
font.setFamily ( value );
131
value = fieldValue ( Size, feature );
132
if ( value.isEmpty() )
134
size = mLabelAttributes->size();
138
size = value.toDouble();
140
if ( mLabelAttributes->sizeType() == QgsLabelAttributes::MapUnits )
146
font.setPointSizeFloat ( size );
148
value = fieldValue ( Color, feature );
149
if ( value.isEmpty() )
151
pen.setColor ( mLabelAttributes->color() );
155
pen.setColor ( QColor(value) );
158
value = fieldValue ( Bold, feature );
159
if ( value.isEmpty() )
161
font.setBold ( mLabelAttributes->bold() );
165
font.setBold ( (bool) value.toInt() );
168
value = fieldValue ( Italic, feature );
169
if ( value.isEmpty() )
171
font.setItalic ( mLabelAttributes->italic() );
175
font.setItalic ( (bool) value.toInt() );
178
value = fieldValue ( Underline, feature );
179
if ( value.isEmpty() )
181
font.setUnderline ( mLabelAttributes->underline() );
185
font.setUnderline ( (bool) value.toInt() );
189
QgsPoint overridePoint;
190
bool useOverridePoint = false;
191
value = fieldValue ( XCoordinate, feature );
192
if ( !value.isEmpty() )
194
overridePoint.setX ( value.toDouble() );
195
useOverridePoint = true;
197
value = fieldValue ( YCoordinate, feature );
198
if ( !value.isEmpty() )
200
overridePoint.setY ( value.toDouble() );
201
useOverridePoint = true;
206
QFontMetrics fm ( font );
207
int width = fm.width ( text );
208
int height = fm.height();
211
value = fieldValue ( Alignment, feature );
212
if ( value.isEmpty() )
214
alignment = mLabelAttributes->alignment();
218
value = value.lower();
219
alignment = Qt::AlignCenter;
220
if ( value.compare("left") == 0 )
222
alignment = Qt::AlignLeft | Qt::AlignVCenter;
224
else if ( value.compare("right") == 0 )
226
alignment = Qt::AlignRight | Qt::AlignVCenter;
228
else if ( value.compare("bottom") == 0 )
230
alignment = Qt::AlignBottom | Qt::AlignHCenter;
232
else if ( value.compare("top") == 0 )
234
alignment = Qt::AlignTop | Qt::AlignHCenter;
238
if ( alignment & Qt::AlignLeft )
242
else if ( alignment & Qt::AlignHCenter )
246
else if ( alignment & Qt::AlignRight )
251
if ( alignment & Qt::AlignBottom )
255
else if ( alignment & Qt::AlignVCenter )
259
else if ( alignment & Qt::AlignTop )
265
double xoffset, yoffset;
266
value = fieldValue ( XOffset, feature );
267
if ( value.isEmpty() )
269
xoffset = mLabelAttributes->xOffset();
273
xoffset = value.toDouble();
275
value = fieldValue ( YOffset, feature );
276
if ( value.isEmpty() )
278
yoffset = mLabelAttributes->yOffset();
282
yoffset = value.toDouble();
285
// recalc offset to points
286
if ( mLabelAttributes->offsetType() == QgsLabelAttributes::MapUnits )
294
value = fieldValue ( Angle, feature );
295
if ( value.isEmpty() )
297
ang = mLabelAttributes->angle();
301
ang = value.toDouble();
305
// Work out a suitable position to put the label for the
306
// feature. For multi-geometries, put the same label on each
308
if (useOverridePoint)
310
renderLabel(painter, overridePoint, doCoordTransform, coordTransform,
311
transform, text, font, pen, dx, dy,
312
xoffset, yoffset, ang);
316
std::vector<QgsPoint> points;
317
labelPoint ( points, feature );
318
for (int i = 0; i < points.size(); ++i)
320
renderLabel(painter, points[i], doCoordTransform, coordTransform,
321
transform, text, font, pen, dx, dy,
322
xoffset, yoffset, ang);
327
void QgsLabel::renderLabel(QPainter* painter, QgsPoint point,
328
bool doCoordTransform,
329
const QgsCoordinateTransform& coordTransform,
330
QgsMapToPixel* transform,
331
QString text, QFont font, QPen pen,
333
double xoffset, double yoffset,
336
// Convert point to projected units
337
if (doCoordTransform)
341
point = (const_cast<QgsCoordinateTransform&>(coordTransform)).transform(point);
343
catch(QgsCsException &cse)
346
std::cout << "Caught transform error in QgsLabel::renderLabel(). "
347
<< "Skipping rendering this label" << std::endl;
353
// and then to canvas units
354
transform->transform(&point);
355
double x = point.x();
356
double y = point.y();
358
static const double rad = ang * M_PI/180;
360
x = x + xoffset * cos(rad) - yoffset * sin(rad);
361
y = y - xoffset * sin(rad) - yoffset * cos(rad);
364
painter->setFont ( font );
365
painter->translate ( x, y );
366
painter->rotate ( -ang );
368
// Draw a buffer behind the text if one is desired
370
if (mLabelAttributes->bufferSizeIsSet() && mLabelAttributes->bufferEnabled())
372
int myBufferSize = static_cast<int>(mLabelAttributes->bufferSize());
373
if (mLabelAttributes->bufferColorIsSet())
375
painter->setPen( mLabelAttributes->bufferColor());
377
else //default to a white buffer
379
painter->setPen( Qt::white);
381
for (int i = dx-myBufferSize; i <= dx+myBufferSize; i++)
383
for (int j = dy-myBufferSize; j <= dy+myBufferSize; j++)
385
painter->drawText( i ,j, text);
390
painter->setPen ( pen );
391
painter->drawText ( dx, dy, text );
395
void QgsLabel::addRequiredFields ( std::list<int> *fields )
397
for ( int i = 0; i < LabelFieldCount; i++ )
399
if ( mLabelFieldIdx[i] == -1 )
402
for (std::list<int>::iterator it = fields->
407
if ( *it == mLabelFieldIdx[i] )
415
fields->push_back(mLabelFieldIdx[i])
421
void QgsLabel::setFields( std::vector<QgsField> const & fields )
426
std::vector<QgsField> & QgsLabel::fields ( void )
431
void QgsLabel::setLabelField ( int attr, const QString str )
433
if ( attr >= LabelFieldCount )
437
mLabelField[attr] = str;
439
mLabelFieldIdx[attr] = -1;
440
for ( int i = 0; i < mField.size(); i++ )
442
if ( mField[i].name().compare(str) == 0 )
444
mLabelFieldIdx[attr] = i;
449
QString QgsLabel::labelField ( int attr )
451
if ( attr > LabelFieldCount )
454
return mLabelField[attr];
457
QgsLabelAttributes *QgsLabel::layerAttributes ( void )
459
return mLabelAttributes;
462
void QgsLabel::labelPoint ( std::vector<QgsPoint>& points, QgsFeature *feature )
464
unsigned char *geom = feature->getGeometry();
466
memcpy(&wkbType, (geom+1), sizeof(wkbType));
473
case QGis::WKBLineString:
474
case QGis::WKBPolygon:
476
labelPoint(point, geom);
477
points.push_back(point);
480
case QGis::WKBMultiPoint:
481
case QGis::WKBMultiLineString:
482
case QGis::WKBMultiPolygon:
483
// Return a position for each individual in the multi-feature
485
int numFeatures = (int)(*(geom + 5));
486
geom += 9; // now points to start of array of WKB's
487
for (int i = 0; i < numFeatures; ++i)
489
geom = labelPoint(point, geom);
490
points.push_back(point);
495
std::cerr << "Unknown geometry type of " << wkbType << '\n';
499
unsigned char* QgsLabel::labelPoint ( QgsPoint& point, unsigned char* geom)
501
// Number of bytes that ints and doubles take in the WKB format.
502
static const unsigned int sizeOfInt = 4;
503
static const unsigned int sizeOfDouble = 8;
509
// Upon return from this function, this variable will contain a
510
// pointer to the first byte beyond the current feature.
511
unsigned char *nextFeature = geom;
513
memcpy(&wkbType, (geom+1), sizeof(wkbType));
519
x = (double *) (geom + 5);
520
y = (double *) (geom + 5 + sizeof(double));
522
nextFeature += 1 + sizeOfInt + sizeOfDouble*2;
526
case QGis::WKBLineString: // Line center
528
double dx, dy, tl, l;
530
nPoints = (int *)ptr;
531
nextFeature += 1 + sizeOfInt*2 + (*nPoints)*sizeOfDouble*2;
532
ptr = geom + 1 + 2 * sizeof(int);
535
for (int i = 1; i < *nPoints; i++)
537
dx = ((double *)ptr)[2*i] - ((double *)ptr)[2*i-2];
538
dy = ((double *)ptr)[2*i+1] - ((double *)ptr)[2*i-1];
539
tl += sqrt(dx*dx + dy*dy);
544
for (int i = 1; i < *nPoints; i++)
548
dx = ((double *)ptr)[2*i] - ((double *)ptr)[2*i-2];
549
dy = ((double *)ptr)[2*i+1] - ((double *)ptr)[2*i-1];
550
dl = sqrt(dx*dx + dy*dy);
557
point.setX ( ((double *)ptr)[2*i-2] + k * dx );
558
point.setY ( ((double *)ptr)[2*i-1] + k * dy );
566
case QGis::WKBPolygon:
569
ptr = geom + 1 + 2 * sizeof(int); // set pointer to the first ring
570
nPoints = (int *) ptr;
573
for (int i = 0; i < *nPoints-1; i++)
575
sx += ((double *)ptr)[2*i];
576
sy += ((double *)ptr)[2*i+1];
578
point.setX ( sx/(*nPoints-1) );
579
point.setY ( sy/(*nPoints-1) );
580
// Work out a pointer to the next feature after this one.
581
int numRings = (int)(*(geom+1+sizeOfInt));
582
unsigned char* nextRing = nextFeature + 1 + 2*sizeOfInt;
583
for (int i = 0; i < numRings; ++i)
585
int numPoints = (int)(*nextRing);
586
// get the start of the next ring
587
nextRing += sizeOfInt + numPoints*sizeOfDouble*2;
589
nextFeature = nextRing;
594
// To get here is a bug because our caller should be filtering
601
void QgsLabel::readXML( const QDomNode& node )
604
std::cout << "QgsLabel::readXML() called for layer label properties \n" << std::endl;
607
qDebug( "%s:%d QgsLabel::readXML() got node %s", __FILE__, __LINE__, (const char *)node.nodeName().toLocal8Bit().data() );
609
QDomNode scratchNode; // DOM node re-used to get current QgsLabel attribute
612
int red, green, blue;
616
scratchNode = node.namedItem("label");
618
if ( scratchNode.isNull() )
620
qDebug( "%s:%d couldn't find QgsLabel ``label'' attribute", __FILE__, __LINE__ );
624
el = scratchNode.toElement();
625
mLabelAttributes->setText ( el.attribute("text","") );
626
setLabelField ( Text, el.attribute("field","") );
630
scratchNode = node.namedItem("family");
632
if ( scratchNode.isNull() )
634
qDebug( "%s:%d couldn't find QgsLabel ``family'' attribute", __FILE__, __LINE__ );
638
el = scratchNode.toElement();
639
mLabelAttributes->setFamily ( el.attribute("name","") );
640
setLabelField ( Family, el.attribute("field","") );
644
scratchNode = node.namedItem("size");
646
if ( scratchNode.isNull() )
648
qDebug( "%s:%d couldn't find QgsLabel ``size'' attribute", __FILE__, __LINE__ );
652
el = scratchNode.toElement();
653
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
654
mLabelAttributes->setSize ( el.attribute("value", "0.0").toDouble(), type );
655
setLabelField ( Size, el.attribute("field","") );
659
scratchNode = node.namedItem("bold");
661
if ( scratchNode.isNull() )
663
qDebug( "%s:%d couldn't find QgsLabel ``bold'' attribute", __FILE__, __LINE__ );
667
el = scratchNode.toElement();
668
mLabelAttributes->setBold ( (bool)el.attribute("on","0").toInt() );
669
setLabelField ( Bold, el.attribute("field","") );
673
scratchNode = node.namedItem("italic");
675
if ( scratchNode.isNull() )
677
qDebug( "%s:%d couldn't find QgsLabel ``italic'' attribute", __FILE__, __LINE__ );
681
el = scratchNode.toElement();
682
mLabelAttributes->setItalic ( (bool)el.attribute("on","0").toInt() );
683
setLabelField ( Italic, el.attribute("field","") );
687
scratchNode = node.namedItem("underline");
689
if ( scratchNode.isNull() )
691
qDebug( "%s:%d couldn't find QgsLabel ``underline'' attribute", __FILE__, __LINE__ );
695
el = scratchNode.toElement();
696
mLabelAttributes->setUnderline ( (bool)el.attribute("on","0").toInt() );
697
setLabelField ( Underline, el.attribute("field","") );
701
scratchNode = node.namedItem("color");
703
if ( scratchNode.isNull() )
705
qDebug( "%s:%d couldn't find QgsLabel ``color'' attribute", __FILE__, __LINE__ );
709
el = scratchNode.toElement();
711
red = el.attribute("red","0").toInt();
712
green = el.attribute("green","0").toInt();
713
blue = el.attribute("blue","0").toInt();
715
mLabelAttributes->setColor( QColor(red, green, blue) );
717
setLabelField ( Color, el.attribute("field","") );
721
scratchNode = node.namedItem("x");
723
if ( scratchNode.isNull() )
725
qDebug( "%s:%d couldn't find QgsLabel ``x'' attribute", __FILE__, __LINE__ );
729
el = scratchNode.toElement();
730
setLabelField ( XCoordinate, el.attribute("field","") );
734
scratchNode = node.namedItem("y");
736
if ( scratchNode.isNull() )
738
qDebug( "%s:%d couldn't find QgsLabel ``y'' attribute", __FILE__, __LINE__ );
742
el = scratchNode.toElement();
743
setLabelField ( YCoordinate, el.attribute("field","") );
748
scratchNode = node.namedItem("offset");
750
if ( scratchNode.isNull() )
752
qDebug( "%s:%d couldn't find QgsLabel ``offset'' attribute", __FILE__, __LINE__ );
756
double xoffset, yoffset;
758
el = scratchNode.toElement();
760
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
761
xoffset = el.attribute("x","0.0").toDouble();
762
yoffset = el.attribute("y","0.0").toDouble();
764
mLabelAttributes->setOffset ( xoffset, yoffset, type );
765
setLabelField ( XOffset, el.attribute("xfield","0") );
766
setLabelField ( YOffset, el.attribute("yfield","0") );
770
scratchNode = node.namedItem("angle");
772
if ( scratchNode.isNull() )
774
qDebug( "%s:%d couldn't find QgsLabel ``angle'' attribute", __FILE__, __LINE__ );
778
el = scratchNode.toElement();
779
mLabelAttributes->setAngle ( el.attribute("value","0.0").toDouble() );
780
setLabelField ( Angle, el.attribute("field","0.0") );
784
scratchNode = node.namedItem("alignment");
786
if ( scratchNode.isNull() )
788
qDebug( "%s:%d couldn't find QgsLabel ``alignment'' attribute", __FILE__, __LINE__ );
792
el = scratchNode.toElement();
793
mLabelAttributes->setAlignment ( QgsLabelAttributes::alignmentCode(el.attribute("value","")) );
794
setLabelField ( Alignment, el.attribute("field","") );
799
scratchNode = node.namedItem("buffercolor");
801
if ( scratchNode.isNull() )
803
qDebug( "%s:%d couldn't find QgsLabel ``buffercolor'' attribute", __FILE__, __LINE__ );
807
el = scratchNode.toElement();
809
red = el.attribute("red","0").toInt();
810
green = el.attribute("green","0").toInt();
811
blue = el.attribute("blue","0").toInt();
813
mLabelAttributes->setBufferColor( QColor(red, green, blue) );
814
setLabelField ( BufferColor, el.attribute("field","") );
817
scratchNode = node.namedItem("buffersize");
819
if ( scratchNode.isNull() )
821
qDebug( "%s:%d couldn't find QgsLabel ``buffersize'' attribute", __FILE__, __LINE__ );
825
el = scratchNode.toElement();
827
type = QgsLabelAttributes::unitsCode( el.attribute("units","") );
828
mLabelAttributes->setBufferSize ( el.attribute("value","0.0").toDouble(), type );
829
setLabelField ( BufferSize, el.attribute("field","") );
832
scratchNode = node.namedItem("bufferenabled");
834
if ( scratchNode.isNull() )
836
qDebug( "%s:%d couldn't find QgsLabel ``bufferenabled'' attribute", __FILE__, __LINE__ );
840
el = scratchNode.toElement();
842
mLabelAttributes->setBufferEnabled ( (bool)el.attribute("on","0").toInt() );
843
setLabelField ( BufferEnabled, el.attribute("field","") );
846
} // QgsLabel::readXML()
850
void QgsLabel::writeXML(std::ostream& xml)
853
xml << "\t\t<labelattributes>\n";
856
if ( mLabelAttributes->textIsSet() && !mLabelField[Text].isEmpty() )
858
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8()) << "\" field=\"" << (const char*)(mLabelField[Text].utf8()) << "\" />\n";
860
else if ( mLabelAttributes->textIsSet() )
862
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8()) << "\" field=\"\" />\n";
866
xml << "\t\t\t<label text=\"" << (const char*)(mLabelAttributes->text().utf8()) << "\" field=\"" << (const char*)(mLabelField[Text].utf8()) << "\" />\n";
869
if ( mLabelAttributes->familyIsSet() && ! mLabelAttributes->family().isNull() && mLabelField[Family].isNull())
871
xml << "\t\t\t<family name=\"" << mLabelAttributes->family().utf8().data() << "\" field=\"" << (const char*)(mLabelField[Family].utf8().data()) << "\" />\n";
873
else if ( mLabelAttributes->familyIsSet() && ! mLabelAttributes->family().isNull() )
875
xml << "\t\t\t<family name=\"" << mLabelAttributes->family().utf8().data() << "\" field=\"\" />\n";
879
xml << "\t\t\t<family name=\"Arial\" field=\"\" />\n";
883
if ( mLabelAttributes->sizeIsSet() && !mLabelField[Size].isEmpty())
885
xml << "\t\t\t<size value=\"" << mLabelAttributes->size() << "\" units=\""
886
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->sizeType()).utf8() << "\" field=\"" << (const char*)(mLabelField[Size].utf8()) << "\" />\n";
888
else if ( mLabelAttributes->sizeIsSet() )
890
xml << "\t\t\t<size value=\"" << mLabelAttributes->size() << "\" units=\""
891
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->sizeType()).utf8() << "\" field=\"\" />\n";
895
xml << "\t\t\t<size value=\"12\" units=\"Points\" field=\"\" />\n";
901
if ( mLabelAttributes->boldIsSet() && !mLabelField[Bold].isEmpty() )
903
xml << "\t\t\t<bold on=\"" << mLabelAttributes->bold() << "\" field=\"" << (const char*)(mLabelField[Bold].utf8()) << "\" />\n";
905
else if ( mLabelAttributes->boldIsSet() )
907
xml << "\t\t\t<bold on=\"" << mLabelAttributes->bold() << "\" field=\"\" />\n";
911
xml << "\t\t\t<bold on=\"0\" field=\"0\" />\n";
915
if ( mLabelAttributes->italicIsSet() && ! mLabelField[Italic].isEmpty())
917
xml << "\t\t\t<italic on=\"" << mLabelAttributes->italic() << "\" field=\"" << (const char*)(mLabelField[Italic].utf8()) << "\" />\n";
919
else if ( mLabelAttributes->italicIsSet() )
921
xml << "\t\t\t<italic on=\"" << mLabelAttributes->italic() << "\" field=\"\" />\n";
925
xml << "\t\t\t<italic on=\"0\" field=\"\" />\n";
928
if ( mLabelAttributes->underlineIsSet() && !mLabelField[Underline].isEmpty())
930
xml << "\t\t\t<underline on=\"" << mLabelAttributes->underline() << "\" field=\"" << (const char*)(mLabelField[Underline].utf8()) << "\" />\n";
932
else if ( mLabelAttributes->underlineIsSet() )
934
xml << "\t\t\t<underline on=\"" << mLabelAttributes->underline() << "\" field=\"\" />\n";
938
xml << "\t\t\t<underline on=\"0\" field=\"\" />\n";
941
if ( mLabelAttributes->colorIsSet() && ! mLabelField[Color].isNull() )
943
xml << "\t\t\t<color red=\"" << mLabelAttributes->color().red() << "\" green=\"" << mLabelAttributes->color().green()
944
<< "\" blue=\"" << mLabelAttributes->color().blue() << "\" field=\"" << (const char*)(mLabelField[Color].utf8()) << "\" />\n";
946
else if ( mLabelAttributes->colorIsSet() )
948
xml << "\t\t\t<color red=\"" << mLabelAttributes->color().red() << "\" green=\"" << mLabelAttributes->color().green()
949
<< "\" blue=\"" << mLabelAttributes->color().blue() << "\" field=\"\" />\n";
953
xml << "\t\t\t<color red=\"0\" green=\"0\" blue=\"0\" field=\"\" />\n";
958
if (! mLabelField[XCoordinate].isEmpty() )
960
xml << "\t\t\t<x field=\"" << (const char*)(mLabelField[XCoordinate].utf8()) << "\" />\n";
964
xml << "\t\t\t<x field=\"" << "\" />\n";
968
if (! mLabelField[YCoordinate].isEmpty() )
970
xml << "\t\t\t<y field=\"" << (const char*)(mLabelField[YCoordinate].utf8()) << "\" />\n";
974
xml << "\t\t\t<y field=\"" << "\" />\n";
978
if ( mLabelAttributes->offsetIsSet() )
980
xml << "\t\t\t<offset units=\"" << QgsLabelAttributes::unitsName(mLabelAttributes->offsetType()).utf8().data()
981
<< "\" x=\"" << mLabelAttributes->xOffset() << "\" xfield=\"" << (const char*)(mLabelField[XOffset].utf8().data())
982
<< "\" y=\"" << mLabelAttributes->yOffset() << "\" yfield=\"" << (const char*)(mLabelField[YOffset].utf8().data())
987
if ( mLabelAttributes->angleIsSet() )
989
xml << "\t\t\t<angle value=\"" << mLabelAttributes->angle() << "\" field=\"" << (const char*)(mLabelField[Angle].utf8()) << "\" />\n";
991
else if ( mLabelAttributes->angleIsSet() )
993
xml << "\t\t\t<angle value=\"" << mLabelAttributes->angle() << "\" field=\"" << "\" />\n";
997
xml << "\t\t\t<angle value=\"" << "\" field=\"" << "\" />\n";
1001
if ( mLabelAttributes->alignmentIsSet() )
1003
xml << "\t\t\t<alignment value=\"" << QgsLabelAttributes::alignmentName(mLabelAttributes->alignment()).utf8().data()
1004
<< "\" field=\"" << (const char*)(mLabelField[Alignment].utf8().data()) << "\" />\n";
1008
if ( mLabelAttributes->bufferColorIsSet() && ! mLabelField[BufferColor].isNull() )
1010
xml << "\t\t\t<buffercolor red=\"" << mLabelAttributes->bufferColor().red() << "\" green=\"" << mLabelAttributes->bufferColor().green()
1011
<< "\" blue=\"" << mLabelAttributes->bufferColor().blue() << "\" field=\"" << (const char*)(mLabelField[BufferColor].utf8()) << "\" />\n";
1013
else if ( mLabelAttributes->bufferColorIsSet() )
1015
xml << "\t\t\t<buffercolor red=\"" << mLabelAttributes->bufferColor().red() << "\" green=\"" << mLabelAttributes->bufferColor().green()
1016
<< "\" blue=\"" << mLabelAttributes->bufferColor().blue() << "\" field=\"" << "\" />\n";
1020
xml << "\t\t\t<buffercolor red=\"" << "\" green=\""
1021
<< "\" blue=\"" << "\" field=\"" << "\" />\n";
1025
if ( mLabelAttributes->bufferSizeIsSet() && ! mLabelField[BufferSize].isNull() )
1027
xml << "\t\t\t<buffersize value=\"" << mLabelAttributes->bufferSize() << "\" units=\""
1028
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->bufferSizeType()).utf8() << "\" field=\"" << (const char*)(mLabelField[BufferSize].utf8()) << "\" />\n";
1030
else if ( mLabelAttributes->bufferSizeIsSet() )
1032
xml << "\t\t\t<buffersize value=\"" << mLabelAttributes->bufferSize() << "\" units=\""
1033
<< (const char *)QgsLabelAttributes::unitsName(mLabelAttributes->bufferSizeType()).utf8() << "\" field=\"" << "\" />\n";
1037
xml << "\t\t\t<buffersize value=\"" << "\" units=\""
1038
<< "\" field=\"" << "\" />\n";
1042
if ( mLabelAttributes->bufferEnabled() && ! mLabelField[BufferEnabled].isNull() )
1044
xml << "\t\t\t<bufferenabled on=\"" << mLabelAttributes->bufferEnabled() << "\" field=\"" << (const char*)(mLabelField[BufferEnabled].utf8()) << "\" />\n";
1046
else if ( mLabelAttributes->bufferEnabled())
1048
xml << "\t\t\t<bufferenabled on=\"" << mLabelAttributes->bufferEnabled() << "\" field=\"" << "\" />\n";
1052
xml << "\t\t\t<bufferenabled on=\"" << "\" field=\"" << "\" />\n";
1054
xml << "\t\t</labelattributes>\n";