Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgslabelattributes.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslabel.cpp - render vector labels
3  -------------------
4  begin : August 2004
5  copyright : (C) 2004 by Radim Blazek
6  email : blazek@itc.it
7  ***************************************************************************/
8 /***************************************************************************
9  * *
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. *
14  * *
15  ***************************************************************************/
16 /* $Id$ */
17 
18 #include <QApplication>
19 #include <QString>
20 #include <QFont>
21 #include <QColor>
22 #include <QPen>
23 #include <QBrush>
24 
25 #include "qgslabelattributes.h"
26 #include "qgslogger.h"
27 
29  : mTextIsSet( false )
30  , mFamilyIsSet( false )
31  , mBoldIsSet( false )
32  , mItalicIsSet( false )
33  , mUnderlineIsSet( false )
34  , mStrikeOutIsSet( false )
35  , mSizeType( 0 )
36  , mSize( 0.0 )
37  , mSizeIsSet( false )
38  , mColorIsSet( false )
39  , mOffsetType( 0 )
40  , mXOffset( 0 )
41  , mYOffset( 0 )
42  , mOffsetIsSet( false )
43  , mAngle( 0.0 )
44  , mAngleIsSet( false )
45  , mAngleIsAuto( false )
46  , mAlignment( 0 )
47  , mAlignmentIsSet( false )
48  , mBufferEnabledFlag( false )
49  , mBufferSizeType( 0 )
50  , mBufferSize( 0.0 )
51  , mBufferSizeIsSet( false )
52  , mBufferColorIsSet( false )
53  , mBufferStyleIsSet( false )
54  , mBorderColorIsSet( false )
55  , mBorderWidthIsSet( false )
56  , mBorderStyleIsSet( false )
57  , mMultilineEnabledFlag( false )
58  , mSelectedOnly( false )
59 {
60 
61  if ( def ) // set defaults
62  {
63  setText( QObject::tr( "Label" ) );
64 
65  mFont = QApplication::font();
66  mFamilyIsSet = true;
67  mBoldIsSet = true;
68  mItalicIsSet = true;
69  mUnderlineIsSet = true;
70 
71  setSize( 12.0, PointUnits );
72 
73  setOffset( 0, 0, PointUnits );
74  setAngle( 0 );
75  setAutoAngle( false );
76 
77  setAlignment( Qt::AlignCenter );
78  setColor( QColor( 0, 0, 0 ) );
79 
81  setBufferColor( QColor( 255, 255, 255 ) );
82  setBufferStyle( Qt::NoBrush );
83 
84  setBorderWidth( 0 );
85  setBorderColor( QColor( 0, 0, 0 ) );
86  setBorderStyle( Qt::NoPen );
87  }
88 }
89 
91 {
92 }
93 /* Text */
94 void QgsLabelAttributes::setText( const QString & text )
95 {
96  mText = text;
97  mTextIsSet = true;
98 }
99 
101 {
102  return mTextIsSet;
103 }
104 
105 const QString QgsLabelAttributes::text( void ) const
106 {
107  return mText;
108 }
109 
110 
111 /* Offset */
112 void QgsLabelAttributes::setOffset( double x, double y, int type )
113 {
114  mOffsetType = type;
115  mXOffset = x;
116  mYOffset = y;
117  mOffsetIsSet = true;
118 }
119 
121 {
122  return mOffsetIsSet;
123 }
124 
126 {
127  return mOffsetType;
128 }
129 
130 double QgsLabelAttributes::xOffset( void ) const
131 {
132  return mXOffset;
133 }
134 
135 double QgsLabelAttributes::yOffset( void ) const
136 {
137  return mYOffset;
138 }
139 
140 /* Angle */
142 {
143  mAngle = angle;
144  mAngleIsSet = true;
145 }
146 
148 {
149  return mAngleIsSet;
150 }
151 
152 double QgsLabelAttributes::angle( void ) const
153 {
154  return mAngle;
155 }
156 
158 {
159  return mAngleIsAuto;
160 }
161 
163 {
164  mAngleIsAuto = state;
165 }
166 
167 /* Alignment */
168 void QgsLabelAttributes::setAlignment( int alignment )
169 {
171  mAlignmentIsSet = true;
172 }
173 
175 {
176  return mAlignmentIsSet;
177 }
178 
180 {
181  return mAlignment;
182 }
183 
184 /* Font */
185 void QgsLabelAttributes::setFamily( const QString & family )
186 {
187  mFont.setFamily( family );
188  mFamilyIsSet = true;
189 }
190 
192 {
193  return mFamilyIsSet;
194 }
195 
196 const QString QgsLabelAttributes::family( void ) const
197 {
198  return mFont.family();
199 }
200 
201 
202 void QgsLabelAttributes::setBold( bool enable )
203 {
204  mFont.setBold( enable );
205  mBoldIsSet = true;
206 }
207 
209 {
210  return mBoldIsSet;
211 }
212 
213 bool QgsLabelAttributes::bold( void ) const
214 {
215  return mFont.bold();
216 }
217 
218 
219 void QgsLabelAttributes::setItalic( bool enable )
220 {
221  mFont.setItalic( enable );
222  mItalicIsSet = true;
223 }
224 
226 {
227  return mItalicIsSet;
228 }
229 
230 bool QgsLabelAttributes::italic( void ) const
231 {
232  return mFont.italic();
233 }
234 
235 
237 {
238  mFont.setUnderline( enable );
239  mUnderlineIsSet = true;
240 }
241 
243 {
244  return mUnderlineIsSet;
245 }
246 
248 {
249  return mFont.underline();
250 }
251 
253 {
254  mFont.setStrikeOut( enable );
255  mStrikeOutIsSet = true;
256 }
257 
259 {
260  return mStrikeOutIsSet;
261 }
262 
264 {
265  return mFont.strikeOut();
266 }
267 
268 
269 void QgsLabelAttributes::setSize( double size, int type )
270 {
271  mSizeType = type;
272  mSize = size;
273  mSizeIsSet = true;
274 }
275 
277 {
278  return mSizeIsSet;
279 }
280 
282 {
283  return mSizeType;
284 }
285 
286 double QgsLabelAttributes::size( void ) const
287 {
288  return mSize;
289 }
290 
291 
292 void QgsLabelAttributes::setColor( const QColor &color )
293 {
294  mColor = color;
295  mColorIsSet = true;
296 }
297 
299 {
300  return mColorIsSet;
301 }
302 
303 const QColor & QgsLabelAttributes::color( void ) const
304 {
305  return mColor;
306 }
307 
308 /* Buffer */
310 {
311  return mBufferEnabledFlag;
312 }
313 void QgsLabelAttributes::setBufferEnabled( bool useBufferFlag )
314 {
315  mBufferEnabledFlag = useBufferFlag;
316 }
317 void QgsLabelAttributes::setBufferSize( double size, int type )
318 {
319  mBufferSizeType = type;
320  mBufferSize = size;
321  mBufferSizeIsSet = true;
322 }
323 
325 {
326  return mBufferSizeIsSet;
327 }
328 
330 {
331  return mBufferSizeType;
332 }
333 
334 double QgsLabelAttributes::bufferSize( void ) const
335 {
336  return mBufferSize;
337 }
338 
339 
340 void QgsLabelAttributes::setBufferColor( const QColor &color )
341 {
342  mBufferBrush.setColor( color );
343  mBufferColorIsSet = true;
344 }
345 
347 {
348  return mColorIsSet;
349 }
350 
352 {
353  return mBufferBrush.color();
354 }
355 
356 
357 void QgsLabelAttributes::setBufferStyle( Qt::BrushStyle style )
358 {
359  mBufferBrush.setStyle( style );
360  mBufferStyleIsSet = true;
361 }
362 
364 {
365  return mBufferStyleIsSet;
366 }
367 
368 Qt::BrushStyle QgsLabelAttributes::bufferStyle( void ) const
369 {
370  return mBufferBrush.style();
371 }
372 
373 /* Border */
374 void QgsLabelAttributes::setBorderColor( const QColor &color )
375 {
376  mBorderPen.setColor( color );
377  mBorderColorIsSet = true;
378 }
379 
381 {
382  return mBorderColorIsSet;
383 }
384 
386 {
387  return mBorderPen.color();
388 }
389 
391 {
392  mBorderPen.setWidth( width );
393  mBorderWidthIsSet = true;
394 }
395 
397 {
398  return mBorderWidthIsSet;
399 }
400 
402 {
403  return mBorderPen.width();
404 }
405 
406 
407 void QgsLabelAttributes::setBorderStyle( Qt::PenStyle style )
408 {
409  mBorderPen.setStyle( style );
410  mBorderStyleIsSet = true;
411 }
412 
414 {
415  return mBorderStyleIsSet;
416 }
417 
418 Qt::PenStyle QgsLabelAttributes::borderStyle( void ) const
419 {
420  return mBorderPen.style();
421 }
422 
423 /* Multiline */
425 {
426  return mMultilineEnabledFlag;
427 }
428 void QgsLabelAttributes::setMultilineEnabled( bool useMultilineFlag )
429 {
430  mMultilineEnabledFlag = useMultilineFlag;
431 }
432 
433 /* selected only */
435 {
436  return mSelectedOnly;
437 }
438 void QgsLabelAttributes::setSelectedOnly( bool selectedOnly )
439 {
441 }
442 
443 /* units */
444 QString QgsLabelAttributes::unitsName( int units )
445 {
446  if ( units == MapUnits )
447  {
448  return QString( "mu" );
449  }
450 
451  return QString( "pt" );
452 }
453 
454 int QgsLabelAttributes::unitsCode( const QString &name )
455 {
456  if ( name.compare( "mu" ) == 0 )
457  {
458  return MapUnits;
459  }
460 
461  return PointUnits;
462 }
463 
464 /* alignment */
465 QString QgsLabelAttributes::alignmentName( int alignment )
466 {
467  QgsDebugMsg( QString( "alignment=%1" ).arg( alignment ) );
468  if ( !alignment ) return QString( "center" );
469  if ( alignment == ( Qt::AlignRight | Qt::AlignBottom ) ) return QString( "aboveleft" );
470  if ( alignment == ( Qt::AlignRight | Qt::AlignTop ) ) return QString( "belowleft" );
471  if ( alignment == ( Qt::AlignLeft | Qt::AlignBottom ) ) return QString( "aboveright" );
472  if ( alignment == ( Qt::AlignLeft | Qt::AlignTop ) ) return QString( "belowright" );
473  if ( alignment == ( Qt::AlignRight | Qt::AlignVCenter ) ) return QString( "left" );
474  if ( alignment == ( Qt::AlignLeft | Qt::AlignVCenter ) ) return QString( "right" );
475  if ( alignment == ( Qt::AlignBottom | Qt::AlignHCenter ) ) return QString( "above" );
476  if ( alignment == ( Qt::AlignTop | Qt::AlignHCenter ) ) return QString( "below" );
477  if ( alignment == ( Qt::AlignCenter ) ) return QString( "center" );
478  return QString( "center" );
479 }
480 
481 int QgsLabelAttributes::alignmentCode( const QString &name )
482 {
483  QString lname = name.toLower();
484  if ( lname.compare( "aboveleft" ) == 0 ) return Qt::AlignRight | Qt::AlignBottom ;
485  if ( lname.compare( "belowleft" ) == 0 ) return Qt::AlignRight | Qt::AlignTop ;
486  if ( lname.compare( "aboveright" ) == 0 ) return Qt::AlignLeft | Qt::AlignBottom ;
487  if ( lname.compare( "belowright" ) == 0 ) return Qt::AlignLeft | Qt::AlignTop ;
488  if ( lname.compare( "left" ) == 0 ) return Qt::AlignRight | Qt::AlignVCenter ;
489  if ( lname.compare( "right" ) == 0 ) return Qt::AlignLeft | Qt::AlignVCenter ;
490  if ( lname.compare( "above" ) == 0 ) return Qt::AlignBottom | Qt::AlignHCenter ;
491  if ( lname.compare( "below" ) == 0 ) return Qt::AlignTop | Qt::AlignHCenter ;
492  if ( lname.compare( "center" ) == 0 ) return Qt::AlignCenter ;
493 
494 
495  return Qt::AlignCenter;
496 }