QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssymbolv2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbolv2.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgssymbolv2.h"
17 #include "qgssymbollayerv2.h"
18 
19 #include "qgslinesymbollayerv2.h"
20 #include "qgsmarkersymbollayerv2.h"
21 #include "qgsfillsymbollayerv2.h"
22 
23 #include "qgslogger.h"
24 #include "qgsrendercontext.h" // for bigSymbolPreview
25 
26 #include "qgsproject.h"
27 #include "qgsstylev2.h"
28 
29 #include <QColor>
30 #include <QImage>
31 #include <QPainter>
32 #include <QSize>
33 
34 #include <cmath>
35 
37  : mType( type ), mLayers( layers ), mAlpha( 1.0 ), mRenderHints( 0 ), mLayer( NULL )
38 {
39 
40  // check they're all correct symbol layers
41  for ( int i = 0; i < mLayers.count(); i++ )
42  {
43  if ( mLayers[i] == NULL )
44  {
45  mLayers.removeAt( i-- );
46  }
47  else if ( !isSymbolLayerCompatible( mLayers[i]->type() ) )
48  {
49  delete mLayers[i];
50  mLayers.removeAt( i-- );
51  }
52  }
53 
54 }
55 
57 {
58  // delete all symbol layers (we own them, so it's okay)
59  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
60  delete *it;
61 }
62 
64 {
65  if ( mLayers.empty() )
66  {
67  return QgsSymbolV2::Mixed;
68  }
69 
70  QgsSymbolLayerV2List::const_iterator it = mLayers.constBegin();
71 
72  QgsSymbolV2::OutputUnit unit = ( *it )->outputUnit();
73 
74  for ( ; it != mLayers.constEnd(); ++it )
75  {
76  if (( *it )->outputUnit() != unit )
77  {
78  return QgsSymbolV2::Mixed;
79  }
80  }
81  return unit;
82 }
83 
85 {
86  if ( mLayers.empty() )
87  {
88  return QgsMapUnitScale();
89  }
90 
91  QgsSymbolLayerV2List::const_iterator it = mLayers.constBegin();
92  if ( it == mLayers.constEnd() )
93  return QgsMapUnitScale();
94 
95  QgsMapUnitScale scale = ( *it )->mapUnitScale();
96  ++it;
97 
98  for ( ; it != mLayers.constEnd(); ++it )
99  {
100  if (( *it )->mapUnitScale() != scale )
101  {
102  return QgsMapUnitScale();
103  }
104  }
105  return scale;
106 }
107 
109 {
110  QgsSymbolLayerV2List::iterator it = mLayers.begin();
111  for ( ; it != mLayers.end(); ++it )
112  {
113  ( *it )->setOutputUnit( u );
114  }
115 }
116 
118 {
119  QgsSymbolLayerV2List::iterator it = mLayers.begin();
120  for ( ; it != mLayers.end(); ++it )
121  {
122  ( *it )->setMapUnitScale( scale );
123  }
124 }
125 
127 {
128  QgsSymbolV2* s = 0;
129 
130  // override global default if project has a default for this type
131  QString defaultSymbol;
132  switch ( geomType )
133  {
134  case QGis::Point :
135  defaultSymbol = QgsProject::instance()->readEntry( "DefaultStyles", "/Marker", "" );
136  break;
137  case QGis::Line :
138  defaultSymbol = QgsProject::instance()->readEntry( "DefaultStyles", "/Line", "" );
139  break;
140  case QGis::Polygon :
141  defaultSymbol = QgsProject::instance()->readEntry( "DefaultStyles", "/Fill", "" );
142  break;
143  default: defaultSymbol = ""; break;
144  }
145  if ( defaultSymbol != "" )
146  s = QgsStyleV2::defaultStyle()->symbol( defaultSymbol );
147 
148  // if no default found for this type, get global default (as previously)
149  if ( ! s )
150  {
151  switch ( geomType )
152  {
153  case QGis::Point: s = new QgsMarkerSymbolV2(); break;
154  case QGis::Line: s = new QgsLineSymbolV2(); break;
155  case QGis::Polygon: s = new QgsFillSymbolV2(); break;
156  default: QgsDebugMsg( "unknown layer's geometry type" ); return NULL;
157  }
158  }
159 
160  // set alpha transparency
161  s->setAlpha( QgsProject::instance()->readDoubleEntry( "DefaultStyles", "/AlphaInt", 255 ) / 255.0 );
162 
163  // set random color, it project prefs allow
164  if ( defaultSymbol == "" ||
165  QgsProject::instance()->readBoolEntry( "DefaultStyles", "/RandomColors", true ) )
166  {
167  s->setColor( QColor::fromHsv( rand() % 360, 64 + rand() % 192, 128 + rand() % 128 ) );
168  }
169 
170  return s;
171 }
172 
174 {
175  if ( layer < 0 || layer >= mLayers.count() )
176  return NULL;
177 
178  return mLayers[layer];
179 }
180 
181 
183 {
184  // fill symbol can contain also line symbol layers for drawing of outlines
185  if ( mType == Fill && t == Line )
186  return true;
187 
188  return mType == t;
189 }
190 
191 
193 {
194  if ( index < 0 || index > mLayers.count() ) // can be added also after the last index
195  return false;
196  if ( layer == NULL || !isSymbolLayerCompatible( layer->type() ) )
197  return false;
198 
199  mLayers.insert( index, layer );
200  return true;
201 }
202 
203 
205 {
206  if ( layer == NULL || !isSymbolLayerCompatible( layer->type() ) )
207  return false;
208 
209  mLayers.append( layer );
210  return true;
211 }
212 
213 
215 {
216  if ( index < 0 || index >= mLayers.count() )
217  return false;
218 
219  delete mLayers[index];
220  mLayers.removeAt( index );
221  return true;
222 }
223 
224 
226 {
227  if ( index < 0 || index >= mLayers.count() )
228  return NULL;
229 
230  return mLayers.takeAt( index );
231 }
232 
233 
235 {
236  if ( index < 0 || index >= mLayers.count() )
237  return false;
238  if ( layer == NULL || !isSymbolLayerCompatible( layer->type() ) )
239  return false;
240 
241  delete mLayers[index]; // first delete the original layer
242  mLayers[index] = layer; // set new layer
243  return true;
244 }
245 
246 
247 void QgsSymbolV2::startRender( QgsRenderContext& context, const QgsFields* fields )
248 {
249  QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, 0, fields, mapUnitScale() );
250 
251 
252  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
253  ( *it )->startRender( symbolContext );
254 }
255 
257 {
258  QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, 0, 0, mapUnitScale() );
259 
260  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
261  ( *it )->stopRender( symbolContext );
262 
263  mLayer = NULL;
264 }
265 
266 void QgsSymbolV2::setColor( const QColor& color )
267 {
268  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
269  {
270  if ( !( *it )->isLocked() )
271  ( *it )->setColor( color );
272  }
273 }
274 
275 QColor QgsSymbolV2::color() const
276 {
277  for ( QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it )
278  {
279  // return color of the first unlocked layer
280  if ( !( *it )->isLocked() )
281  return ( *it )->color();
282  }
283  return QColor( 0, 0, 0 );
284 }
285 
286 void QgsSymbolV2::drawPreviewIcon( QPainter* painter, QSize size )
287 {
289  QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, false, mRenderHints, 0, 0, mapUnitScale() );
290 
291  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
292  {
293  if ( mType == Fill && ( *it )->type() == Line )
294  {
295  // line symbol layer would normally draw just a line
296  // so we override this case to force it to draw a polygon outline
298 
299  // from QgsFillSymbolLayerV2::drawPreviewIcon()
300  QPolygonF poly = QRectF( QPointF( 0, 0 ), QPointF( size.width() - 1, size.height() - 1 ) );
301  lsl->startRender( symbolContext );
302  lsl->renderPolygonOutline( poly, NULL, symbolContext );
303  lsl->stopRender( symbolContext );
304  }
305  else
306  ( *it )->drawPreviewIcon( symbolContext, size );
307  }
308 }
309 
310 
312 {
313  QImage preview( QSize( 100, 100 ), QImage::Format_ARGB32_Premultiplied );
314  preview.fill( 0 );
315 
316  QPainter p( &preview );
317  p.setRenderHint( QPainter::Antialiasing );
318  p.translate( 0.5, 0.5 ); // shift by half a pixel to avoid blurring due antialising
319 
320  if ( mType == QgsSymbolV2::Marker )
321  {
322  p.setPen( QPen( Qt::gray ) );
323  p.drawLine( 0, 50, 100, 50 );
324  p.drawLine( 50, 0, 50, 100 );
325  }
326 
328  startRender( context );
329 
330  if ( mType == QgsSymbolV2::Line )
331  {
332  QPolygonF poly;
333  poly << QPointF( 0, 50 ) << QPointF( 99, 50 );
334  static_cast<QgsLineSymbolV2*>( this )->renderPolyline( poly, 0, context );
335  }
336  else if ( mType == QgsSymbolV2::Fill )
337  {
338  QPolygonF polygon;
339  polygon << QPointF( 20, 20 ) << QPointF( 80, 20 ) << QPointF( 80, 80 ) << QPointF( 20, 80 ) << QPointF( 20, 20 );
340  static_cast<QgsFillSymbolV2*>( this )->renderPolygon( polygon, NULL, 0, context );
341  }
342  else // marker
343  {
344  static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( QPointF( 50, 50 ), 0, context );
345  }
346 
347  stopRender( context );
348  return preview;
349 }
350 
351 
352 QString QgsSymbolV2::dump() const
353 {
354  QString t;
355  switch ( type() )
356  {
357  case QgsSymbolV2::Marker: t = "MARKER"; break;
358  case QgsSymbolV2::Line: t = "LINE"; break;
359  case QgsSymbolV2::Fill: t = "FILL"; break;
360  default: Q_ASSERT( 0 && "unknown symbol type" );
361  }
362  QString s = QString( "%1 SYMBOL (%2 layers) color %3" ).arg( t ).arg( mLayers.count() ).arg( QgsSymbolLayerV2Utils::encodeColor( color() ) );
363 
364  for ( QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it )
365  {
366  // TODO:
367  }
368  return s;
369 }
370 
371 void QgsSymbolV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
372 {
373  props[ "alpha" ] = QString::number( alpha() );
374  double scaleFactor = 1.0;
375  props[ "uom" ] = QgsSymbolLayerV2Utils::encodeSldUom( outputUnit(), &scaleFactor );
376  props[ "uomScale" ] = scaleFactor != 1 ? QString::number( scaleFactor ) : "";
377 
378  for ( QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it )
379  {
380  ( *it )->toSld( doc, element, props );
381  }
382 }
383 
385 {
387  for ( QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it )
388  {
389  QgsSymbolLayerV2* layer = ( *it )->clone();
390  layer->setLocked(( *it )->isLocked() );
391  layer->setRenderingPass(( *it )->renderingPass() );
392  lst.append( layer );
393  }
394  return lst;
395 }
396 
397 QSet<QString> QgsSymbolV2::usedAttributes() const
398 {
399  QSet<QString> attributes;
400  QgsSymbolLayerV2List::const_iterator sIt = mLayers.constBegin();
401  for ( ; sIt != mLayers.constEnd(); ++sIt )
402  {
403  if ( *sIt )
404  {
405  attributes.unite(( *sIt )->usedAttributes() );
406  }
407  }
408  return attributes;
409 }
410 
412 
413 
414 QgsSymbolV2RenderContext::QgsSymbolV2RenderContext( QgsRenderContext& c, QgsSymbolV2::OutputUnit u, qreal alpha, bool selected, int renderHints, const QgsFeature* f, const QgsFields* fields, const QgsMapUnitScale& mapUnitScale )
415  : mRenderContext( c ), mOutputUnit( u ), mMapUnitScale( mapUnitScale ), mAlpha( alpha ), mSelected( selected ), mRenderHints( renderHints ), mFeature( f ), mFields( fields )
416 {
417 
418 }
419 
421 {
422 
423 }
424 
425 
426 double QgsSymbolV2RenderContext::outputLineWidth( double width ) const
427 {
429 }
430 
432 {
434 }
435 
437 {
438  // This is just a dummy implementation of assignment.
439  // sip 4.7 generates a piece of code that needs this function to exist.
440  // It's not generated automatically by the compiler because of
441  // mRenderContext member which is a reference (and thus can't be changed).
442  Q_ASSERT( false );
443  return *this;
444 }
445 
447 
449 {
451  if ( sl == NULL )
452  return NULL;
453 
454  QgsSymbolLayerV2List layers;
455  layers.append( sl );
456  return new QgsMarkerSymbolV2( layers );
457 }
458 
460 {
462  if ( sl == NULL )
463  return NULL;
464 
465  QgsSymbolLayerV2List layers;
466  layers.append( sl );
467  return new QgsLineSymbolV2( layers );
468 }
469 
471 {
473  if ( sl == NULL )
474  return NULL;
475 
476  QgsSymbolLayerV2List layers;
477  layers.append( sl );
478  return new QgsFillSymbolV2( layers );
479 }
480 
482 
483 
485  : QgsSymbolV2( Marker, layers )
486 {
487  if ( mLayers.count() == 0 )
488  mLayers.append( new QgsSimpleMarkerSymbolLayerV2() );
489 }
490 
491 void QgsMarkerSymbolV2::setAngle( double ang )
492 {
493  double origAngle = angle();
494  double angleDiff = ang - origAngle;
495  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
496  {
498  layer->setAngle( layer->angle() + angleDiff );
499  }
500 }
501 
503 {
504  QgsSymbolLayerV2List::const_iterator it = mLayers.begin();
505 
506  if ( it == mLayers.end() )
507  return 0;
508 
509  // return angle of the first symbol layer
510  const QgsMarkerSymbolLayerV2* layer = static_cast<const QgsMarkerSymbolLayerV2 *>( *it );
511  return layer->angle();
512 }
513 
515 {
516  double origSize = size();
517 
518  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
519  {
520  QgsMarkerSymbolLayerV2* layer = static_cast<QgsMarkerSymbolLayerV2*>( *it );
521  if ( layer->size() == origSize )
522  layer->setSize( s );
523  else
524  {
525  // proportionally scale size
526  if ( origSize != 0 )
527  layer->setSize( layer->size() * s / origSize );
528  }
529  }
530 }
531 
533 {
534  // return size of the largest symbol
535  double maxSize = 0;
536  for ( QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it )
537  {
538  const QgsMarkerSymbolLayerV2* layer = static_cast<const QgsMarkerSymbolLayerV2 *>( *it );
539  double lsize = layer->size();
540  if ( lsize > maxSize )
541  maxSize = lsize;
542  }
543  return maxSize;
544 }
545 
546 
548 {
549  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
550  {
551  QgsMarkerSymbolLayerV2* layer = static_cast<QgsMarkerSymbolLayerV2*>( *it );
552  layer->setScaleMethod( scaleMethod );
553  }
554 }
555 
557 {
558  QgsSymbolLayerV2List::const_iterator it = mLayers.begin();
559 
560  if ( it == mLayers.end() )
561  return DEFAULT_SCALE_METHOD;
562 
563  // return scale method of the first symbol layer
564  const QgsMarkerSymbolLayerV2* layer = static_cast<const QgsMarkerSymbolLayerV2 *>( *it );
565  return layer->scaleMethod();
566 }
567 
568 void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
569 {
570  QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, 0, mapUnitScale() );
571 
572  if ( layer != -1 )
573  {
574  if ( layer >= 0 && layer < mLayers.count() )
575  (( QgsMarkerSymbolLayerV2* ) mLayers[layer] )->renderPoint( point, symbolContext );
576  return;
577  }
578 
579  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
580  {
582  layer->renderPoint( point, symbolContext );
583  }
584 }
585 
587 {
588  QgsSymbolV2* cloneSymbol = new QgsMarkerSymbolV2( cloneLayers() );
589  cloneSymbol->setAlpha( mAlpha );
590  return cloneSymbol;
591 }
592 
593 
595 // LINE
596 
598  : QgsSymbolV2( Line, layers )
599 {
600  if ( mLayers.count() == 0 )
601  mLayers.append( new QgsSimpleLineSymbolLayerV2() );
602 }
603 
605 {
606  double origWidth = width();
607 
608  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
609  {
611  if ( layer->width() == origWidth )
612  {
613  layer->setWidth( w );
614  }
615  else
616  {
617  // proportionally scale the width
618  if ( origWidth != 0 )
619  layer->setWidth( layer->width() * w / origWidth );
620  }
621  }
622 }
623 
625 {
626  double maxWidth = 0;
627  for ( QgsSymbolLayerV2List::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it )
628  {
629  const QgsLineSymbolLayerV2* layer = ( const QgsLineSymbolLayerV2* ) * it;
630  double width = layer->width();
631  if ( width > maxWidth )
632  maxWidth = width;
633  }
634  return maxWidth;
635 }
636 
637 void QgsLineSymbolV2::renderPolyline( const QPolygonF& points, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
638 {
639  QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, 0, mapUnitScale() );
640 
641  if ( layer != -1 )
642  {
643  if ( layer >= 0 && layer < mLayers.count() )
644  (( QgsLineSymbolLayerV2* ) mLayers[layer] )->renderPolyline( points, symbolContext );
645  return;
646  }
647 
648  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
649  {
650  QgsLineSymbolLayerV2* layer = ( QgsLineSymbolLayerV2* ) * it;
651  layer->renderPolyline( points, symbolContext );
652  }
653 }
654 
655 
657 {
658  QgsSymbolV2* cloneSymbol = new QgsLineSymbolV2( cloneLayers() );
659  cloneSymbol->setAlpha( mAlpha );
660  return cloneSymbol;
661 }
662 
664 // FILL
665 
667  : QgsSymbolV2( Fill, layers )
668 {
669  if ( mLayers.count() == 0 )
670  mLayers.append( new QgsSimpleFillSymbolLayerV2() );
671 }
672 
673 void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, const QgsFeature* f, QgsRenderContext& context, int layer, bool selected )
674 {
675  QgsSymbolV2RenderContext symbolContext( context, outputUnit(), mAlpha, selected, mRenderHints, f, 0, mapUnitScale() );
676 
677  if ( layer != -1 )
678  {
679  if ( layer >= 0 && layer < mLayers.count() )
680  {
681  QgsSymbolV2::SymbolType layertype = mLayers.at( layer )->type();
682  if ( layertype == QgsSymbolV2::Fill )
683  (( QgsFillSymbolLayerV2* ) mLayers[layer] )->renderPolygon( points, rings, symbolContext );
684  else if ( layertype == QgsSymbolV2::Line )
685  (( QgsLineSymbolLayerV2* ) mLayers[layer] )->renderPolygonOutline( points, rings, symbolContext );
686  }
687  return;
688  }
689 
690  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
691  {
692  QgsSymbolV2::SymbolType layertype = ( *it )->type();
693  if ( layertype == QgsSymbolV2::Fill )
694  {
695  QgsFillSymbolLayerV2* layer = ( QgsFillSymbolLayerV2* ) * it;
696  layer->renderPolygon( points, rings, symbolContext );
697  }
698  else if ( layertype == QgsSymbolV2::Line )
699  {
700  QgsLineSymbolLayerV2* layer = ( QgsLineSymbolLayerV2* ) * it;
701  layer->renderPolygonOutline( points, rings, symbolContext );
702  }
703  }
704 }
705 
706 
708 {
709  QgsSymbolV2* cloneSymbol = new QgsFillSymbolV2( cloneLayers() );
710  cloneSymbol->setAlpha( mAlpha );
711  return cloneSymbol;
712 }
713 
715 {
716  for ( QgsSymbolLayerV2List::iterator it = mLayers.begin(); it != mLayers.end(); ++it )
717  {
719  layer->setAngle( angle );
720  }
721 }
722 
723 
void setLocked(bool locked)
bool deleteSymbolLayer(int index)
delete symbol layer at specified index
static unsigned index
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
static QgsMarkerSymbolV2 * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
QgsSymbolV2(SymbolType type, QgsSymbolLayerV2List layers)
Definition: qgssymbolv2.cpp:36
GeometryType
Definition: qgis.h:155
virtual double width() const
const QgsVectorLayer * mLayer
Definition: qgssymbolv2.h:157
SymbolType type() const
Definition: qgssymbolv2.h:79
QSet< QString > usedAttributes() const
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
void drawPreviewIcon(QPainter *painter, QSize size)
static QString encodeSldUom(QgsSymbolV2::OutputUnit unit, double *scaleFactor)
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
QgsFillSymbolV2(QgsSymbolLayerV2List layers=QgsSymbolLayerV2List())
static QgsFillSymbolV2 * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
QgsMapUnitScale mMapUnitScale
Definition: qgssymbolv2.h:210
bool changeSymbolLayer(int index, QgsSymbolLayerV2 *layer)
delete layer at specified index and set a new one
ScaleMethod scaleMethod()
QgsMapUnitScale mapUnitScale() const
Definition: qgssymbolv2.cpp:84
Container of fields for a vector layer.
Definition: qgsfield.h:163
virtual void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)=0
QgsSymbolV2 * symbol(QString name)
return a NEW copy of symbol
Definition: qgsstylev2.cpp:166
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
SymbolType mType
Definition: qgssymbolv2.h:149
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
static double pixelSizeScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns scale factor painter units -> pixel dimensions.
void setWidth(double width)
void setMapUnitScale(const QgsMapUnitScale &scale)
void setAngle(double angle)
const QgsVectorLayer * layer() const
Definition: qgssymbolv2.h:137
virtual void startRender(QgsSymbolV2RenderContext &context)=0
static QString encodeColor(QColor color)
void setColor(const QColor &color)
static QgsRenderContext createRenderContext(QPainter *p)
Creates a render context for a pixel based device.
QgsSymbolLayerV2List mLayers
Definition: qgssymbolv2.h:150
QgsSymbolLayerV2List cloneLayers() const
bool appendSymbolLayer(QgsSymbolLayerV2 *layer)
append symbol layer at the end of the list
virtual void renderPoint(const QPointF &point, QgsSymbolV2RenderContext &context)=0
QgsLineSymbolV2(QgsSymbolLayerV2List layers=QgsSymbolLayerV2List())
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:125
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
void toSld(QDomDocument &doc, QDomElement &element, QgsStringMap props) const
void setRenderingPass(int renderingPass)
#define DEFAULT_SCALE_METHOD
virtual void setWidth(double width)
static QgsStyleV2 * defaultStyle()
return default application-wide style
Definition: qgsstylev2.cpp:51
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void setAngle(double angle)
void setAngle(double angle)
void setSize(double size)
qreal mAlpha
Symbol opacity (in the range 0 - 1)
Definition: qgssymbolv2.h:153
QgsSymbolV2RenderContext & operator=(const QgsSymbolV2RenderContext &)
virtual void renderPolygonOutline(const QPolygonF &points, QList< QPolygonF > *rings, QgsSymbolV2RenderContext &context)
void renderPoint(const QPointF &point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
QgsSymbolV2::ScaleMethod scaleMethod() const
QgsSymbolV2::SymbolType type() const
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
virtual ~QgsSymbolV2()
Definition: qgssymbolv2.cpp:56
virtual void renderPolyline(const QPolygonF &points, QgsSymbolV2RenderContext &context)=0
virtual QgsSymbolV2 * clone() const
bool isSymbolLayerCompatible(SymbolType t)
check whether a symbol layer type can be used within the symbol (marker-marker, line-line, fill-fill/line)
QgsMarkerSymbolV2(QgsSymbolLayerV2List layers=QgsSymbolLayerV2List())
Contains information about the context of a rendering operation.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
void stopRender(QgsRenderContext &context)
bool insertSymbolLayer(int index, QgsSymbolLayerV2 *layer)
insert symbol layer to specified index
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns the line width scale factor depending on the unit and the paint device.
static QgsSymbolV2 * defaultSymbol(QGis::GeometryType geomType)
return new default symbol for specified geometry type
virtual QgsSymbolV2 * clone() const
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
Definition: qgssymbolv2.h:39
QgsSymbolV2RenderContext(QgsRenderContext &c, QgsSymbolV2::OutputUnit u, qreal alpha=1.0, bool selected=false, int renderHints=0, const QgsFeature *f=0, const QgsFields *=0, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
QgsRenderContext & mRenderContext
Definition: qgssymbolv2.h:208
QgsSymbolV2::OutputUnit outputUnit() const
Definition: qgssymbolv2.cpp:63
virtual QgsSymbolV2 * clone() const
QgsSymbolLayerV2 * takeSymbolLayer(int index)
remove symbol layer from the list and return pointer to it
double outputPixelSize(double size) const
double outputLineWidth(double width) const
QgsSymbolLayerV2 * symbolLayer(int layer)
QString dump() const
void setSize(double size)
void setAngle(double angle)
double size
Definition: qgssvgcache.cpp:77
virtual void stopRender(QgsSymbolV2RenderContext &context)=0
QgsSymbolV2::OutputUnit mOutputUnit
Definition: qgssymbolv2.h:209
void setOutputUnit(QgsSymbolV2::OutputUnit u)
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
Definition: qgssymbolv2.h:127
QImage bigSymbolPreviewImage()
void setScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
QColor color() const
int mRenderHints
Definition: qgssymbolv2.h:155