26
25
#include "qgslabelattributes.h"
26
#include "qgslogger.h"
28
28
QgsLabelAttributes::QgsLabelAttributes( bool def )
29
29
: mTextIsSet( false ),
30
mFamilyIsSet( false ),
32
mItalicIsSet( false ),
33
mUnderlineIsSet( false ),
41
mOffsetIsSet( false ),
45
mAlignmentIsSet( false ),
46
mBufferEnabledFlag( false ),
49
mBufferSizeIsSet( false ),
50
mBufferColorIsSet( false ),
51
mBufferStyleIsSet( false ),
52
mBorderColorIsSet( false ),
53
mBorderWidthIsSet( false ),
54
mBorderStyleIsSet( false )
57
if ( def ) { // set defaults
58
setText (QObject::tr("Label"));
60
mFont = QApplication::font();
64
mUnderlineIsSet = true;
66
setSize(12.0, PointUnits);
68
setOffset ( 0, 0, PointUnits );
71
setAlignment ( Qt::AlignCenter );
72
setColor ( QColor(0,0,0) );
74
setBufferSize ( 1, PointUnits );
75
setBufferColor ( QColor(255,255,255) );
76
setBufferStyle ( Qt::NoBrush );
79
setBorderColor ( QColor(0,0,0) );
80
setBorderStyle ( Qt::NoPen );
84
QgsLabelAttributes::~QgsLabelAttributes()
88
void QgsLabelAttributes::setText ( const QString & text )
94
bool QgsLabelAttributes::textIsSet ( void ) const
99
const QString QgsLabelAttributes::text ( void ) const
106
void QgsLabelAttributes::setOffset ( double x, double y, int type )
114
bool QgsLabelAttributes::offsetIsSet ( void ) const
119
int QgsLabelAttributes::offsetType ( void ) const
124
double QgsLabelAttributes::xOffset ( void ) const
129
double QgsLabelAttributes::yOffset ( void ) const
135
void QgsLabelAttributes::setAngle ( double angle )
141
bool QgsLabelAttributes::angleIsSet ( void ) const
146
double QgsLabelAttributes::angle ( void ) const
152
void QgsLabelAttributes::setAlignment ( int alignment )
154
mAlignment = alignment;
155
mAlignmentIsSet = true;
158
bool QgsLabelAttributes::alignmentIsSet ( void ) const
160
return mAlignmentIsSet;
163
int QgsLabelAttributes::alignment ( void ) const
169
void QgsLabelAttributes::setFamily ( const QString & family )
171
mFont.setFamily ( family );
30
mFamilyIsSet( false ),
32
mItalicIsSet( false ),
33
mUnderlineIsSet( false ),
41
mOffsetIsSet( false ),
44
mAngleIsAuto( false ),
46
mAlignmentIsSet( false ),
47
mBufferEnabledFlag( false ),
50
mBufferSizeIsSet( false ),
51
mBufferColorIsSet( false ),
52
mBufferStyleIsSet( false ),
53
mBorderColorIsSet( false ),
54
mBorderWidthIsSet( false ),
55
mBorderStyleIsSet( false ),
56
mMultilineEnabledFlag( false )
59
if ( def ) // set defaults
61
setText( QObject::tr( "Label" ) );
63
mFont = QApplication::font();
172
64
mFamilyIsSet = true;
175
bool QgsLabelAttributes::familyIsSet ( void ) const
180
const QString QgsLabelAttributes::family ( void ) const
182
return mFont.family();
186
void QgsLabelAttributes::setBold ( bool enable )
188
mFont.setBold ( enable );
189
65
mBoldIsSet = true;
192
bool QgsLabelAttributes::boldIsSet ( void ) const
197
bool QgsLabelAttributes::bold ( void ) const
203
void QgsLabelAttributes::setItalic ( bool enable )
205
mFont.setItalic ( enable );
206
66
mItalicIsSet = true;
209
bool QgsLabelAttributes::italicIsSet ( void ) const
214
bool QgsLabelAttributes::italic ( void ) const
216
return mFont.italic();
220
void QgsLabelAttributes::setUnderline ( bool enable )
222
mFont.setUnderline ( enable );
223
67
mUnderlineIsSet = true;
226
bool QgsLabelAttributes::underlineIsSet ( void ) const
228
return mUnderlineIsSet;
231
bool QgsLabelAttributes::underline ( void ) const
233
return mFont.underline();
237
void QgsLabelAttributes::setSize ( double size, int type )
244
bool QgsLabelAttributes::sizeIsSet ( void ) const
249
int QgsLabelAttributes::sizeType ( void ) const
254
double QgsLabelAttributes::size ( void ) const
260
void QgsLabelAttributes::setColor ( const QColor &color )
266
bool QgsLabelAttributes::colorIsSet ( void ) const
271
const QColor & QgsLabelAttributes::color ( void ) const
69
setSize( 12.0, PointUnits );
71
setOffset( 0, 0, PointUnits );
73
setAutoAngle( false );
75
setAlignment( Qt::AlignCenter );
76
setColor( QColor( 0, 0, 0 ) );
78
setBufferSize( 1, PointUnits );
79
setBufferColor( QColor( 255, 255, 255 ) );
80
setBufferStyle( Qt::NoBrush );
83
setBorderColor( QColor( 0, 0, 0 ) );
84
setBorderStyle( Qt::NoPen );
88
QgsLabelAttributes::~QgsLabelAttributes()
92
void QgsLabelAttributes::setText( const QString & text )
98
bool QgsLabelAttributes::textIsSet( void ) const
103
const QString QgsLabelAttributes::text( void ) const
110
void QgsLabelAttributes::setOffset( double x, double y, int type )
118
bool QgsLabelAttributes::offsetIsSet( void ) const
123
int QgsLabelAttributes::offsetType( void ) const
128
double QgsLabelAttributes::xOffset( void ) const
133
double QgsLabelAttributes::yOffset( void ) const
139
void QgsLabelAttributes::setAngle( double angle )
145
bool QgsLabelAttributes::angleIsSet( void ) const
150
double QgsLabelAttributes::angle( void ) const
155
bool QgsLabelAttributes::angleIsAuto() const
160
void QgsLabelAttributes::setAutoAngle( bool state )
162
mAngleIsAuto = state;
166
void QgsLabelAttributes::setAlignment( int alignment )
168
mAlignment = alignment;
169
mAlignmentIsSet = true;
172
bool QgsLabelAttributes::alignmentIsSet( void ) const
174
return mAlignmentIsSet;
177
int QgsLabelAttributes::alignment( void ) const
183
void QgsLabelAttributes::setFamily( const QString & family )
185
mFont.setFamily( family );
189
bool QgsLabelAttributes::familyIsSet( void ) const
194
const QString QgsLabelAttributes::family( void ) const
196
return mFont.family();
200
void QgsLabelAttributes::setBold( bool enable )
202
mFont.setBold( enable );
206
bool QgsLabelAttributes::boldIsSet( void ) const
211
bool QgsLabelAttributes::bold( void ) const
217
void QgsLabelAttributes::setItalic( bool enable )
219
mFont.setItalic( enable );
223
bool QgsLabelAttributes::italicIsSet( void ) const
228
bool QgsLabelAttributes::italic( void ) const
230
return mFont.italic();
234
void QgsLabelAttributes::setUnderline( bool enable )
236
mFont.setUnderline( enable );
237
mUnderlineIsSet = true;
240
bool QgsLabelAttributes::underlineIsSet( void ) const
242
return mUnderlineIsSet;
245
bool QgsLabelAttributes::underline( void ) const
247
return mFont.underline();
251
void QgsLabelAttributes::setSize( double size, int type )
258
bool QgsLabelAttributes::sizeIsSet( void ) const
263
int QgsLabelAttributes::sizeType( void ) const
268
double QgsLabelAttributes::size( void ) const
274
void QgsLabelAttributes::setColor( const QColor &color )
280
bool QgsLabelAttributes::colorIsSet( void ) const
285
const QColor & QgsLabelAttributes::color( void ) const
277
291
bool QgsLabelAttributes::bufferEnabled() const
279
293
return mBufferEnabledFlag;
281
void QgsLabelAttributes::setBufferEnabled(bool useBufferFlag)
283
mBufferEnabledFlag=useBufferFlag;
285
void QgsLabelAttributes::setBufferSize ( double size, int type )
287
mBufferSizeType = type;
289
mBufferSizeIsSet = true;
292
bool QgsLabelAttributes::bufferSizeIsSet ( void ) const
294
return mBufferSizeIsSet;
297
int QgsLabelAttributes::bufferSizeType ( void ) const
299
return mBufferSizeType;
302
double QgsLabelAttributes::bufferSize ( void ) const
308
void QgsLabelAttributes::setBufferColor ( const QColor &color )
310
mBufferBrush.setColor ( color );
311
mBufferColorIsSet = true;
314
bool QgsLabelAttributes::bufferColorIsSet ( void ) const
319
QColor QgsLabelAttributes::bufferColor ( void ) const
321
return mBufferBrush.color();
325
void QgsLabelAttributes::setBufferStyle ( Qt::BrushStyle style )
327
mBufferBrush.setStyle ( style );
328
mBufferStyleIsSet = true;
331
bool QgsLabelAttributes::bufferStyleIsSet ( void ) const
333
return mBufferStyleIsSet;
336
Qt::BrushStyle QgsLabelAttributes::bufferStyle ( void ) const
338
return mBufferBrush.style();
342
void QgsLabelAttributes::setBorderColor ( const QColor &color )
344
mBorderPen.setColor ( color );
345
mBorderColorIsSet = true;
348
bool QgsLabelAttributes::borderColorIsSet ( void ) const
350
return mBorderColorIsSet;
353
QColor QgsLabelAttributes::borderColor ( void ) const
355
return mBorderPen.color();
358
void QgsLabelAttributes::setBorderWidth ( int width )
360
mBorderPen.setWidth ( width );
361
mBorderWidthIsSet = true;
364
bool QgsLabelAttributes::borderWidthIsSet ( void ) const
366
return mBorderWidthIsSet;
369
int QgsLabelAttributes::borderWidth ( void ) const
371
return mBorderPen.width();
375
void QgsLabelAttributes::setBorderStyle ( Qt::PenStyle style )
377
mBorderPen.setStyle ( style );
378
mBorderStyleIsSet = true;
381
bool QgsLabelAttributes::borderStyleIsSet ( void ) const
383
return mBorderStyleIsSet;
386
Qt::PenStyle QgsLabelAttributes::borderStyle ( void ) const
388
return mBorderPen.style();
391
QString QgsLabelAttributes::unitsName ( int units )
393
if ( units == MapUnits ){
394
return QString("mu");
397
return QString("pt");
400
int QgsLabelAttributes::unitsCode ( const QString &name )
402
if ( name.compare("mu") == 0 ) {
409
QString QgsLabelAttributes::alignmentName ( int alignment )
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");
425
int QgsLabelAttributes::alignmentCode ( const QString &name )
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 )
297
mBufferEnabledFlag = useBufferFlag;
299
void QgsLabelAttributes::setBufferSize( double size, int type )
301
mBufferSizeType = type;
303
mBufferSizeIsSet = true;
306
bool QgsLabelAttributes::bufferSizeIsSet( void ) const
308
return mBufferSizeIsSet;
311
int QgsLabelAttributes::bufferSizeType( void ) const
313
return mBufferSizeType;
316
double QgsLabelAttributes::bufferSize( void ) const
322
void QgsLabelAttributes::setBufferColor( const QColor &color )
324
mBufferBrush.setColor( color );
325
mBufferColorIsSet = true;
328
bool QgsLabelAttributes::bufferColorIsSet( void ) const
333
QColor QgsLabelAttributes::bufferColor( void ) const
335
return mBufferBrush.color();
339
void QgsLabelAttributes::setBufferStyle( Qt::BrushStyle style )
341
mBufferBrush.setStyle( style );
342
mBufferStyleIsSet = true;
345
bool QgsLabelAttributes::bufferStyleIsSet( void ) const
347
return mBufferStyleIsSet;
350
Qt::BrushStyle QgsLabelAttributes::bufferStyle( void ) const
352
return mBufferBrush.style();
356
void QgsLabelAttributes::setBorderColor( const QColor &color )
358
mBorderPen.setColor( color );
359
mBorderColorIsSet = true;
362
bool QgsLabelAttributes::borderColorIsSet( void ) const
364
return mBorderColorIsSet;
367
QColor QgsLabelAttributes::borderColor( void ) const
369
return mBorderPen.color();
372
void QgsLabelAttributes::setBorderWidth( int width )
374
mBorderPen.setWidth( width );
375
mBorderWidthIsSet = true;
378
bool QgsLabelAttributes::borderWidthIsSet( void ) const
380
return mBorderWidthIsSet;
383
int QgsLabelAttributes::borderWidth( void ) const
385
return mBorderPen.width();
389
void QgsLabelAttributes::setBorderStyle( Qt::PenStyle style )
391
mBorderPen.setStyle( style );
392
mBorderStyleIsSet = true;
395
bool QgsLabelAttributes::borderStyleIsSet( void ) const
397
return mBorderStyleIsSet;
400
Qt::PenStyle QgsLabelAttributes::borderStyle( void ) const
402
return mBorderPen.style();
406
bool QgsLabelAttributes::multilineEnabled() const
408
return mMultilineEnabledFlag;
410
void QgsLabelAttributes::setMultilineEnabled( bool useMultilineFlag )
412
mMultilineEnabledFlag = useMultilineFlag;
416
QString QgsLabelAttributes::unitsName( int units )
418
if ( units == MapUnits )
420
return QString( "mu" );
423
return QString( "pt" );
426
int QgsLabelAttributes::unitsCode( const QString &name )
428
if ( name.compare( "mu" ) == 0 )
437
QString QgsLabelAttributes::alignmentName( int alignment )
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" );
453
int QgsLabelAttributes::alignmentCode( const QString &name )
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 ;
439
467
return Qt::AlignCenter;