QGIS API Documentation  2.14.0-Essen
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 #include "qgsgeometryfactory.h"
23 
24 class QgsDxfExport;
25 class QgsDxfPaintDevice;
26 class QgsPoint;
27 
32 class CORE_EXPORT QgsDxfPaintEngine: public QPaintEngine
33 {
34  public:
35  QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf );
37 
38  bool begin( QPaintDevice* pdev ) override;
39  bool end() override;
40  QPaintEngine::Type type() const override;
41  void updateState( const QPaintEngineState& state ) override;
42 
43  void drawPixmap( const QRectF& r, const QPixmap& pm, const QRectF& sr ) override;
44 
45  void drawPolygon( const QPointF * points, int pointCount, PolygonDrawMode mode ) override;
46  void drawPath( const QPainterPath& path ) override;
47  void drawLines( const QLineF* lines, int lineCount ) override;
48 
49  void setLayer( const QString& layer ) { mLayer = layer; }
50  QString layer() const { return mLayer; }
51 
52  void setShift( QPointF shift ) { mShift = shift; }
53 
54  private:
55  const QgsDxfPaintDevice* mPaintDevice;
56  QgsDxfExport* mDxf;
57 
58  //painter state information
59  QTransform mTransform;
60  QPen mPen;
61  QBrush mBrush;
62  QString mLayer;
63  QPointF mShift;
64  QgsPolygon mPolygon;
65  QPolygonF mCurrentPolygon;
66  QList<QPointF> mCurrentCurve;
67 
68  QgsPoint toDxfCoordinates( QPointF pt ) const;
69  double currentWidth() const;
70 
71  void moveTo( double dx, double dy );
72  void lineTo( double dx, double dy );
73  void curveTo( double dx, double dy );
74  void endPolygon();
75  void endCurve();
76 
77  void setRing( QgsPolyline &polyline, const QPointF * points, int pointCount );
78 
79  //utils for bezier curve calculation
80  static QPointF bezierPoint( const QList<QPointF>& controlPolygon, double t );
81  static double bernsteinPoly( int n, int i, double t );
82  static int lower( int n, int i );
83  static double power( double a, int b );
84  static int faculty( int n );
85 };
86 
87 #endif // QGSDXFPAINTENGINE_H
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)=0
virtual void drawPath(const QPainterPath &path)
A paint device for drawing into dxf files.
virtual bool begin(QPaintDevice *pdev)=0
QString layer() const
int ANALYSIS_EXPORT faculty(int n)
Faculty function.
virtual bool end()=0
virtual void drawLines(const QLine *lines, int lineCount)
virtual Type type() const =0
void setShift(QPointF shift)
A class to represent a point.
Definition: qgspoint.h:65
double ANALYSIS_EXPORT power(double a, int b)
Power function for integer coefficients.
int ANALYSIS_EXPORT lower(int n, int i)
Lower function.
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
virtual void updateState(const QPaintEngineState &state)=0
void setLayer(const QString &layer)