Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start implementation of QgsDxfPaintDevice / Engine to export svg mark…
…ers to dxf
- Loading branch information
Showing
7 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*************************************************************************** | ||
qgsdxpaintdevice.cpp | ||
-------------------- | ||
begin : November 2013 | ||
copyright : (C) 2013 by Marco Hugentobler | ||
email : marco at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsdxfpaintdevice.h" | ||
|
||
QgsDxfPaintDevice::QgsDxfPaintDevice( QgsDxfExport* dxf ): QPaintDevice(), mPaintEngine( 0 ) | ||
{ | ||
mPaintEngine = new QgsDxfPaintEngine( this, dxf ); | ||
} | ||
|
||
QgsDxfPaintDevice::~QgsDxfPaintDevice() | ||
{ | ||
delete mPaintEngine; | ||
} | ||
|
||
QPaintEngine* QgsDxfPaintDevice::paintEngine() const | ||
{ | ||
return mPaintEngine; | ||
} | ||
|
||
int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const | ||
{ | ||
switch ( metric ) | ||
{ | ||
case QPaintDevice::PdmWidth: | ||
return mDrawingSize.width(); | ||
case QPaintDevice::PdmHeight: | ||
return mDrawingSize.height(); | ||
case QPaintDevice::PdmWidthMM: | ||
return mDrawingSize.width(); | ||
case QPaintDevice::PdmHeightMM: | ||
return mDrawingSize.height(); | ||
case QPaintDevice::PdmNumColors: | ||
return INT_MAX; | ||
case QPaintDevice::PdmDepth: | ||
return 32; | ||
case QPaintDevice::PdmDpiX: | ||
case QPaintDevice::PdmDpiY: | ||
case QPaintDevice::PdmPhysicalDpiX: | ||
case QPaintDevice::PdmPhysicalDpiY: | ||
return 96; | ||
} | ||
return 0; | ||
} | ||
|
||
double QgsDxfPaintDevice::widthScaleFactor() const | ||
{ | ||
if ( !mDrawingSize.isValid() || mRectangle.isEmpty() ) | ||
{ | ||
return 1.0; | ||
} | ||
|
||
double widthFactor = mRectangle.width() / mDrawingSize.width(); | ||
double heightFactor = mRectangle.height() / mDrawingSize.height(); | ||
return ( widthFactor + heightFactor ) / 2.0; | ||
} | ||
|
||
QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt ) | ||
{ | ||
if ( !mDrawingSize.isValid() || mRectangle.isEmpty() ) | ||
{ | ||
return QPointF( pt.x(), pt.y() ); | ||
} | ||
|
||
double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() ); | ||
double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() ); | ||
return QPointF( x, y ); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*************************************************************************** | ||
qgsdxpaintdevice.h | ||
------------------ | ||
begin : November 2013 | ||
copyright : (C) 2013 by Marco Hugentobler | ||
email : marco at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSDXFPAINTDEVICE_H | ||
#define QGSDXFPAINTDEVICE_H | ||
|
||
#include <QPaintDevice> | ||
#include "qgsdxfpaintengine.h" | ||
|
||
class QgsDxfExport; | ||
class QPaintEngine; | ||
|
||
/**A paint device for drawing into dxf files*/ | ||
|
||
class QgsDxfPaintDevice: public QPaintDevice | ||
{ | ||
public: | ||
QgsDxfPaintDevice( QgsDxfExport* dxf ); | ||
~QgsDxfPaintDevice(); | ||
|
||
QPaintEngine* paintEngine() const; | ||
|
||
void setDrawingSize( const QSizeF& size ) { mDrawingSize = size; } | ||
void setOutputSize( const QRectF& r ) { mRectangle = r; } | ||
|
||
/**Returns scale factor for line width*/ | ||
double widthScaleFactor() const; | ||
|
||
/**Converts a point from device coordinates to dxf coordinates*/ | ||
QPointF dxfCoordinates( const QPointF& pt ); | ||
|
||
/*int height() const { return mDrawingSize.height(); } | ||
int width() const { return mDrawingSize.width(); }*/ | ||
|
||
int metric( PaintDeviceMetric metric ) const; | ||
|
||
|
||
private: | ||
QgsDxfPaintEngine* mPaintEngine; | ||
|
||
QSizeF mDrawingSize; //size (in source coordinates) | ||
QRectF mRectangle; //size (in dxf coordinates) | ||
}; | ||
|
||
#endif // QGSDXFPAINTDEVICE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/*************************************************************************** | ||
qgsdxpaintengine.cpp | ||
-------------------- | ||
begin : November 2013 | ||
copyright : (C) 2013 by Marco Hugentobler | ||
email : marco at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsdxfpaintengine.h" | ||
#include "qgsdxfexport.h" | ||
#include "qgslogger.h" | ||
|
||
QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf ): QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ ) | ||
, mPaintDevice( dxfDevice ), mDxf( dxf ) | ||
{ | ||
|
||
} | ||
|
||
QgsDxfPaintEngine::~QgsDxfPaintEngine() | ||
{ | ||
|
||
} | ||
|
||
bool QgsDxfPaintEngine::begin( QPaintDevice* pdev ) | ||
{ | ||
Q_UNUSED( pdev ); | ||
return true; | ||
} | ||
|
||
bool QgsDxfPaintEngine::end() | ||
{ | ||
return true; | ||
} | ||
|
||
QPaintEngine::Type QgsDxfPaintEngine::type() const | ||
{ | ||
return QPaintEngine::User; | ||
} | ||
|
||
void QgsDxfPaintEngine::drawPixmap( const QRectF& r, const QPixmap& pm, const QRectF& sr ) | ||
{ | ||
Q_UNUSED( r ); Q_UNUSED( pm ); Q_UNUSED( sr ); | ||
} | ||
|
||
void QgsDxfPaintEngine::updateState( const QPaintEngineState& state ) | ||
{ | ||
if ( state.state() | QPaintEngine::DirtyTransform ) | ||
{ | ||
mTransform = state.transform(); | ||
} | ||
if ( state.state() | QPaintEngine::DirtyPen ) | ||
{ | ||
mPen = state.pen(); | ||
} | ||
} | ||
|
||
void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, PolygonDrawMode mode ) | ||
{ | ||
QgsDebugMsg( "***********************Dxf paint engine: drawing polygon*********************" ); | ||
} | ||
|
||
void QgsDxfPaintEngine::drawRects( const QRectF * rects, int rectCount ) | ||
{ | ||
QgsDebugMsg( "***********************Dxf paint engine: drawing rects*********************" ); | ||
} | ||
|
||
void QgsDxfPaintEngine::drawEllipse( const QRectF& rect ) | ||
{ | ||
QgsDebugMsg( "***********************Dxf paint engine: drawing ellipse*********************" ); | ||
} | ||
|
||
void QgsDxfPaintEngine::drawPath( const QPainterPath& path ) | ||
{ | ||
QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" ); | ||
} | ||
|
||
void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount ) | ||
{ | ||
QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
qgsdxpaintengine.h | ||
------------------ | ||
begin : November 2013 | ||
copyright : (C) 2013 by Marco Hugentobler | ||
email : marco at sourcepole dot ch | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSDXFPAINTENGINE_H | ||
#define QGSDXFPAINTENGINE_H | ||
|
||
#include <QPaintEngine> | ||
|
||
class QgsDxfExport; | ||
class QgsDxfPaintDevice; | ||
|
||
class QgsDxfPaintEngine: public QPaintEngine | ||
{ | ||
public: | ||
QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf ); | ||
~QgsDxfPaintEngine(); | ||
|
||
bool begin( QPaintDevice* pdev ); | ||
bool end(); | ||
QPaintEngine::Type type() const; | ||
void updateState( const QPaintEngineState& state ); | ||
|
||
void drawPixmap( const QRectF& r, const QPixmap& pm, const QRectF& sr ); | ||
|
||
void drawPolygon( const QPointF * points, int pointCount, PolygonDrawMode mode ); | ||
void drawRects( const QRectF * rects, int rectCount ); | ||
void drawEllipse( const QRectF& rect ); | ||
void drawPath( const QPainterPath& path ); | ||
void drawLines( const QLineF* lines, int lineCount ); | ||
|
||
private: | ||
const QgsDxfPaintDevice* mPaintDevice; | ||
QgsDxfExport* mDxf; | ||
|
||
//painter state information | ||
QTransform mTransform; | ||
QPen mPen; | ||
}; | ||
|
||
#endif // QGSDXFPAINTENGINE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters