Skip to content

Commit 504cd61

Browse files
authored
[FEATURE] 3D maps in print layouts (part 2) - PR #7705
2 parents 6097b13 + 02a6b83 commit 504cd61

14 files changed

+894
-16
lines changed

images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@
702702
<file>themes/default/mIconGPU.svg</file>
703703
<file>themes/default/mAddToProject.svg</file>
704704
<file>themes/default/mDockify.svg</file>
705+
<file>themes/default/mActionAdd3DMap.svg</file>
705706
</qresource>
706707
<qresource prefix="/images/tips">
707708
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
Lines changed: 163 additions & 0 deletions
Loading

src/3d/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ SET(QGIS_3D_MOC_HDRS
5454
qgs3dmapsettings.h
5555
qgsabstract3dengine.h
5656
qgscameracontroller.h
57+
qgslayoutitem3dmap.h
5758
qgsoffscreen3dengine.h
5859
qgswindow3dengine.h
5960

src/3d/qgs3dmapsettings.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
6363
elemOrigin.attribute( "y" ).toDouble(),
6464
elemOrigin.attribute( "z" ).toDouble() );
6565

66+
QDomElement elemColor = elem.firstChildElement( "color" );
67+
if ( !elemColor.isNull() )
68+
{
69+
mBackgroundColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( "background" ) );
70+
mSelectionColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( "selection" ) );
71+
}
72+
6673
QDomElement elemCrs = elem.firstChildElement( "crs" );
6774
mCrs.readXml( elemCrs );
6875

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

157+
QDomElement elemColor = doc.createElement( "color" );
158+
elemColor.setAttribute( "background", QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) );
159+
elemColor.setAttribute( "selection", QgsSymbolLayerUtils::encodeColor( mSelectionColor ) );
160+
elem.appendChild( elemColor );
161+
150162
QDomElement elemCrs = doc.createElement( "crs" );
151163
mCrs.writeXml( elemCrs, doc );
152164
elem.appendChild( elemCrs );

src/3d/qgscameracontroller.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ void QgsCameraController::setLookingAtPoint( const QgsVector3D &point, float dis
419419

420420
void QgsCameraController::setCameraPose( const QgsCameraPose &camPose )
421421
{
422+
if ( camPose == mCameraPose )
423+
return;
424+
422425
mCameraPose = camPose;
423426

424427
if ( mCamera )

src/3d/qgscamerapose.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@
1717

1818
#include <Qt3DRender/QCamera>
1919

20+
#include <QDomDocument>
21+
22+
QDomElement QgsCameraPose::writeXml( QDomDocument &doc ) const
23+
{
24+
QDomElement elemCamera = doc.createElement( "camera-pose" );
25+
elemCamera.setAttribute( QStringLiteral( "x" ), mCenterPoint.x() );
26+
elemCamera.setAttribute( QStringLiteral( "y" ), mCenterPoint.y() );
27+
elemCamera.setAttribute( QStringLiteral( "z" ), mCenterPoint.z() );
28+
elemCamera.setAttribute( QStringLiteral( "dist" ), mDistanceFromCenterPoint );
29+
elemCamera.setAttribute( QStringLiteral( "pitch" ), mPitchAngle );
30+
elemCamera.setAttribute( QStringLiteral( "heading" ), mHeadingAngle );
31+
return elemCamera;
32+
}
33+
34+
void QgsCameraPose::readXml( const QDomElement &elem )
35+
{
36+
double x = elem.attribute( QStringLiteral( "x" ) ).toDouble();
37+
double y = elem.attribute( QStringLiteral( "y" ) ).toDouble();
38+
double z = elem.attribute( QStringLiteral( "z" ) ).toDouble();
39+
mCenterPoint = QgsVector3D( x, y, z );
40+
41+
mDistanceFromCenterPoint = elem.attribute( QStringLiteral( "dist" ) ).toFloat();
42+
mPitchAngle = elem.attribute( QStringLiteral( "pitch" ) ).toFloat();
43+
mHeadingAngle = elem.attribute( QStringLiteral( "heading" ) ).toFloat();
44+
}
2045

2146
void QgsCameraPose::updateCamera( Qt3DRender::QCamera *camera )
2247
{

src/3d/qgscamerapose.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ namespace Qt3DRender
2525
class QCamera;
2626
}
2727

28+
class QDomDocument;
29+
class QDomElement;
30+
2831
/**
2932
* \ingroup 3d
3033
* Class that encapsulates camera pose in a 3D scene. The pose is defined with the following parameters:
@@ -62,6 +65,11 @@ class _3D_EXPORT QgsCameraPose
6265
//! Update Qt3D camera view matrix based on the pose
6366
void updateCamera( Qt3DRender::QCamera *camera );
6467

68+
//! Writes configuration to a new DOM element and returns it
69+
QDomElement writeXml( QDomDocument &doc ) const;
70+
//! Reads configuration from a DOM element previously written using writeXml()
71+
void readXml( const QDomElement &elem );
72+
6573
bool operator==( const QgsCameraPose &other ) const
6674
{
6775
return mCenterPoint == other.mCenterPoint &&

0 commit comments

Comments
 (0)