Skip to content

Commit

Permalink
[FEATURE] 3D maps in print layouts (part 2) - PR #7705
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Aug 25, 2018
2 parents 6097b13 + 02a6b83 commit 504cd61
Show file tree
Hide file tree
Showing 14 changed files with 894 additions and 16 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -702,6 +702,7 @@
<file>themes/default/mIconGPU.svg</file>
<file>themes/default/mAddToProject.svg</file>
<file>themes/default/mDockify.svg</file>
<file>themes/default/mActionAdd3DMap.svg</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Expand Down
163 changes: 163 additions & 0 deletions images/themes/default/mActionAdd3DMap.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/3d/CMakeLists.txt
Expand Up @@ -54,6 +54,7 @@ SET(QGIS_3D_MOC_HDRS
qgs3dmapsettings.h
qgsabstract3dengine.h
qgscameracontroller.h
qgslayoutitem3dmap.h
qgsoffscreen3dengine.h
qgswindow3dengine.h

Expand Down
12 changes: 12 additions & 0 deletions src/3d/qgs3dmapsettings.cpp
Expand Up @@ -63,6 +63,13 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
elemOrigin.attribute( "y" ).toDouble(),
elemOrigin.attribute( "z" ).toDouble() );

QDomElement elemColor = elem.firstChildElement( "color" );
if ( !elemColor.isNull() )
{
mBackgroundColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( "background" ) );
mSelectionColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( "selection" ) );
}

QDomElement elemCrs = elem.firstChildElement( "crs" );
mCrs.readXml( elemCrs );

Expand Down Expand Up @@ -147,6 +154,11 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
elemOrigin.setAttribute( "z", QString::number( mOrigin.z() ) );
elem.appendChild( elemOrigin );

QDomElement elemColor = doc.createElement( "color" );
elemColor.setAttribute( "background", QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) );
elemColor.setAttribute( "selection", QgsSymbolLayerUtils::encodeColor( mSelectionColor ) );
elem.appendChild( elemColor );

QDomElement elemCrs = doc.createElement( "crs" );
mCrs.writeXml( elemCrs, doc );
elem.appendChild( elemCrs );
Expand Down
3 changes: 3 additions & 0 deletions src/3d/qgscameracontroller.cpp
Expand Up @@ -419,6 +419,9 @@ void QgsCameraController::setLookingAtPoint( const QgsVector3D &point, float dis

void QgsCameraController::setCameraPose( const QgsCameraPose &camPose )
{
if ( camPose == mCameraPose )
return;

mCameraPose = camPose;

if ( mCamera )
Expand Down
25 changes: 25 additions & 0 deletions src/3d/qgscamerapose.cpp
Expand Up @@ -17,6 +17,31 @@

#include <Qt3DRender/QCamera>

#include <QDomDocument>

QDomElement QgsCameraPose::writeXml( QDomDocument &doc ) const
{
QDomElement elemCamera = doc.createElement( "camera-pose" );
elemCamera.setAttribute( QStringLiteral( "x" ), mCenterPoint.x() );
elemCamera.setAttribute( QStringLiteral( "y" ), mCenterPoint.y() );
elemCamera.setAttribute( QStringLiteral( "z" ), mCenterPoint.z() );
elemCamera.setAttribute( QStringLiteral( "dist" ), mDistanceFromCenterPoint );
elemCamera.setAttribute( QStringLiteral( "pitch" ), mPitchAngle );
elemCamera.setAttribute( QStringLiteral( "heading" ), mHeadingAngle );
return elemCamera;
}

void QgsCameraPose::readXml( const QDomElement &elem )
{
double x = elem.attribute( QStringLiteral( "x" ) ).toDouble();
double y = elem.attribute( QStringLiteral( "y" ) ).toDouble();
double z = elem.attribute( QStringLiteral( "z" ) ).toDouble();
mCenterPoint = QgsVector3D( x, y, z );

mDistanceFromCenterPoint = elem.attribute( QStringLiteral( "dist" ) ).toFloat();
mPitchAngle = elem.attribute( QStringLiteral( "pitch" ) ).toFloat();
mHeadingAngle = elem.attribute( QStringLiteral( "heading" ) ).toFloat();
}

void QgsCameraPose::updateCamera( Qt3DRender::QCamera *camera )
{
Expand Down
8 changes: 8 additions & 0 deletions src/3d/qgscamerapose.h
Expand Up @@ -25,6 +25,9 @@ namespace Qt3DRender
class QCamera;
}

class QDomDocument;
class QDomElement;

/**
* \ingroup 3d
* Class that encapsulates camera pose in a 3D scene. The pose is defined with the following parameters:
Expand Down Expand Up @@ -62,6 +65,11 @@ class _3D_EXPORT QgsCameraPose
//! Update Qt3D camera view matrix based on the pose
void updateCamera( Qt3DRender::QCamera *camera );

//! Writes configuration to a new DOM element and returns it
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from a DOM element previously written using writeXml()
void readXml( const QDomElement &elem );

bool operator==( const QgsCameraPose &other ) const
{
return mCenterPoint == other.mCenterPoint &&
Expand Down

0 comments on commit 504cd61

Please sign in to comment.