QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdxfpaintengine.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdxpaintengine.h
3  ------------------
4  begin : November 2013
5  copyright : (C) 2013 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSDXFPAINTENGINE_H
19 #define QGSDXFPAINTENGINE_H
20 
21 #include <QPaintEngine>
22 
23 class QgsDxfExport;
24 class QgsDxfPaintDevice;
25 class QgsPoint;
26 
27 class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
28 {
29  public:
30  QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf );
32 
33  bool begin( QPaintDevice* pdev ) override;
34  bool end() override;
35  QPaintEngine::Type type() const override;
36  void updateState( const QPaintEngineState& state ) override;
37 
38  void drawPixmap( const QRectF& r, const QPixmap& pm, const QRectF& sr ) override;
39 
40  void drawPolygon( const QPointF * points, int pointCount, PolygonDrawMode mode ) override;
41  void drawRects( const QRectF * rects, int rectCount ) override;
42  void drawPath( const QPainterPath& path ) override;
43  void drawLines( const QLineF* lines, int lineCount ) override;
44 
45  void setLayer( const QString& layer ) { mLayer = layer; }
46  QString layer() const { return mLayer; }
47 
48  void setShift( const QPointF& shift ) { mShift = shift; }
49 
50  private:
51  const QgsDxfPaintDevice* mPaintDevice;
52  QgsDxfExport* mDxf;
53 
54  //painter state information
55  QTransform mTransform;
56  QPen mPen;
57  QBrush mBrush;
58  QString mLayer;
59  QPointF mShift;
60  QPolygonF mCurrentPolygon;
61  QList<QPointF> mCurrentCurve;
62 
63  QgsPoint toDxfCoordinates( const QPointF& pt ) const;
64  double currentWidth() const;
65 
66  void moveTo( double dx, double dy );
67  void lineTo( double dx, double dy );
68  void curveTo( double dx, double dy );
69  void endPolygon();
70  void endCurve();
71 
72  //utils for bezier curve calculation
73  static QPointF bezierPoint( const QList<QPointF>& controlPolygon, double t );
74  static double bernsteinPoly( int n, int i, double t );
75  static int lower( int n, int i );
76  static double power( double a, int b );
77  static int faculty( int n );
78 };
79 
80 #endif // QGSDXFPAINTENGINE_H