Skip to content
Permalink
Browse files

Numbering of 3d map print layout items

  • Loading branch information
wonder-sk committed Aug 25, 2018
1 parent 3a0454f commit 02a6b83974eb2ffc825e73576a2981109998f22e
Showing with 68 additions and 0 deletions.
  1. +51 −0 src/3d/qgslayoutitem3dmap.cpp
  2. +17 −0 src/3d/qgslayoutitem3dmap.h
@@ -19,13 +19,16 @@
#include "qgs3dutils.h"
#include "qgscameracontroller.h"
#include "qgslayout.h"
#include "qgslayoutmodel.h"
#include "qgslayoutitemregistry.h"
#include "qgsoffscreen3dengine.h"


QgsLayoutItem3DMap::QgsLayoutItem3DMap( QgsLayout *layout )
: QgsLayoutItem( layout )
{
assignFreeId();

connect( this, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItem3DMap::onSizePositionChanged );
}

@@ -42,6 +45,49 @@ int QgsLayoutItem3DMap::type() const
return QgsLayoutItemRegistry::Layout3DMap;
}

void QgsLayoutItem3DMap::assignFreeId()
{
if ( !mLayout )
return;

QList<QgsLayoutItem3DMap *> mapsList;
mLayout->layoutItems( mapsList );

int maxId = -1;
bool used = false;
for ( QgsLayoutItem3DMap *map : qgis::as_const( mapsList ) )
{
if ( map == this )
continue;

if ( map->mMapId == mMapId )
used = true;

maxId = std::max( maxId, map->mMapId );
}
if ( used )
{
mMapId = maxId + 1;
mLayout->itemsModel()->updateItemDisplayName( this );
}
updateToolTip();
}

QString QgsLayoutItem3DMap::displayName() const
{
if ( !QgsLayoutItem::id().isEmpty() )
{
return QgsLayoutItem::id();
}

return tr( "3D Map %1" ).arg( mMapId );
}

void QgsLayoutItem3DMap::updateToolTip()
{
setToolTip( displayName() );
}

void QgsLayoutItem3DMap::draw( QgsLayoutItemRenderContext &context )
{
QgsRenderContext &ctx = context.renderContext();
@@ -170,6 +216,11 @@ bool QgsLayoutItem3DMap::readPropertiesFromElement( const QDomElement &element,
return true;
}

void QgsLayoutItem3DMap::finalizeRestoreFromXml()
{
assignFreeId();
}

void QgsLayoutItem3DMap::setMapSettings( Qgs3DMapSettings *settings )
{
mSettings.reset( settings );
@@ -89,6 +89,16 @@ class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem
//! Returns map scene. May be a null pointer if not yet configured.
Qgs3DMapSettings *mapSettings() const { return mSettings.get(); }

/**
* Sets the map id() to a number not yet used in the layout. The existing id() is kept if it is not in use.
*/
void assignFreeId();

//! overridden to show "3D Map 1" type names
QString displayName() const override;

void finalizeRestoreFromXml() override;

public slots:
void refresh() override;

@@ -102,13 +112,20 @@ class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem
void onSceneStateChanged();
void onSizePositionChanged();

private:
//! Resets the item tooltip to reflect current map id
void updateToolTip();

private:
std::unique_ptr<Qgs3DMapSettings> mSettings;
std::unique_ptr<QgsOffscreen3DEngine> mEngine;
Qgs3DMapScene *mScene = nullptr; //!< 3D scene (owned by the 3D engine)
QImage mCapturedImage;
QgsCameraPose mCameraPose;
bool mDrawing = false;

//! Unique identifier
int mMapId = 1;
};

#endif // QGSLAYOUTITEM3DMAP_H

0 comments on commit 02a6b83

Please sign in to comment.
You can’t perform that action at this time.