Skip to content

Commit

Permalink
Initial support for 3D map item in print layouts GUI
Browse files Browse the repository at this point in the history
The GUI logic is not working yet, just getting the new files ready.

Many thanks to @nirvn for the icon!
  • Loading branch information
wonder-sk committed Aug 21, 2018
1 parent eb220ed commit d4a3f68
Show file tree
Hide file tree
Showing 10 changed files with 463 additions and 1 deletion.
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
7 changes: 6 additions & 1 deletion src/3d/qgslayoutitem3dmap.cpp
Expand Up @@ -26,9 +26,11 @@
QgsLayoutItem3DMap::QgsLayoutItem3DMap( QgsLayout *layout )
: QgsLayoutItem( layout )
{

}

QgsLayoutItem3DMap::~QgsLayoutItem3DMap() = default;


QgsLayoutItem3DMap *QgsLayoutItem3DMap::create( QgsLayout *layout )
{
return new QgsLayoutItem3DMap( layout );
Expand All @@ -41,6 +43,9 @@ int QgsLayoutItem3DMap::type() const

void QgsLayoutItem3DMap::draw( QgsLayoutItemRenderContext &context )
{
if ( !mSettings )
return;

QgsOffscreen3DEngine engine;
QSizeF sizePixels = mLayout->renderContext().measurementConverter().convert( sizeWithUnits(), QgsUnitTypes::LayoutPixels ).toQSizeF();
engine.setSize( QSize( static_cast<int>( std::ceil( sizePixels.width() ) ),
Expand Down
3 changes: 3 additions & 0 deletions src/3d/qgslayoutitem3dmap.h
Expand Up @@ -34,6 +34,7 @@ class Qgs3DMapSettings;
*/
class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem
{
Q_OBJECT

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
Expand Down Expand Up @@ -61,6 +62,8 @@ class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem
*/
QgsLayoutItem3DMap( QgsLayout *layout SIP_TRANSFERTHIS );

~QgsLayoutItem3DMap();

/**
* Returns a new 3D map item for the specified \a layout.
*
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -446,6 +446,7 @@ IF (WITH_3D)
3d/qgspolygon3dsymbolwidget.cpp
3d/qgsphongmaterialwidget.cpp
3d/qgsvectorlayer3drendererwidget.cpp
layout/qgslayout3dmapwidget.cpp
)

SET (QGIS_APP_MOC_HDRS
Expand All @@ -459,6 +460,7 @@ IF (WITH_3D)
3d/qgspolygon3dsymbolwidget.h
3d/qgsphongmaterialwidget.h
3d/qgsvectorlayer3drendererwidget.h
layout/qgslayout3dmapwidget.h
)
ENDIF (WITH_3D)

Expand Down
24 changes: 24 additions & 0 deletions src/app/layout/qgslayout3dmapwidget.cpp
@@ -0,0 +1,24 @@
/***************************************************************************
qgslayout3dmapwidget.cpp
--------------------------------------
Date : August 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* 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 "qgslayout3dmapwidget.h"


QgsLayout3DMapWidget::QgsLayout3DMapWidget( QgsLayoutItem3DMap *map3D )
: QgsLayoutItemBaseWidget( nullptr, map3D )
, mMap3D( map3D )
{
setupUi( this );
}
35 changes: 35 additions & 0 deletions src/app/layout/qgslayout3dmapwidget.h
@@ -0,0 +1,35 @@
/***************************************************************************
qgslayout3dmapwidget.h
--------------------------------------
Date : August 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* 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 QGSLAYOUT3DMAPWIDGET_H
#define QGSLAYOUT3DMAPWIDGET_H

#include "qgslayoutitemwidget.h"
#include "ui_qgslayout3dmapwidgetbase.h"
#include "qgslayoutitem3dmap.h"

class QgsLayoutItem3DMap;

class QgsLayout3DMapWidget : public QgsLayoutItemBaseWidget, private Ui::QgsLayout3DMapWidgetBase
{
Q_OBJECT
public:
explicit QgsLayout3DMapWidget( QgsLayoutItem3DMap *map3D );

private:
QPointer< QgsLayoutItem3DMap > mMap3D;
};

#endif // QGSLAYOUT3DMAPWIDGET_H
15 changes: 15 additions & 0 deletions src/app/layout/qgslayoutapputils.cpp
Expand Up @@ -43,6 +43,10 @@
#include "qgisapp.h"
#include "qgsmapcanvas.h"

#ifdef HAVE_3D
#include "qgslayout3dmapwidget.h"
#endif

void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
{
QgsLayoutItemGuiRegistry *registry = QgsGui::layoutItemGuiRegistry();
Expand Down Expand Up @@ -341,4 +345,15 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
return f;
} );
registry->addLayoutItemGuiMetadata( attributeTableItemMetadata .release() );

// 3D map item
#ifdef HAVE_3D
std::unique_ptr< QgsLayoutItemGuiMetadata > map3dMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata>(
QgsLayoutItemRegistry::Layout3DMap, QObject::tr( "3D Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAdd3DMap.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return new QgsLayout3DMapWidget( qobject_cast< QgsLayoutItem3DMap * >( item ) );
}, createRubberBand );
registry->addLayoutItemGuiMetadata( map3dMetadata.release() );
#endif
}

0 comments on commit d4a3f68

Please sign in to comment.