Skip to content

Commit d4a3f68

Browse files
committed
Initial support for 3D map item in print layouts GUI
The GUI logic is not working yet, just getting the new files ready. Many thanks to @nirvn for the icon!
1 parent eb220ed commit d4a3f68

10 files changed

+463
-1
lines changed

images/images.qrc

+1
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>
+163
Loading

src/3d/CMakeLists.txt

+1
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/qgslayoutitem3dmap.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
QgsLayoutItem3DMap::QgsLayoutItem3DMap( QgsLayout *layout )
2727
: QgsLayoutItem( layout )
2828
{
29-
3029
}
3130

31+
QgsLayoutItem3DMap::~QgsLayoutItem3DMap() = default;
32+
33+
3234
QgsLayoutItem3DMap *QgsLayoutItem3DMap::create( QgsLayout *layout )
3335
{
3436
return new QgsLayoutItem3DMap( layout );
@@ -41,6 +43,9 @@ int QgsLayoutItem3DMap::type() const
4143

4244
void QgsLayoutItem3DMap::draw( QgsLayoutItemRenderContext &context )
4345
{
46+
if ( !mSettings )
47+
return;
48+
4449
QgsOffscreen3DEngine engine;
4550
QSizeF sizePixels = mLayout->renderContext().measurementConverter().convert( sizeWithUnits(), QgsUnitTypes::LayoutPixels ).toQSizeF();
4651
engine.setSize( QSize( static_cast<int>( std::ceil( sizePixels.width() ) ),

src/3d/qgslayoutitem3dmap.h

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Qgs3DMapSettings;
3434
*/
3535
class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem
3636
{
37+
Q_OBJECT
3738

3839
#ifdef SIP_RUN
3940
SIP_CONVERT_TO_SUBCLASS_CODE
@@ -61,6 +62,8 @@ class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem
6162
*/
6263
QgsLayoutItem3DMap( QgsLayout *layout SIP_TRANSFERTHIS );
6364

65+
~QgsLayoutItem3DMap();
66+
6467
/**
6568
* Returns a new 3D map item for the specified \a layout.
6669
*

src/app/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ IF (WITH_3D)
446446
3d/qgspolygon3dsymbolwidget.cpp
447447
3d/qgsphongmaterialwidget.cpp
448448
3d/qgsvectorlayer3drendererwidget.cpp
449+
layout/qgslayout3dmapwidget.cpp
449450
)
450451

451452
SET (QGIS_APP_MOC_HDRS
@@ -459,6 +460,7 @@ IF (WITH_3D)
459460
3d/qgspolygon3dsymbolwidget.h
460461
3d/qgsphongmaterialwidget.h
461462
3d/qgsvectorlayer3drendererwidget.h
463+
layout/qgslayout3dmapwidget.h
462464
)
463465
ENDIF (WITH_3D)
464466

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/***************************************************************************
2+
qgslayout3dmapwidget.cpp
3+
--------------------------------------
4+
Date : August 2018
5+
Copyright : (C) 2018 by Martin Dobias
6+
Email : wonder dot sk at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgslayout3dmapwidget.h"
17+
18+
19+
QgsLayout3DMapWidget::QgsLayout3DMapWidget( QgsLayoutItem3DMap *map3D )
20+
: QgsLayoutItemBaseWidget( nullptr, map3D )
21+
, mMap3D( map3D )
22+
{
23+
setupUi( this );
24+
}

src/app/layout/qgslayout3dmapwidget.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/***************************************************************************
2+
qgslayout3dmapwidget.h
3+
--------------------------------------
4+
Date : August 2018
5+
Copyright : (C) 2018 by Martin Dobias
6+
Email : wonder dot sk at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSLAYOUT3DMAPWIDGET_H
17+
#define QGSLAYOUT3DMAPWIDGET_H
18+
19+
#include "qgslayoutitemwidget.h"
20+
#include "ui_qgslayout3dmapwidgetbase.h"
21+
#include "qgslayoutitem3dmap.h"
22+
23+
class QgsLayoutItem3DMap;
24+
25+
class QgsLayout3DMapWidget : public QgsLayoutItemBaseWidget, private Ui::QgsLayout3DMapWidgetBase
26+
{
27+
Q_OBJECT
28+
public:
29+
explicit QgsLayout3DMapWidget( QgsLayoutItem3DMap *map3D );
30+
31+
private:
32+
QPointer< QgsLayoutItem3DMap > mMap3D;
33+
};
34+
35+
#endif // QGSLAYOUT3DMAPWIDGET_H

src/app/layout/qgslayoutapputils.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
#include "qgisapp.h"
4444
#include "qgsmapcanvas.h"
4545

46+
#ifdef HAVE_3D
47+
#include "qgslayout3dmapwidget.h"
48+
#endif
49+
4650
void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
4751
{
4852
QgsLayoutItemGuiRegistry *registry = QgsGui::layoutItemGuiRegistry();
@@ -341,4 +345,15 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
341345
return f;
342346
} );
343347
registry->addLayoutItemGuiMetadata( attributeTableItemMetadata .release() );
348+
349+
// 3D map item
350+
#ifdef HAVE_3D
351+
std::unique_ptr< QgsLayoutItemGuiMetadata > map3dMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata>(
352+
QgsLayoutItemRegistry::Layout3DMap, QObject::tr( "3D Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAdd3DMap.svg" ) ),
353+
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
354+
{
355+
return new QgsLayout3DMapWidget( qobject_cast< QgsLayoutItem3DMap * >( item ) );
356+
}, createRubberBand );
357+
registry->addLayoutItemGuiMetadata( map3dMetadata.release() );
358+
#endif
344359
}

0 commit comments

Comments
 (0)