1
|
Index: app/qgslabeldialog.cpp
|
2
|
===================================================================
|
3
|
--- app/qgslabeldialog.cpp (revision 8705)
|
4
|
+++ app/qgslabeldialog.cpp (working copy)
|
5
|
@@ -239,6 +239,8 @@
|
6
|
{
|
7
|
spinBufferSize->setValue(1);
|
8
|
}
|
9
|
+ //set the state of the multiline enabled checkbox
|
10
|
+ chkUseMultiline->setChecked(myLabelAttributes->multilineEnabled());
|
11
|
//set the state of the buffer enabled checkbox
|
12
|
chkUseBuffer->setChecked(myLabelAttributes->bufferEnabled());
|
13
|
|
14
|
@@ -360,6 +362,7 @@
|
15
|
if (radioBelow->isChecked()) myLabelAttributes->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
|
16
|
if (radioOver->isChecked()) myLabelAttributes->setAlignment(Qt::AlignCenter);
|
17
|
|
18
|
+ myLabelAttributes->setMultilineEnabled(chkUseMultiline->isChecked());
|
19
|
myLabelAttributes->setBufferEnabled(chkUseBuffer->isChecked());
|
20
|
myLabelAttributes->setBufferColor(mBufferColor);
|
21
|
myTypeInt = 0;
|
22
|
Index: core/qgslabelattributes.cpp
|
23
|
===================================================================
|
24
|
--- core/qgslabelattributes.cpp (revision 8705)
|
25
|
+++ core/qgslabelattributes.cpp (working copy)
|
26
|
@@ -51,7 +51,8 @@
|
27
|
mBufferStyleIsSet( false ),
|
28
|
mBorderColorIsSet( false ),
|
29
|
mBorderWidthIsSet( false ),
|
30
|
- mBorderStyleIsSet( false )
|
31
|
+ mBorderStyleIsSet( false ),
|
32
|
+ mMultilineEnabledFlag( false )
|
33
|
{
|
34
|
|
35
|
if ( def ) { // set defaults
|
36
|
@@ -388,13 +389,25 @@
|
37
|
return mBorderPen.style();
|
38
|
}
|
39
|
|
40
|
+ /* Multiline */
|
41
|
+bool QgsLabelAttributes::multilineEnabled() const
|
42
|
+{
|
43
|
+ return mMultilineEnabledFlag;
|
44
|
+}
|
45
|
+void QgsLabelAttributes::setMultilineEnabled(bool useMultilineFlag)
|
46
|
+{
|
47
|
+ mMultilineEnabledFlag=useMultilineFlag;
|
48
|
+}
|
49
|
+
|
50
|
+ /* units */
|
51
|
QString QgsLabelAttributes::unitsName ( int units )
|
52
|
{
|
53
|
- if ( units == MapUnits ){
|
54
|
- return QString("mu");
|
55
|
- }
|
56
|
-
|
57
|
- return QString("pt");
|
58
|
+ if ( units == MapUnits )
|
59
|
+ {
|
60
|
+ return QString("mu");
|
61
|
+ }
|
62
|
+
|
63
|
+ return QString("pt");
|
64
|
}
|
65
|
|
66
|
int QgsLabelAttributes::unitsCode ( const QString &name )
|
67
|
@@ -406,6 +419,7 @@
|
68
|
return PointUnits;
|
69
|
}
|
70
|
|
71
|
+ /* alignment */
|
72
|
QString QgsLabelAttributes::alignmentName ( int alignment )
|
73
|
{
|
74
|
std::cout << "QString QgsLabelAttributes::alignmentName (" << alignment << ")" << std::endl;
|
75
|
Index: core/qgslabel.cpp
|
76
|
===================================================================
|
77
|
--- core/qgslabel.cpp (revision 8705)
|
78
|
+++ core/qgslabel.cpp (working copy)
|
79
|
@@ -71,7 +71,7 @@
|
80
|
|
81
|
const QgsAttributeMap& attrs = feature.attributeMap();
|
82
|
QgsAttributeMap::const_iterator it = attrs.find(mLabelFieldIdx[attr]);
|
83
|
-
|
84
|
+
|
85
|
if (it != attrs.end())
|
86
|
{
|
87
|
return it->toString();
|
88
|
@@ -86,7 +86,7 @@
|
89
|
const QgsCoordinateTransform* coordTransform,
|
90
|
const QgsMapToPixel *transform,
|
91
|
QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes,
|
92
|
- double sizeScale )
|
93
|
+ double sizeScale )
|
94
|
{
|
95
|
|
96
|
QPen pen;
|
97
|
@@ -137,20 +137,20 @@
|
98
|
int sizeType;
|
99
|
value = fieldValue ( SizeType, feature );
|
100
|
if( value.isEmpty() )
|
101
|
- sizeType = mLabelAttributes->sizeType();
|
102
|
+ sizeType = mLabelAttributes->sizeType();
|
103
|
else
|
104
|
{
|
105
|
- value = value.toLower();
|
106
|
- if( value.compare("mapunits") == 0 )
|
107
|
- sizeType = QgsLabelAttributes::MapUnits;
|
108
|
- else
|
109
|
- sizeType = QgsLabelAttributes::PointUnits;
|
110
|
+ value = value.toLower();
|
111
|
+ if( value.compare("mapunits") == 0 )
|
112
|
+ sizeType = QgsLabelAttributes::MapUnits;
|
113
|
+ else
|
114
|
+ sizeType = QgsLabelAttributes::PointUnits;
|
115
|
}
|
116
|
if ( sizeType == QgsLabelAttributes::MapUnits )
|
117
|
{
|
118
|
size *= scale;
|
119
|
} else {
|
120
|
- size *= sizeScale;
|
121
|
+ size *= sizeScale;
|
122
|
}
|
123
|
if(size>0.0)
|
124
|
font.setPointSizeF ( size );
|
125
|
@@ -214,8 +214,26 @@
|
126
|
/* Alignment */
|
127
|
int alignment;
|
128
|
QFontMetrics fm ( font );
|
129
|
- int width = fm.width ( text );
|
130
|
- int height = fm.height();
|
131
|
+ int width, height;
|
132
|
+
|
133
|
+ if( mLabelAttributes->multilineEnabled() )
|
134
|
+ {
|
135
|
+ QStringList texts = text.split("\n");
|
136
|
+
|
137
|
+ width=0;
|
138
|
+ for(int i=0; i<texts.size(); i++) {
|
139
|
+ int w = fm.width(texts[i]);
|
140
|
+ if(w>width)
|
141
|
+ width=w;
|
142
|
+ }
|
143
|
+
|
144
|
+ height = fm.height()*texts.size();
|
145
|
+ }
|
146
|
+ else
|
147
|
+ {
|
148
|
+ width = fm.width ( text );
|
149
|
+ height = fm.height();
|
150
|
+ }
|
151
|
int dx = 0;
|
152
|
int dy = 0;
|
153
|
|
154
|
@@ -226,23 +244,23 @@
|
155
|
}
|
156
|
else
|
157
|
{
|
158
|
- value = value.toLower();
|
159
|
+ value = value.toLower();
|
160
|
|
161
|
- alignment=0;
|
162
|
+ alignment=0;
|
163
|
|
164
|
- if ( value.contains("left") )
|
165
|
- alignment |= Qt::AlignLeft;
|
166
|
- else if( value.contains("right") )
|
167
|
- alignment |= Qt::AlignRight;
|
168
|
- else
|
169
|
- alignment |= Qt::AlignHCenter;
|
170
|
+ if ( value.contains("left") )
|
171
|
+ alignment |= Qt::AlignLeft;
|
172
|
+ else if( value.contains("right") )
|
173
|
+ alignment |= Qt::AlignRight;
|
174
|
+ else
|
175
|
+ alignment |= Qt::AlignHCenter;
|
176
|
|
177
|
- if( value.contains("bottom") )
|
178
|
- alignment |= Qt::AlignBottom;
|
179
|
- else if( value.contains("top") )
|
180
|
- alignment |= Qt::AlignTop;
|
181
|
- else
|
182
|
- alignment |= Qt::AlignVCenter;
|
183
|
+ if( value.contains("bottom") )
|
184
|
+ alignment |= Qt::AlignBottom;
|
185
|
+ else if( value.contains("top") )
|
186
|
+ alignment |= Qt::AlignTop;
|
187
|
+ else
|
188
|
+ alignment |= Qt::AlignVCenter;
|
189
|
}
|
190
|
|
191
|
if ( alignment & Qt::AlignLeft )
|
192
|
@@ -319,7 +337,7 @@
|
193
|
{
|
194
|
renderLabel(painter, overridePoint, coordTransform,
|
195
|
transform, text, font, pen, dx, dy,
|
196
|
- xoffset, yoffset, ang);
|
197
|
+ xoffset, yoffset, ang, width, height, alignment);
|
198
|
}
|
199
|
else
|
200
|
{
|
201
|
@@ -329,7 +347,7 @@
|
202
|
{
|
203
|
renderLabel(painter, points[i], coordTransform,
|
204
|
transform, text, font, pen, dx, dy,
|
205
|
- xoffset, yoffset, ang);
|
206
|
+ xoffset, yoffset, ang, width, height, alignment);
|
207
|
}
|
208
|
}
|
209
|
}
|
210
|
@@ -340,7 +358,8 @@
|
211
|
QString text, QFont font, QPen pen,
|
212
|
int dx, int dy,
|
213
|
double xoffset, double yoffset,
|
214
|
- double ang)
|
215
|
+ double ang,
|
216
|
+ int width, int height, int alignment)
|
217
|
{
|
218
|
// Convert point to projected units
|
219
|
if (coordTransform)
|
220
|
@@ -372,31 +391,38 @@
|
221
|
painter->setFont ( font );
|
222
|
painter->translate ( x, y );
|
223
|
painter->rotate ( -ang );
|
224
|
+
|
225
|
//
|
226
|
// Draw a buffer behind the text if one is desired
|
227
|
//
|
228
|
if (mLabelAttributes->bufferSizeIsSet() && mLabelAttributes->bufferEnabled())
|
229
|
{
|
230
|
- int myBufferSize = static_cast<int>(mLabelAttributes->bufferSize());
|
231
|
- if (mLabelAttributes->bufferColorIsSet())
|
232
|
+ int myBufferSize = static_cast<int>(mLabelAttributes->bufferSize());
|
233
|
+ if (mLabelAttributes->bufferColorIsSet())
|
234
|
+ {
|
235
|
+ painter->setPen( mLabelAttributes->bufferColor());
|
236
|
+ }
|
237
|
+ else //default to a white buffer
|
238
|
+ {
|
239
|
+ painter->setPen( Qt::white);
|
240
|
+ }
|
241
|
+ for (int i = dx-myBufferSize; i <= dx+myBufferSize; i++)
|
242
|
+ {
|
243
|
+ for (int j = dy-myBufferSize; j <= dy+myBufferSize; j++)
|
244
|
{
|
245
|
- painter->setPen( mLabelAttributes->bufferColor());
|
246
|
+ if( mLabelAttributes->multilineEnabled() )
|
247
|
+ painter->drawText( i , j, width, height, alignment, text);
|
248
|
+ else
|
249
|
+ painter->drawText( i , j, text);
|
250
|
}
|
251
|
- else //default to a white buffer
|
252
|
- {
|
253
|
- painter->setPen( Qt::white);
|
254
|
- }
|
255
|
- for (int i = dx-myBufferSize; i <= dx+myBufferSize; i++)
|
256
|
- {
|
257
|
- for (int j = dy-myBufferSize; j <= dy+myBufferSize; j++)
|
258
|
- {
|
259
|
- painter->drawText( i ,j, text);
|
260
|
- }
|
261
|
- }
|
262
|
+ }
|
263
|
}
|
264
|
|
265
|
painter->setPen ( pen );
|
266
|
- painter->drawText ( dx, dy, text );
|
267
|
+ if( mLabelAttributes->multilineEnabled() )
|
268
|
+ painter->drawText ( dx, dy-height, width, height, alignment, text );
|
269
|
+ else
|
270
|
+ painter->drawText ( dx, dy, text );
|
271
|
painter->restore();
|
272
|
}
|
273
|
|
274
|
@@ -882,6 +908,20 @@
|
275
|
setLabelField ( BufferEnabled, _elementFieldIndex(el) );
|
276
|
}
|
277
|
|
278
|
+ scratchNode = node.namedItem("multilineenabled");
|
279
|
+
|
280
|
+ if ( scratchNode.isNull() )
|
281
|
+ {
|
282
|
+ QgsDebugMsg("couldn't find QgsLabel ``multilineenabled'' attribute");
|
283
|
+ }
|
284
|
+ else
|
285
|
+ {
|
286
|
+ el = scratchNode.toElement();
|
287
|
+
|
288
|
+ mLabelAttributes->setMultilineEnabled ( (bool)el.attribute("on","0").toInt() );
|
289
|
+ setLabelField ( MultilineEnabled, _elementFieldIndex(el) );
|
290
|
+ }
|
291
|
+
|
292
|
} // QgsLabel::readXML()
|
293
|
|
294
|
|
295
|
@@ -1158,6 +1198,26 @@
|
296
|
{
|
297
|
xml << "\t\t\t<bufferenabled on=\"" << "\" field=\"" << "\" />\n";
|
298
|
}
|
299
|
+
|
300
|
+ // multiline enabled
|
301
|
+ if (mLabelAttributes->multilineEnabled())
|
302
|
+ {
|
303
|
+ if (mLabelFieldIdx[MultilineEnabled] != -1)
|
304
|
+ {
|
305
|
+ xml << "\t\t\t<multilineenabled on=\"" << mLabelAttributes->multilineEnabled()
|
306
|
+ << "\" field=\"" << mLabelFieldIdx[MultilineEnabled] << "\" />\n";
|
307
|
+ }
|
308
|
+ else
|
309
|
+ {
|
310
|
+ xml << "\t\t\t<multilineenabled on=\"" << mLabelAttributes->multilineEnabled()
|
311
|
+ << "\" field=\"\" />\n";
|
312
|
+ }
|
313
|
+ }
|
314
|
+ else
|
315
|
+ {
|
316
|
+ xml << "\t\t\t<multilineenabled on=\"" << "\" field=\"" << "\" />\n";
|
317
|
+ }
|
318
|
+
|
319
|
xml << "\t\t</labelattributes>\n";
|
320
|
}
|
321
|
|
322
|
Index: core/qgslabel.h
|
323
|
===================================================================
|
324
|
--- core/qgslabel.h (revision 8705)
|
325
|
+++ core/qgslabel.h (working copy)
|
326
|
@@ -73,6 +73,7 @@
|
327
|
BorderWidth,
|
328
|
BorderColor,
|
329
|
BorderStyle,
|
330
|
+ MultilineEnabled,
|
331
|
LabelFieldCount
|
332
|
};
|
333
|
|
334
|
@@ -127,7 +128,8 @@
|
335
|
QString text, QFont font, QPen pen,
|
336
|
int dx, int dy,
|
337
|
double xoffset, double yoffset,
|
338
|
- double ang);
|
339
|
+ double ang,
|
340
|
+ int width, int height, int alignment);
|
341
|
|
342
|
/** Get label point for simple feature in map units */
|
343
|
void labelPoint ( std::vector<QgsPoint>&, QgsFeature & feature );
|
344
|
Index: core/qgslabelattributes.h
|
345
|
===================================================================
|
346
|
--- core/qgslabelattributes.h (revision 8705)
|
347
|
+++ core/qgslabelattributes.h (working copy)
|
348
|
@@ -171,6 +171,9 @@
|
349
|
void setBorderStyle ( Qt::PenStyle style );
|
350
|
bool borderStyleIsSet ( void ) const;
|
351
|
Qt::PenStyle borderStyle ( void ) const;
|
352
|
+
|
353
|
+ bool multilineEnabled() const;
|
354
|
+ void setMultilineEnabled( bool useMultiline );
|
355
|
|
356
|
protected:
|
357
|
/* Text */
|
358
|
@@ -224,6 +227,9 @@
|
359
|
bool mBorderColorIsSet;
|
360
|
bool mBorderWidthIsSet;
|
361
|
bool mBorderStyleIsSet;
|
362
|
+
|
363
|
+ /** Multiline enablement */
|
364
|
+ bool mMultilineEnabledFlag;
|
365
|
};
|
366
|
|
367
|
#endif
|
368
|
Index: ui/qgslabeldialogbase.ui
|
369
|
===================================================================
|
370
|
--- ui/qgslabeldialogbase.ui (revision 8705)
|
371
|
+++ ui/qgslabeldialogbase.ui (working copy)
|
372
|
@@ -449,6 +449,16 @@
|
373
|
</widget>
|
374
|
</item>
|
375
|
<item row="5" column="0" >
|
376
|
+ <widget class="QCheckBox" name="chkUseMultiline" >
|
377
|
+ <property name="text" >
|
378
|
+ <string>Multiline labels?</string>
|
379
|
+ </property>
|
380
|
+ <property name="checked" >
|
381
|
+ <bool>true</bool>
|
382
|
+ </property>
|
383
|
+ </widget>
|
384
|
+ </item>
|
385
|
+ <item row="6" column="0" >
|
386
|
<spacer>
|
387
|
<property name="orientation" >
|
388
|
<enum>Qt::Vertical</enum>
|