QGIS API Documentation  2.6.0-Brighton
 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 );
34  bool end();
35  QPaintEngine::Type type() const;
36  void updateState( const QPaintEngineState& state );
37 
38  void drawPixmap( const QRectF& r, const QPixmap& pm, const QRectF& sr );
39 
40  void drawPolygon( const QPointF * points, int pointCount, PolygonDrawMode mode );
41  void drawRects( const QRectF * rects, int rectCount );
42  void drawPath( const QPainterPath& path );
43  void drawLines( const QLineF* lines, int lineCount );
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  QColor currentColor() const;
65  double currentWidth() const;
66 
67  void moveTo( double dx, double dy );
68  void lineTo( double dx, double dy );
69  void curveTo( double dx, double dy );
70  void endPolygon();
71  void endCurve();
72 
73  //utils for bezier curve calculation
74  static QPointF bezierPoint( const QList<QPointF>& controlPolygon, double t );
75  static double bernsteinPoly( int n, int i, double t );
76  static int lower( int n, int i );
77  static double power( double a, int b );
78  static int faculty( int n );
79 };
80 
81 #endif // QGSDXFPAINTENGINE_H