Skip to content

Commit

Permalink
Numbering of 3d map print layout items
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Aug 25, 2018
1 parent 3a0454f commit 02a6b83
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/3d/qgslayoutitem3dmap.cpp
Expand Up @@ -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 );
}

Expand All @@ -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();
Expand Down Expand Up @@ -170,6 +216,11 @@ bool QgsLayoutItem3DMap::readPropertiesFromElement( const QDomElement &element,
return true;
}

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

void QgsLayoutItem3DMap::setMapSettings( Qgs3DMapSettings *settings )
{
mSettings.reset( settings );
Expand Down
17 changes: 17 additions & 0 deletions src/3d/qgslayoutitem3dmap.h
Expand Up @@ -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;

Expand All @@ -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.