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