~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/core/qgslabelattributes.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 *   (at your option) any later version.                                   *
14
14
 *                                                                         *
15
15
 ***************************************************************************/
16
 
/* $Id: qgslabelattributes.cpp 5886 2006-09-30 05:58:51Z g_j_m $ */
17
 
#include <iostream>
 
16
/* $Id$ */
18
17
 
19
18
#include <QApplication>
20
19
#include <QString>
24
23
#include <QBrush>
25
24
 
26
25
#include "qgslabelattributes.h"
 
26
#include "qgslogger.h"
27
27
 
28
28
QgsLabelAttributes::QgsLabelAttributes( bool def )
29
29
    : mTextIsSet( false ),
30
 
      mFamilyIsSet( false ),
31
 
      mBoldIsSet( false ),
32
 
      mItalicIsSet( false ),
33
 
      mUnderlineIsSet( false ),
34
 
      mSizeType( 0 ),
35
 
      mSize( 0.0 ),
36
 
      mSizeIsSet( false ),
37
 
      mColorIsSet( false ),
38
 
      mOffsetType( 0 ),
39
 
      mXOffset( 0 ),
40
 
      mYOffset( 0 ),
41
 
      mOffsetIsSet( false ),
42
 
      mAngle( 0.0 ),
43
 
      mAngleIsSet( false ),
44
 
      mAlignment( 0 ),
45
 
      mAlignmentIsSet( false ),
46
 
      mBufferEnabledFlag( false ),
47
 
      mBufferSizeType( 0 ),
48
 
      mBufferSize( 0.0 ),
49
 
      mBufferSizeIsSet( false ),
50
 
      mBufferColorIsSet( false ),
51
 
      mBufferStyleIsSet( false ),
52
 
      mBorderColorIsSet( false ),
53
 
      mBorderWidthIsSet( false ),
54
 
      mBorderStyleIsSet( false )
55
 
{
56
 
 
57
 
    if ( def ) { // set defaults
58
 
        setText (QObject::tr("Label"));
59
 
 
60
 
        mFont = QApplication::font();
61
 
        mFamilyIsSet = true;
62
 
        mBoldIsSet = true;
63
 
        mItalicIsSet = true;
64
 
        mUnderlineIsSet = true;
65
 
 
66
 
        setSize(12.0, PointUnits);
67
 
        
68
 
        setOffset ( 0, 0, PointUnits );
69
 
        setAngle ( 0 );
70
 
        
71
 
        setAlignment ( Qt::AlignCenter );
72
 
        setColor ( QColor(0,0,0) );
73
 
 
74
 
        setBufferSize ( 1, PointUnits );
75
 
        setBufferColor ( QColor(255,255,255) );
76
 
        setBufferStyle ( Qt::NoBrush );
77
 
        
78
 
        setBorderWidth ( 0 );
79
 
        setBorderColor ( QColor(0,0,0) );
80
 
        setBorderStyle ( Qt::NoPen );
81
 
    }
82
 
}
83
 
 
84
 
QgsLabelAttributes::~QgsLabelAttributes()
85
 
{
86
 
}
87
 
  /* Text */
88
 
void QgsLabelAttributes::setText ( const QString & text )
89
 
{
90
 
    mText = text;
91
 
    mTextIsSet = true;
92
 
}
93
 
 
94
 
bool QgsLabelAttributes::textIsSet ( void ) const
95
 
{
96
 
    return mTextIsSet;
97
 
}
98
 
 
99
 
const QString QgsLabelAttributes::text ( void ) const
100
 
{
101
 
    return mText;
102
 
}
103
 
 
104
 
 
105
 
  /* Offset */
106
 
void QgsLabelAttributes::setOffset ( double x, double y, int type )
107
 
{
108
 
    mOffsetType = type;
109
 
    mXOffset = x;
110
 
    mYOffset = y;
111
 
    mOffsetIsSet = true;
112
 
}
113
 
 
114
 
bool QgsLabelAttributes::offsetIsSet ( void ) const
115
 
{
116
 
    return mOffsetIsSet;
117
 
}
118
 
 
119
 
int QgsLabelAttributes::offsetType ( void ) const
120
 
{
121
 
    return mOffsetType;
122
 
}
123
 
 
124
 
double QgsLabelAttributes::xOffset ( void ) const
125
 
{
126
 
    return mXOffset;
127
 
}
128
 
 
129
 
double QgsLabelAttributes::yOffset ( void ) const
130
 
{
131
 
    return mYOffset;
132
 
}
133
 
 
134
 
  /* Angle */
135
 
void QgsLabelAttributes::setAngle ( double angle )
136
 
{
137
 
    mAngle = angle;
138
 
    mAngleIsSet = true;
139
 
}
140
 
 
141
 
bool QgsLabelAttributes::angleIsSet ( void ) const
142
 
{
143
 
    return mAngleIsSet;
144
 
}
145
 
 
146
 
double QgsLabelAttributes::angle ( void ) const
147
 
{
148
 
    return mAngle;
149
 
}
150
 
 
151
 
  /* Alignment */
152
 
void QgsLabelAttributes::setAlignment ( int alignment )
153
 
{
154
 
    mAlignment = alignment;
155
 
    mAlignmentIsSet = true;
156
 
}
157
 
 
158
 
bool QgsLabelAttributes::alignmentIsSet ( void ) const
159
 
{
160
 
    return mAlignmentIsSet;
161
 
}
162
 
 
163
 
int QgsLabelAttributes::alignment ( void ) const
164
 
{
165
 
    return mAlignment;
166
 
}
167
 
 
168
 
  /* Font */
169
 
void QgsLabelAttributes::setFamily ( const QString & family )
170
 
{
171
 
    mFont.setFamily ( family );
 
30
    mFamilyIsSet( false ),
 
31
    mBoldIsSet( false ),
 
32
    mItalicIsSet( false ),
 
33
    mUnderlineIsSet( false ),
 
34
    mSizeType( 0 ),
 
35
    mSize( 0.0 ),
 
36
    mSizeIsSet( false ),
 
37
    mColorIsSet( false ),
 
38
    mOffsetType( 0 ),
 
39
    mXOffset( 0 ),
 
40
    mYOffset( 0 ),
 
41
    mOffsetIsSet( false ),
 
42
    mAngle( 0.0 ),
 
43
    mAngleIsSet( false ),
 
44
    mAngleIsAuto( false ),
 
45
    mAlignment( 0 ),
 
46
    mAlignmentIsSet( false ),
 
47
    mBufferEnabledFlag( false ),
 
48
    mBufferSizeType( 0 ),
 
49
    mBufferSize( 0.0 ),
 
50
    mBufferSizeIsSet( false ),
 
51
    mBufferColorIsSet( false ),
 
52
    mBufferStyleIsSet( false ),
 
53
    mBorderColorIsSet( false ),
 
54
    mBorderWidthIsSet( false ),
 
55
    mBorderStyleIsSet( false ),
 
56
    mMultilineEnabledFlag( false )
 
57
{
 
58
 
 
59
  if ( def )   // set defaults
 
60
  {
 
61
    setText( QObject::tr( "Label" ) );
 
62
 
 
63
    mFont = QApplication::font();
172
64
    mFamilyIsSet = true;
173
 
}
174
 
 
175
 
bool QgsLabelAttributes::familyIsSet ( void ) const
176
 
{
177
 
    return mFamilyIsSet;
178
 
}
179
 
 
180
 
const QString QgsLabelAttributes::family ( void ) const
181
 
{
182
 
    return mFont.family();
183
 
}
184
 
 
185
 
 
186
 
void QgsLabelAttributes::setBold ( bool enable )
187
 
{
188
 
    mFont.setBold ( enable );
189
65
    mBoldIsSet = true;
190
 
}
191
 
 
192
 
bool QgsLabelAttributes::boldIsSet ( void ) const
193
 
{
194
 
    return mBoldIsSet;
195
 
}
196
 
 
197
 
bool QgsLabelAttributes::bold ( void ) const
198
 
{
199
 
    return mFont.bold();
200
 
}
201
 
 
202
 
 
203
 
void QgsLabelAttributes::setItalic ( bool enable )
204
 
{
205
 
    mFont.setItalic ( enable );
206
66
    mItalicIsSet = true;
207
 
}
208
 
 
209
 
bool QgsLabelAttributes::italicIsSet ( void ) const
210
 
{
211
 
    return mItalicIsSet;
212
 
}
213
 
 
214
 
bool QgsLabelAttributes::italic ( void ) const
215
 
{
216
 
    return mFont.italic();
217
 
}
218
 
 
219
 
 
220
 
void QgsLabelAttributes::setUnderline ( bool enable )
221
 
{
222
 
    mFont.setUnderline ( enable );
223
67
    mUnderlineIsSet = true;
224
 
}
225
 
 
226
 
bool QgsLabelAttributes::underlineIsSet ( void ) const
227
 
{
228
 
    return mUnderlineIsSet;
229
 
}
230
 
 
231
 
bool QgsLabelAttributes::underline ( void ) const
232
 
{
233
 
    return mFont.underline();
234
 
}
235
 
 
236
 
 
237
 
void QgsLabelAttributes::setSize ( double size, int type )
238
 
{
239
 
    mSizeType = type;
240
 
    mSize = size;
241
 
    mSizeIsSet = true;
242
 
}
243
 
 
244
 
bool QgsLabelAttributes::sizeIsSet ( void ) const
245
 
{
246
 
    return mSizeIsSet;
247
 
}
248
 
 
249
 
int QgsLabelAttributes::sizeType ( void ) const
250
 
{
251
 
    return mSizeType;
252
 
}
253
 
 
254
 
double QgsLabelAttributes::size ( void ) const
255
 
{
256
 
    return mSize;
257
 
}
258
 
 
259
 
 
260
 
void QgsLabelAttributes::setColor ( const QColor &color )
261
 
{
262
 
    mColor = color;
263
 
    mColorIsSet = true;
264
 
}
265
 
 
266
 
bool QgsLabelAttributes::colorIsSet ( void ) const
267
 
{
268
 
    return mColorIsSet;
269
 
}
270
 
 
271
 
const QColor & QgsLabelAttributes::color ( void ) const
272
 
{
273
 
    return mColor;
274
 
}
275
 
 
276
 
  /* Buffer */
 
68
 
 
69
    setSize( 12.0, PointUnits );
 
70
 
 
71
    setOffset( 0, 0, PointUnits );
 
72
    setAngle( 0 );
 
73
    setAutoAngle( false );
 
74
 
 
75
    setAlignment( Qt::AlignCenter );
 
76
    setColor( QColor( 0, 0, 0 ) );
 
77
 
 
78
    setBufferSize( 1, PointUnits );
 
79
    setBufferColor( QColor( 255, 255, 255 ) );
 
80
    setBufferStyle( Qt::NoBrush );
 
81
 
 
82
    setBorderWidth( 0 );
 
83
    setBorderColor( QColor( 0, 0, 0 ) );
 
84
    setBorderStyle( Qt::NoPen );
 
85
  }
 
86
}
 
87
 
 
88
QgsLabelAttributes::~QgsLabelAttributes()
 
89
{
 
90
}
 
91
/* Text */
 
92
void QgsLabelAttributes::setText( const QString & text )
 
93
{
 
94
  mText = text;
 
95
  mTextIsSet = true;
 
96
}
 
97
 
 
98
bool QgsLabelAttributes::textIsSet( void ) const
 
99
{
 
100
  return mTextIsSet;
 
101
}
 
102
 
 
103
const QString QgsLabelAttributes::text( void ) const
 
104
{
 
105
  return mText;
 
106
}
 
107
 
 
108
 
 
109
/* Offset */
 
110
void QgsLabelAttributes::setOffset( double x, double y, int type )
 
111
{
 
112
  mOffsetType = type;
 
113
  mXOffset = x;
 
114
  mYOffset = y;
 
115
  mOffsetIsSet = true;
 
116
}
 
117
 
 
118
bool QgsLabelAttributes::offsetIsSet( void ) const
 
119
{
 
120
  return mOffsetIsSet;
 
121
}
 
122
 
 
123
int QgsLabelAttributes::offsetType( void ) const
 
124
{
 
125
  return mOffsetType;
 
126
}
 
127
 
 
128
double QgsLabelAttributes::xOffset( void ) const
 
129
{
 
130
  return mXOffset;
 
131
}
 
132
 
 
133
double QgsLabelAttributes::yOffset( void ) const
 
134
{
 
135
  return mYOffset;
 
136
}
 
137
 
 
138
/* Angle */
 
139
void QgsLabelAttributes::setAngle( double angle )
 
140
{
 
141
  mAngle = angle;
 
142
  mAngleIsSet = true;
 
143
}
 
144
 
 
145
bool QgsLabelAttributes::angleIsSet( void ) const
 
146
{
 
147
  return mAngleIsSet;
 
148
}
 
149
 
 
150
double QgsLabelAttributes::angle( void ) const
 
151
{
 
152
  return mAngle;
 
153
}
 
154
 
 
155
bool QgsLabelAttributes::angleIsAuto() const
 
156
{
 
157
  return mAngleIsAuto;
 
158
}
 
159
 
 
160
void QgsLabelAttributes::setAutoAngle( bool state )
 
161
{
 
162
  mAngleIsAuto = state;
 
163
}
 
164
 
 
165
/* Alignment */
 
166
void QgsLabelAttributes::setAlignment( int alignment )
 
167
{
 
168
  mAlignment = alignment;
 
169
  mAlignmentIsSet = true;
 
170
}
 
171
 
 
172
bool QgsLabelAttributes::alignmentIsSet( void ) const
 
173
{
 
174
  return mAlignmentIsSet;
 
175
}
 
176
 
 
177
int QgsLabelAttributes::alignment( void ) const
 
178
{
 
179
  return mAlignment;
 
180
}
 
181
 
 
182
/* Font */
 
183
void QgsLabelAttributes::setFamily( const QString & family )
 
184
{
 
185
  mFont.setFamily( family );
 
186
  mFamilyIsSet = true;
 
187
}
 
188
 
 
189
bool QgsLabelAttributes::familyIsSet( void ) const
 
190
{
 
191
  return mFamilyIsSet;
 
192
}
 
193
 
 
194
const QString QgsLabelAttributes::family( void ) const
 
195
{
 
196
  return mFont.family();
 
197
}
 
198
 
 
199
 
 
200
void QgsLabelAttributes::setBold( bool enable )
 
201
{
 
202
  mFont.setBold( enable );
 
203
  mBoldIsSet = true;
 
204
}
 
205
 
 
206
bool QgsLabelAttributes::boldIsSet( void ) const
 
207
{
 
208
  return mBoldIsSet;
 
209
}
 
210
 
 
211
bool QgsLabelAttributes::bold( void ) const
 
212
{
 
213
  return mFont.bold();
 
214
}
 
215
 
 
216
 
 
217
void QgsLabelAttributes::setItalic( bool enable )
 
218
{
 
219
  mFont.setItalic( enable );
 
220
  mItalicIsSet = true;
 
221
}
 
222
 
 
223
bool QgsLabelAttributes::italicIsSet( void ) const
 
224
{
 
225
  return mItalicIsSet;
 
226
}
 
227
 
 
228
bool QgsLabelAttributes::italic( void ) const
 
229
{
 
230
  return mFont.italic();
 
231
}
 
232
 
 
233
 
 
234
void QgsLabelAttributes::setUnderline( bool enable )
 
235
{
 
236
  mFont.setUnderline( enable );
 
237
  mUnderlineIsSet = true;
 
238
}
 
239
 
 
240
bool QgsLabelAttributes::underlineIsSet( void ) const
 
241
{
 
242
  return mUnderlineIsSet;
 
243
}
 
244
 
 
245
bool QgsLabelAttributes::underline( void ) const
 
246
{
 
247
  return mFont.underline();
 
248
}
 
249
 
 
250
 
 
251
void QgsLabelAttributes::setSize( double size, int type )
 
252
{
 
253
  mSizeType = type;
 
254
  mSize = size;
 
255
  mSizeIsSet = true;
 
256
}
 
257
 
 
258
bool QgsLabelAttributes::sizeIsSet( void ) const
 
259
{
 
260
  return mSizeIsSet;
 
261
}
 
262
 
 
263
int QgsLabelAttributes::sizeType( void ) const
 
264
{
 
265
  return mSizeType;
 
266
}
 
267
 
 
268
double QgsLabelAttributes::size( void ) const
 
269
{
 
270
  return mSize;
 
271
}
 
272
 
 
273
 
 
274
void QgsLabelAttributes::setColor( const QColor &color )
 
275
{
 
276
  mColor = color;
 
277
  mColorIsSet = true;
 
278
}
 
279
 
 
280
bool QgsLabelAttributes::colorIsSet( void ) const
 
281
{
 
282
  return mColorIsSet;
 
283
}
 
284
 
 
285
const QColor & QgsLabelAttributes::color( void ) const
 
286
{
 
287
  return mColor;
 
288
}
 
289
 
 
290
/* Buffer */
277
291
bool QgsLabelAttributes::bufferEnabled() const
278
292
{
279
293
  return mBufferEnabledFlag;
280
294
}
281
 
void QgsLabelAttributes::setBufferEnabled(bool useBufferFlag)
282
 
{
283
 
 mBufferEnabledFlag=useBufferFlag;   
284
 
}
285
 
void QgsLabelAttributes::setBufferSize ( double size, int type )
286
 
{
287
 
    mBufferSizeType = type;
288
 
    mBufferSize = size;
289
 
    mBufferSizeIsSet = true;
290
 
}
291
 
 
292
 
bool QgsLabelAttributes::bufferSizeIsSet ( void ) const
293
 
{
294
 
    return mBufferSizeIsSet;
295
 
}
296
 
 
297
 
int QgsLabelAttributes::bufferSizeType ( void ) const
298
 
{
299
 
    return mBufferSizeType;
300
 
}
301
 
 
302
 
double QgsLabelAttributes::bufferSize ( void ) const
303
 
{
304
 
    return mBufferSize;
305
 
}
306
 
 
307
 
 
308
 
void QgsLabelAttributes::setBufferColor ( const QColor &color )
309
 
{
310
 
    mBufferBrush.setColor ( color );
311
 
    mBufferColorIsSet = true;
312
 
}
313
 
 
314
 
bool QgsLabelAttributes::bufferColorIsSet ( void ) const
315
 
{
316
 
    return mColorIsSet;
317
 
}
318
 
 
319
 
QColor QgsLabelAttributes::bufferColor ( void ) const
320
 
{
321
 
    return mBufferBrush.color();
322
 
}
323
 
 
324
 
 
325
 
void QgsLabelAttributes::setBufferStyle ( Qt::BrushStyle style )
326
 
{
327
 
    mBufferBrush.setStyle ( style );
328
 
    mBufferStyleIsSet = true;
329
 
}
330
 
 
331
 
bool QgsLabelAttributes::bufferStyleIsSet ( void ) const
332
 
{
333
 
    return mBufferStyleIsSet;
334
 
}
335
 
 
336
 
Qt::BrushStyle QgsLabelAttributes::bufferStyle ( void ) const
337
 
{
338
 
    return mBufferBrush.style();
339
 
}
340
 
 
341
 
  /* Border */
342
 
void QgsLabelAttributes::setBorderColor ( const QColor &color )
343
 
{
344
 
    mBorderPen.setColor ( color );
345
 
    mBorderColorIsSet = true;
346
 
}
347
 
 
348
 
bool QgsLabelAttributes::borderColorIsSet ( void ) const
349
 
{
350
 
    return mBorderColorIsSet;
351
 
}
352
 
 
353
 
QColor QgsLabelAttributes::borderColor ( void ) const
354
 
{
355
 
    return mBorderPen.color();
356
 
}
357
 
 
358
 
void QgsLabelAttributes::setBorderWidth ( int width )
359
 
{
360
 
    mBorderPen.setWidth ( width );
361
 
    mBorderWidthIsSet = true;
362
 
}
363
 
 
364
 
bool QgsLabelAttributes::borderWidthIsSet ( void ) const 
365
 
{
366
 
    return mBorderWidthIsSet;
367
 
}
368
 
 
369
 
int QgsLabelAttributes::borderWidth ( void ) const
370
 
{
371
 
    return mBorderPen.width();
372
 
}
373
 
 
374
 
 
375
 
void QgsLabelAttributes::setBorderStyle ( Qt::PenStyle style )
376
 
{
377
 
     mBorderPen.setStyle ( style );
378
 
     mBorderStyleIsSet = true;
379
 
}
380
 
 
381
 
bool QgsLabelAttributes::borderStyleIsSet ( void ) const
382
 
{
383
 
    return mBorderStyleIsSet;
384
 
}
385
 
 
386
 
Qt::PenStyle QgsLabelAttributes::borderStyle ( void ) const
387
 
{
388
 
    return mBorderPen.style();
389
 
}
390
 
 
391
 
QString QgsLabelAttributes::unitsName ( int units ) 
392
 
{
393
 
    if ( units == MapUnits ){ 
394
 
        return QString("mu");
395
 
    }
396
 
        
397
 
    return QString("pt");
398
 
}
399
 
 
400
 
int QgsLabelAttributes::unitsCode ( const QString &name )
401
 
{
402
 
    if ( name.compare("mu") == 0 ) {
403
 
        return MapUnits;
404
 
    }
405
 
        
406
 
    return PointUnits;
407
 
}
408
 
 
409
 
QString QgsLabelAttributes::alignmentName ( int alignment ) 
410
 
{
411
 
  std::cout << "QString QgsLabelAttributes::alignmentName (" << alignment << ")" << std::endl;
412
 
  if (!alignment)                                       return  QString("center");
413
 
  if (alignment == (Qt::AlignRight | Qt::AlignBottom )) return  QString("aboveleft");
414
 
  if (alignment == (Qt::AlignRight | Qt::AlignTop    )) return  QString("belowleft"); 
415
 
  if (alignment == (Qt::AlignLeft  | Qt::AlignBottom )) return  QString("aboveright");
416
 
  if (alignment == (Qt::AlignLeft  | Qt::AlignTop    )) return  QString("belowright");
417
 
  if (alignment == (Qt::AlignRight | Qt::AlignVCenter)) return  QString("left");
418
 
  if (alignment == (Qt::AlignLeft  | Qt::AlignVCenter)) return  QString("right");
419
 
  if (alignment == (Qt::AlignBottom| Qt::AlignHCenter)) return  QString("above"); 
420
 
  if (alignment == (Qt::AlignTop   | Qt::AlignHCenter)) return  QString("below"); 
421
 
  if (alignment == (Qt::AlignCenter                  )) return  QString("center");
422
 
  return QString("center");
423
 
}
424
 
 
425
 
int QgsLabelAttributes::alignmentCode ( const QString &name ) 
426
 
{
427
 
  QString lname = name.lower();
428
 
  if (lname.compare("aboveleft")  == 0)  return Qt::AlignRight | Qt::AlignBottom     ;
429
 
  if (lname.compare("belowleft")  == 0)  return Qt::AlignRight | Qt::AlignTop        ; 
430
 
  if (lname.compare("aboveright")  == 0) return Qt::AlignLeft  | Qt::AlignBottom     ;
431
 
  if (lname.compare("belowright")  == 0) return Qt::AlignLeft  | Qt::AlignTop        ;
432
 
  if (lname.compare("left")  == 0)       return Qt::AlignRight | Qt::AlignVCenter    ;
433
 
  if (lname.compare("right")  == 0)      return Qt::AlignLeft  | Qt::AlignVCenter    ;
434
 
  if (lname.compare("above")  == 0)      return Qt::AlignBottom| Qt::AlignHCenter    ; 
435
 
  if (lname.compare("below")  == 0)      return Qt::AlignTop   | Qt::AlignHCenter    ; 
436
 
  if (lname.compare("center")  == 0)       return Qt::AlignCenter                      ;  
 
295
void QgsLabelAttributes::setBufferEnabled( bool useBufferFlag )
 
296
{
 
297
  mBufferEnabledFlag = useBufferFlag;
 
298
}
 
299
void QgsLabelAttributes::setBufferSize( double size, int type )
 
300
{
 
301
  mBufferSizeType = type;
 
302
  mBufferSize = size;
 
303
  mBufferSizeIsSet = true;
 
304
}
 
305
 
 
306
bool QgsLabelAttributes::bufferSizeIsSet( void ) const
 
307
{
 
308
  return mBufferSizeIsSet;
 
309
}
 
310
 
 
311
int QgsLabelAttributes::bufferSizeType( void ) const
 
312
{
 
313
  return mBufferSizeType;
 
314
}
 
315
 
 
316
double QgsLabelAttributes::bufferSize( void ) const
 
317
{
 
318
  return mBufferSize;
 
319
}
 
320
 
 
321
 
 
322
void QgsLabelAttributes::setBufferColor( const QColor &color )
 
323
{
 
324
  mBufferBrush.setColor( color );
 
325
  mBufferColorIsSet = true;
 
326
}
 
327
 
 
328
bool QgsLabelAttributes::bufferColorIsSet( void ) const
 
329
{
 
330
  return mColorIsSet;
 
331
}
 
332
 
 
333
QColor QgsLabelAttributes::bufferColor( void ) const
 
334
{
 
335
  return mBufferBrush.color();
 
336
}
 
337
 
 
338
 
 
339
void QgsLabelAttributes::setBufferStyle( Qt::BrushStyle style )
 
340
{
 
341
  mBufferBrush.setStyle( style );
 
342
  mBufferStyleIsSet = true;
 
343
}
 
344
 
 
345
bool QgsLabelAttributes::bufferStyleIsSet( void ) const
 
346
{
 
347
  return mBufferStyleIsSet;
 
348
}
 
349
 
 
350
Qt::BrushStyle QgsLabelAttributes::bufferStyle( void ) const
 
351
{
 
352
  return mBufferBrush.style();
 
353
}
 
354
 
 
355
/* Border */
 
356
void QgsLabelAttributes::setBorderColor( const QColor &color )
 
357
{
 
358
  mBorderPen.setColor( color );
 
359
  mBorderColorIsSet = true;
 
360
}
 
361
 
 
362
bool QgsLabelAttributes::borderColorIsSet( void ) const
 
363
{
 
364
  return mBorderColorIsSet;
 
365
}
 
366
 
 
367
QColor QgsLabelAttributes::borderColor( void ) const
 
368
{
 
369
  return mBorderPen.color();
 
370
}
 
371
 
 
372
void QgsLabelAttributes::setBorderWidth( int width )
 
373
{
 
374
  mBorderPen.setWidth( width );
 
375
  mBorderWidthIsSet = true;
 
376
}
 
377
 
 
378
bool QgsLabelAttributes::borderWidthIsSet( void ) const
 
379
{
 
380
  return mBorderWidthIsSet;
 
381
}
 
382
 
 
383
int QgsLabelAttributes::borderWidth( void ) const
 
384
{
 
385
  return mBorderPen.width();
 
386
}
 
387
 
 
388
 
 
389
void QgsLabelAttributes::setBorderStyle( Qt::PenStyle style )
 
390
{
 
391
  mBorderPen.setStyle( style );
 
392
  mBorderStyleIsSet = true;
 
393
}
 
394
 
 
395
bool QgsLabelAttributes::borderStyleIsSet( void ) const
 
396
{
 
397
  return mBorderStyleIsSet;
 
398
}
 
399
 
 
400
Qt::PenStyle QgsLabelAttributes::borderStyle( void ) const
 
401
{
 
402
  return mBorderPen.style();
 
403
}
 
404
 
 
405
/* Multiline */
 
406
bool QgsLabelAttributes::multilineEnabled() const
 
407
{
 
408
  return mMultilineEnabledFlag;
 
409
}
 
410
void QgsLabelAttributes::setMultilineEnabled( bool useMultilineFlag )
 
411
{
 
412
  mMultilineEnabledFlag = useMultilineFlag;
 
413
}
 
414
 
 
415
/* units */
 
416
QString QgsLabelAttributes::unitsName( int units )
 
417
{
 
418
  if ( units == MapUnits )
 
419
  {
 
420
    return QString( "mu" );
 
421
  }
 
422
 
 
423
  return QString( "pt" );
 
424
}
 
425
 
 
426
int QgsLabelAttributes::unitsCode( const QString &name )
 
427
{
 
428
  if ( name.compare( "mu" ) == 0 )
 
429
  {
 
430
    return MapUnits;
 
431
  }
 
432
 
 
433
  return PointUnits;
 
434
}
 
435
 
 
436
/* alignment */
 
437
QString QgsLabelAttributes::alignmentName( int alignment )
 
438
{
 
439
  QgsDebugMsg( QString( "alignment=%1" ).arg( alignment ) );
 
440
  if ( !alignment )                                       return  QString( "center" );
 
441
  if ( alignment == ( Qt::AlignRight | Qt::AlignBottom ) ) return  QString( "aboveleft" );
 
442
  if ( alignment == ( Qt::AlignRight | Qt::AlignTop ) ) return  QString( "belowleft" );
 
443
  if ( alignment == ( Qt::AlignLeft  | Qt::AlignBottom ) ) return  QString( "aboveright" );
 
444
  if ( alignment == ( Qt::AlignLeft  | Qt::AlignTop ) ) return  QString( "belowright" );
 
445
  if ( alignment == ( Qt::AlignRight | Qt::AlignVCenter ) ) return  QString( "left" );
 
446
  if ( alignment == ( Qt::AlignLeft  | Qt::AlignVCenter ) ) return  QString( "right" );
 
447
  if ( alignment == ( Qt::AlignBottom | Qt::AlignHCenter ) ) return  QString( "above" );
 
448
  if ( alignment == ( Qt::AlignTop   | Qt::AlignHCenter ) ) return  QString( "below" );
 
449
  if ( alignment == ( Qt::AlignCenter ) ) return  QString( "center" );
 
450
  return QString( "center" );
 
451
}
 
452
 
 
453
int QgsLabelAttributes::alignmentCode( const QString &name )
 
454
{
 
455
  QString lname = name.toLower();
 
456
  if ( lname.compare( "aboveleft" )  == 0 )  return Qt::AlignRight | Qt::AlignBottom     ;
 
457
  if ( lname.compare( "belowleft" )  == 0 )  return Qt::AlignRight | Qt::AlignTop        ;
 
458
  if ( lname.compare( "aboveright" )  == 0 ) return Qt::AlignLeft  | Qt::AlignBottom     ;
 
459
  if ( lname.compare( "belowright" )  == 0 ) return Qt::AlignLeft  | Qt::AlignTop        ;
 
460
  if ( lname.compare( "left" )  == 0 )       return Qt::AlignRight | Qt::AlignVCenter    ;
 
461
  if ( lname.compare( "right" )  == 0 )      return Qt::AlignLeft  | Qt::AlignVCenter    ;
 
462
  if ( lname.compare( "above" )  == 0 )      return Qt::AlignBottom | Qt::AlignHCenter    ;
 
463
  if ( lname.compare( "below" )  == 0 )      return Qt::AlignTop   | Qt::AlignHCenter    ;
 
464
  if ( lname.compare( "center" )  == 0 )       return Qt::AlignCenter                      ;
437
465
 
438
466
 
439
467
  return Qt::AlignCenter;