Skip to content

Commit 02a6b83

Browse files
committed
Numbering of 3d map print layout items
1 parent 3a0454f commit 02a6b83

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

src/3d/qgslayoutitem3dmap.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
#include "qgs3dutils.h"
2020
#include "qgscameracontroller.h"
2121
#include "qgslayout.h"
22+
#include "qgslayoutmodel.h"
2223
#include "qgslayoutitemregistry.h"
2324
#include "qgsoffscreen3dengine.h"
2425

2526

2627
QgsLayoutItem3DMap::QgsLayoutItem3DMap( QgsLayout *layout )
2728
: QgsLayoutItem( layout )
2829
{
30+
assignFreeId();
31+
2932
connect( this, &QgsLayoutItem::sizePositionChanged, this, &QgsLayoutItem3DMap::onSizePositionChanged );
3033
}
3134

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

48+
void QgsLayoutItem3DMap::assignFreeId()
49+
{
50+
if ( !mLayout )
51+
return;
52+
53+
QList<QgsLayoutItem3DMap *> mapsList;
54+
mLayout->layoutItems( mapsList );
55+
56+
int maxId = -1;
57+
bool used = false;
58+
for ( QgsLayoutItem3DMap *map : qgis::as_const( mapsList ) )
59+
{
60+
if ( map == this )
61+
continue;
62+
63+
if ( map->mMapId == mMapId )
64+
used = true;
65+
66+
maxId = std::max( maxId, map->mMapId );
67+
}
68+
if ( used )
69+
{
70+
mMapId = maxId + 1;
71+
mLayout->itemsModel()->updateItemDisplayName( this );
72+
}
73+
updateToolTip();
74+
}
75+
76+
QString QgsLayoutItem3DMap::displayName() const
77+
{
78+
if ( !QgsLayoutItem::id().isEmpty() )
79+
{
80+
return QgsLayoutItem::id();
81+
}
82+
83+
return tr( "3D Map %1" ).arg( mMapId );
84+
}
85+
86+
void QgsLayoutItem3DMap::updateToolTip()
87+
{
88+
setToolTip( displayName() );
89+
}
90+
4591
void QgsLayoutItem3DMap::draw( QgsLayoutItemRenderContext &context )
4692
{
4793
QgsRenderContext &ctx = context.renderContext();
@@ -170,6 +216,11 @@ bool QgsLayoutItem3DMap::readPropertiesFromElement( const QDomElement &element,
170216
return true;
171217
}
172218

219+
void QgsLayoutItem3DMap::finalizeRestoreFromXml()
220+
{
221+
assignFreeId();
222+
}
223+
173224
void QgsLayoutItem3DMap::setMapSettings( Qgs3DMapSettings *settings )
174225
{
175226
mSettings.reset( settings );

src/3d/qgslayoutitem3dmap.h

+17
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ class _3D_EXPORT QgsLayoutItem3DMap : public QgsLayoutItem
8989
//! Returns map scene. May be a null pointer if not yet configured.
9090
Qgs3DMapSettings *mapSettings() const { return mSettings.get(); }
9191

92+
/**
93+
* Sets the map id() to a number not yet used in the layout. The existing id() is kept if it is not in use.
94+
*/
95+
void assignFreeId();
96+
97+
//! overridden to show "3D Map 1" type names
98+
QString displayName() const override;
99+
100+
void finalizeRestoreFromXml() override;
101+
92102
public slots:
93103
void refresh() override;
94104

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

115+
private:
116+
//! Resets the item tooltip to reflect current map id
117+
void updateToolTip();
118+
105119
private:
106120
std::unique_ptr<Qgs3DMapSettings> mSettings;
107121
std::unique_ptr<QgsOffscreen3DEngine> mEngine;
108122
Qgs3DMapScene *mScene = nullptr; //!< 3D scene (owned by the 3D engine)
109123
QImage mCapturedImage;
110124
QgsCameraPose mCameraPose;
111125
bool mDrawing = false;
126+
127+
//! Unique identifier
128+
int mMapId = 1;
112129
};
113130

114131
#endif // QGSLAYOUTITEM3DMAP_H

0 commit comments

Comments
 (0)