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

« back to all changes in this revision

Viewing changes to src/core/symbology-ng/qgsfillsymbollayerv2.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:
 
1
 
 
2
#include "qgsfillsymbollayerv2.h"
 
3
#include "qgssymbollayerv2utils.h"
 
4
 
 
5
#include "qgsrendercontext.h"
 
6
 
 
7
#include <QPainter>
 
8
 
 
9
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth )
 
10
    : mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
 
11
{
 
12
  mColor = color;
 
13
}
 
14
 
 
15
 
 
16
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props )
 
17
{
 
18
  QColor color = DEFAULT_SIMPLEFILL_COLOR;
 
19
  Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE;
 
20
  QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR;
 
21
  Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE;
 
22
  double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH;
 
23
 
 
24
  if ( props.contains( "color" ) )
 
25
    color = QgsSymbolLayerV2Utils::decodeColor( props["color"] );
 
26
  if ( props.contains( "style" ) )
 
27
    style = QgsSymbolLayerV2Utils::decodeBrushStyle( props["style"] );
 
28
  if ( props.contains( "color_border" ) )
 
29
    borderColor = QgsSymbolLayerV2Utils::decodeColor( props["color_border"] );
 
30
  if ( props.contains( "style_border" ) )
 
31
    borderStyle = QgsSymbolLayerV2Utils::decodePenStyle( props["style_border"] );
 
32
  if ( props.contains( "width_border" ) )
 
33
    borderWidth = props["width_border"].toDouble();
 
34
 
 
35
  return new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth );
 
36
}
 
37
 
 
38
 
 
39
QString QgsSimpleFillSymbolLayerV2::layerType() const
 
40
{
 
41
  return "SimpleFill";
 
42
}
 
43
 
 
44
void QgsSimpleFillSymbolLayerV2::startRender( QgsRenderContext& context )
 
45
{
 
46
  mBrush = QBrush( mColor, mBrushStyle );
 
47
  mPen = QPen( mBorderColor );
 
48
  mPen.setStyle( mBorderStyle );
 
49
  mPen.setWidthF( mBorderWidth );
 
50
}
 
51
 
 
52
void QgsSimpleFillSymbolLayerV2::stopRender( QgsRenderContext& context )
 
53
{
 
54
}
 
55
 
 
56
void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context )
 
57
{
 
58
  QPainter* p = context.painter();
 
59
  p->setBrush( mBrush );
 
60
  p->setPen( mPen );
 
61
 
 
62
  if ( rings == NULL )
 
63
  {
 
64
    // simple polygon without holes
 
65
    p->drawPolygon( points );
 
66
  }
 
67
  else
 
68
  {
 
69
    // polygon with holes must be drawn using painter path
 
70
    QPainterPath path;
 
71
    path.addPolygon( points );
 
72
    QList<QPolygonF>::iterator it;
 
73
    for ( it = rings->begin(); it != rings->end(); ++it )
 
74
      path.addPolygon( *it );
 
75
 
 
76
    p->drawPath( path );
 
77
  }
 
78
}
 
79
 
 
80
QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
 
81
{
 
82
  QgsStringMap map;
 
83
  map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
 
84
  map["style"] = QgsSymbolLayerV2Utils::encodeBrushStyle( mBrushStyle );
 
85
  map["color_border"] = QgsSymbolLayerV2Utils::encodeColor( mBorderColor );
 
86
  map["style_border"] = QgsSymbolLayerV2Utils::encodePenStyle( mBorderStyle );
 
87
  map["width_border"] = QString::number( mBorderWidth );
 
88
  return map;
 
89
}
 
90
 
 
91
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
 
92
{
 
93
  return new QgsSimpleFillSymbolLayerV2( mColor, mBrushStyle, mBorderColor, mBorderStyle, mBorderWidth );
 
94
}