19
19
#include " qgs3dutils.h"
20
20
#include " qgscameracontroller.h"
21
21
#include " qgslayout.h"
22
+ #include " qgslayoutmodel.h"
22
23
#include " qgslayoutitemregistry.h"
23
24
#include " qgsoffscreen3dengine.h"
24
25
25
26
26
27
QgsLayoutItem3DMap::QgsLayoutItem3DMap ( QgsLayout *layout )
27
28
: QgsLayoutItem( layout )
28
29
{
30
+ assignFreeId ();
31
+
29
32
connect ( this , &QgsLayoutItem::sizePositionChanged, this , &QgsLayoutItem3DMap::onSizePositionChanged );
30
33
}
31
34
@@ -42,6 +45,49 @@ int QgsLayoutItem3DMap::type() const
42
45
return QgsLayoutItemRegistry::Layout3DMap;
43
46
}
44
47
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
+
45
91
void QgsLayoutItem3DMap::draw ( QgsLayoutItemRenderContext &context )
46
92
{
47
93
QgsRenderContext &ctx = context.renderContext ();
@@ -170,6 +216,11 @@ bool QgsLayoutItem3DMap::readPropertiesFromElement( const QDomElement &element,
170
216
return true ;
171
217
}
172
218
219
+ void QgsLayoutItem3DMap::finalizeRestoreFromXml ()
220
+ {
221
+ assignFreeId ();
222
+ }
223
+
173
224
void QgsLayoutItem3DMap::setMapSettings ( Qgs3DMapSettings *settings )
174
225
{
175
226
mSettings .reset ( settings );
0 commit comments