Skip to content

Commit a9896ea

Browse files
committedDec 6, 2017
Port a bunch of QgsLayoutManager methods to use QgsLayouts
1 parent 3a0b751 commit a9896ea

File tree

8 files changed

+315
-29
lines changed

8 files changed

+315
-29
lines changed
 

‎python/core/layout/qgslayout.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb
537537
and updated.
538538
%End
539539

540+
void nameChanged( const QString &name );
541+
%Docstring
542+
Emitted when the layout's name is changed.
543+
.. seealso:: setName()
544+
%End
545+
540546
};
541547

542548

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
633633
{
634634
mLayout->guides().clear();
635635
} );
636+
connect( mLayout, &QgsLayout::nameChanged, this, &QgsLayoutDesignerDialog::setWindowTitle );
636637

637638
mActionShowGrid->setChecked( mLayout->context().gridVisible() );
638639
mActionSnapGrid->setChecked( mLayout->snapper().snapToGrid() );

‎src/app/qgisapp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7315,7 +7315,7 @@ bool QgisApp::uniqueComposerTitle( QWidget *parent, QString &composerTitle, bool
73157315
else
73167316
{
73177317
titleValid = true;
7318-
newTitle = QgsProject::instance()->layoutManager()->generateUniqueTitle();
7318+
newTitle = QgsProject::instance()->layoutManager()->generateUniqueComposerTitle();
73197319
}
73207320
}
73217321
else if ( cNames.indexOf( newTitle, 1 ) >= 0 )
@@ -7380,7 +7380,7 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
73807380
else
73817381
{
73827382
titleValid = true;
7383-
newTitle = QgsProject::instance()->layoutManager()->generateUniqueTitle();
7383+
newTitle = QgsProject::instance()->layoutManager()->generateUniqueComposerTitle();
73847384
}
73857385
}
73867386
else if ( cNames.indexOf( newTitle, 1 ) >= 0 )
@@ -7403,7 +7403,7 @@ QgsComposer *QgisApp::createNewComposer( QString title )
74037403
{
74047404
if ( title.isEmpty() )
74057405
{
7406-
title = QgsProject::instance()->layoutManager()->generateUniqueTitle();
7406+
title = QgsProject::instance()->layoutManager()->generateUniqueComposerTitle();
74077407
}
74087408
//create new composition object
74097409
QgsComposition *composition = new QgsComposition( QgsProject::instance() );

‎src/core/composer/qgslayoutmanager.cpp

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ bool QgsLayoutManager::addComposition( QgsComposition *composition )
5353
return true;
5454
}
5555

56+
bool QgsLayoutManager::addLayout( QgsLayout *layout )
57+
{
58+
if ( !layout )
59+
return false;
60+
61+
// check for duplicate name
62+
for ( QgsLayout *l : qgis::as_const( mLayouts ) )
63+
{
64+
if ( l->name() == layout->name() )
65+
return false;
66+
}
67+
68+
connect( layout, &QgsLayout::nameChanged, this, [this, layout]( const QString & newName )
69+
{
70+
emit layoutRenamed( layout, newName );
71+
} );
72+
emit layoutAboutToBeAdded( layout->name() );
73+
mLayouts << layout;
74+
emit layoutAdded( layout->name() );
75+
mProject->setDirty( true );
76+
return true;
77+
}
78+
5679
bool QgsLayoutManager::removeComposition( QgsComposition *composition )
5780
{
5881
if ( !composition )
@@ -70,19 +93,46 @@ bool QgsLayoutManager::removeComposition( QgsComposition *composition )
7093
return true;
7194
}
7295

96+
bool QgsLayoutManager::removeLayout( QgsLayout *layout )
97+
{
98+
if ( !layout )
99+
return false;
100+
101+
if ( !mLayouts.contains( layout ) )
102+
return false;
103+
104+
QString name = layout->name();
105+
emit layoutAboutToBeRemoved( name );
106+
mLayouts.removeAll( layout );
107+
delete layout;
108+
emit layoutRemoved( name );
109+
mProject->setDirty( true );
110+
return true;
111+
}
112+
73113
void QgsLayoutManager::clear()
74114
{
75115
Q_FOREACH ( QgsComposition *c, mCompositions )
76116
{
77117
removeComposition( c );
78118
}
119+
const QList< QgsLayout * > layouts = mLayouts;
120+
for ( QgsLayout *l : layouts )
121+
{
122+
removeLayout( l );
123+
}
79124
}
80125

81126
QList<QgsComposition *> QgsLayoutManager::compositions() const
82127
{
83128
return mCompositions;
84129
}
85130

131+
QList<QgsLayout *> QgsLayoutManager::layouts() const
132+
{
133+
return mLayouts;
134+
}
135+
86136
QgsComposition *QgsLayoutManager::compositionByName( const QString &name ) const
87137
{
88138
Q_FOREACH ( QgsComposition *c, mCompositions )
@@ -93,6 +143,16 @@ QgsComposition *QgsLayoutManager::compositionByName( const QString &name ) const
93143
return nullptr;
94144
}
95145

146+
QgsLayout *QgsLayoutManager::layoutByName( const QString &name ) const
147+
{
148+
for ( QgsLayout *l : mLayouts )
149+
{
150+
if ( l->name() == name )
151+
return l;
152+
}
153+
return nullptr;
154+
}
155+
96156
bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &doc )
97157
{
98158
clear();
@@ -204,22 +264,19 @@ QgsLayout *QgsLayoutManager::duplicateLayout( const QgsLayout *layout, const QSt
204264
}
205265

206266
newLayout->setName( newName );
207-
#if 0 //TODO
208-
if ( !addComposition( newComposition ) )
267+
QgsLayout *l = newLayout.get();
268+
if ( !addLayout( l ) )
209269
{
210-
delete newComposition;
211270
return nullptr;
212271
}
213272
else
214273
{
215-
return newComposition;
274+
( void )newLayout.release(); //ownership was transferred successfully
275+
return l;
216276
}
217-
#endif
218-
219-
return newLayout.release();
220277
}
221278

222-
QString QgsLayoutManager::generateUniqueTitle() const
279+
QString QgsLayoutManager::generateUniqueComposerTitle() const
223280
{
224281
QStringList names;
225282
Q_FOREACH ( QgsComposition *c, mCompositions )
@@ -236,6 +293,23 @@ QString QgsLayoutManager::generateUniqueTitle() const
236293
return name;
237294
}
238295

296+
QString QgsLayoutManager::generateUniqueTitle() const
297+
{
298+
QStringList names;
299+
for ( QgsLayout *l : mLayouts )
300+
{
301+
names << l->name();
302+
}
303+
QString name;
304+
int id = 1;
305+
while ( name.isEmpty() || names.contains( name ) )
306+
{
307+
name = tr( "Layout %1" ).arg( id );
308+
id++;
309+
}
310+
return name;
311+
}
312+
239313
QgsComposition *QgsLayoutManager::createCompositionFromXml( const QDomElement &element, const QDomDocument &doc ) const
240314
{
241315
QDomNodeList compositionNodeList = element.elementsByTagName( QStringLiteral( "Composition" ) );

‎src/core/composer/qgslayoutmanager.h

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgis_core.h"
2020
#include "qgis.h"
2121
#include "qgscomposition.h"
22+
#include "qgslayout.h"
2223
#include <QObject>
2324

2425
class QgsProject;
@@ -28,13 +29,13 @@ class QgsProject;
2829
* \class QgsLayoutManager
2930
* \since QGIS 3.0
3031
*
31-
* \brief Manages storage of a set of compositions.
32+
* \brief Manages storage of a set of layouts.
3233
*
3334
* QgsLayoutManager handles the storage, serializing and deserializing
34-
* of QgsCompositions. Usually this class is not constructed directly, but
35+
* of QgsLayouts. Usually this class is not constructed directly, but
3536
* rather accessed through a QgsProject via QgsProject::layoutManager().
3637
*
37-
* QgsLayoutManager retains ownership of all the compositions contained
38+
* QgsLayoutManager retains ownership of all the layouts contained
3839
* in the manager.
3940
*/
4041

@@ -61,6 +62,15 @@ class CORE_EXPORT QgsLayoutManager : public QObject
6162
*/
6263
bool addComposition( QgsComposition *composition SIP_TRANSFER );
6364

65+
/**
66+
* Adds a \a layout to the manager. Ownership of the layout is transferred to the manager.
67+
* Returns true if the addition was successful, or false if the layout could not be added (eg
68+
* as a result of a duplicate layout name).
69+
* \see removeLayout()
70+
* \see layoutAdded()
71+
*/
72+
bool addLayout( QgsLayout *layout SIP_TRANSFER );
73+
6474
/**
6575
* Removes a composition from the manager. The composition is deleted.
6676
* Returns true if the removal was successful, or false if the removal failed (eg as a result
@@ -73,8 +83,19 @@ class CORE_EXPORT QgsLayoutManager : public QObject
7383
bool removeComposition( QgsComposition *composition );
7484

7585
/**
76-
* Removes and deletes all compositions from the manager.
77-
* \see removeComposition()
86+
* Removes a \a layout from the manager. The layout is deleted.
87+
* Returns true if the removal was successful, or false if the removal failed (eg as a result
88+
* of removing a layout which is not contained in the manager).
89+
* \see addLayout()
90+
* \see layoutRemoved()
91+
* \see layoutAboutToBeRemoved()
92+
* \see clear()
93+
*/
94+
bool removeLayout( QgsLayout *layout );
95+
96+
/**
97+
* Removes and deletes all layouts from the manager.
98+
* \see removeLayout()
7899
*/
79100
void clear();
80101

@@ -83,14 +104,25 @@ class CORE_EXPORT QgsLayoutManager : public QObject
83104
*/
84105
QList< QgsComposition * > compositions() const;
85106

107+
/**
108+
* Returns a list of all layouts contained in the manager.
109+
*/
110+
QList< QgsLayout * > layouts() const;
111+
86112
/**
87113
* Returns the composition with a matching name, or nullptr if no matching compositions
88114
* were found.
89115
*/
90116
QgsComposition *compositionByName( const QString &name ) const;
91117

92118
/**
93-
* Reads the manager's state from a DOM element, restoring all compositions
119+
* Returns the layout with a matching name, or nullptr if no matching layouts
120+
* were found.
121+
*/
122+
QgsLayout *layoutByName( const QString &name ) const;
123+
124+
/**
125+
* Reads the manager's state from a DOM element, restoring all layouts
94126
* present in the XML document.
95127
* \see writeXml()
96128
*/
@@ -126,30 +158,52 @@ class CORE_EXPORT QgsLayoutManager : public QObject
126158
* Generates a unique title for a new composition, which does not
127159
* clash with any already contained by the manager.
128160
*/
161+
QString generateUniqueComposerTitle() const;
162+
163+
/**
164+
* Generates a unique title for a new layout, which does not
165+
* clash with any already contained by the manager.
166+
*/
129167
QString generateUniqueTitle() const;
130168

131169
signals:
132170

133171
//! Emitted when a composition is about to be added to the manager
134172
void compositionAboutToBeAdded( const QString &name );
135173

174+
//! Emitted when a layout is about to be added to the manager
175+
void layoutAboutToBeAdded( const QString &name );
176+
136177
//! Emitted when a composition has been added to the manager
137178
void compositionAdded( const QString &name );
138179

180+
//! Emitted when a layout has been added to the manager
181+
void layoutAdded( const QString &name );
182+
139183
//! Emitted when a composition was removed from the manager
140184
void compositionRemoved( const QString &name );
141185

186+
//! Emitted when a layout was removed from the manager
187+
void layoutRemoved( const QString &name );
188+
142189
//! Emitted when a composition is about to be removed from the manager
143190
void compositionAboutToBeRemoved( const QString &name );
144191

192+
//! Emitted when a layout is about to be removed from the manager
193+
void layoutAboutToBeRemoved( const QString &name );
194+
145195
//! Emitted when a composition is renamed
146196
void compositionRenamed( QgsComposition *composition, const QString &newName );
147197

198+
//! Emitted when a layout is renamed
199+
void layoutRenamed( QgsLayout *layout, const QString &newName );
200+
148201
private:
149202

150203
QgsProject *mProject = nullptr;
151204

152205
QList< QgsComposition * > mCompositions;
206+
QList< QgsLayout * > mLayouts;
153207

154208
QgsComposition *createCompositionFromXml( const QDomElement &element, const QDomDocument &doc ) const;
155209

‎src/core/layout/qgslayout.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ QgsLayoutExporter &QgsLayout::exporter()
117117
return mExporter;
118118
}
119119

120+
void QgsLayout::setName( const QString &name )
121+
{
122+
mName = name;
123+
emit nameChanged( name );
124+
}
125+
120126
QList<QgsLayoutItem *> QgsLayout::selectedLayoutItems( const bool includeLockedItems )
121127
{
122128
QList<QgsLayoutItem *> layoutItemList;

‎src/core/layout/qgslayout.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class QgsLayoutMultiFrame;
4040
class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContextGenerator, public QgsLayoutUndoObjectInterface
4141
{
4242
Q_OBJECT
43+
Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
4344

4445
public:
4546

@@ -108,7 +109,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
108109
* Sets the layout's name.
109110
* \see name()
110111
*/
111-
void setName( const QString &name ) { mName = name; }
112+
void setName( const QString &name );
112113

113114
/**
114115
* Returns a list of layout items of a specific type.
@@ -585,6 +586,12 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
585586
*/
586587
void refreshed();
587588

589+
/**
590+
* Emitted when the layout's name is changed.
591+
* \see setName()
592+
*/
593+
void nameChanged( const QString &name );
594+
588595
private:
589596

590597
QgsProject *mProject = nullptr;

‎tests/src/python/test_qgslayoutmanager.py

Lines changed: 149 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from qgis.PyQt.QtXml import QDomDocument
1919

2020
from qgis.core import (QgsComposition,
21+
QgsLayout,
2122
QgsLayoutManager,
2223
QgsProject)
2324

@@ -73,6 +74,38 @@ def testAddComposition(self):
7374
composition3.setName('test composition2')
7475
self.assertFalse(manager.addComposition(composition3))
7576

77+
def testAddLayout(self):
78+
project = QgsProject()
79+
layout = QgsLayout(project)
80+
layout.setName('test layout')
81+
82+
manager = QgsLayoutManager(project)
83+
84+
layout_about_to_be_added_spy = QSignalSpy(manager.layoutAboutToBeAdded)
85+
layout_added_spy = QSignalSpy(manager.layoutAdded)
86+
self.assertTrue(manager.addLayout(layout))
87+
self.assertEqual(len(layout_about_to_be_added_spy), 1)
88+
self.assertEqual(layout_about_to_be_added_spy[0][0], 'test layout')
89+
self.assertEqual(len(layout_added_spy), 1)
90+
self.assertEqual(layout_added_spy[0][0], 'test layout')
91+
92+
# adding it again should fail
93+
self.assertFalse(manager.addLayout(layout))
94+
95+
# try adding a second layout
96+
layout2 = QgsLayout(project)
97+
layout2.setName('test layout2')
98+
self.assertTrue(manager.addLayout(layout2))
99+
self.assertEqual(len(layout_added_spy), 2)
100+
self.assertEqual(layout_about_to_be_added_spy[1][0], 'test layout2')
101+
self.assertEqual(len(layout_about_to_be_added_spy), 2)
102+
self.assertEqual(layout_added_spy[1][0], 'test layout2')
103+
104+
# adding a layout with duplicate name should fail
105+
layout3 = QgsLayout(project)
106+
layout3.setName('test layout2')
107+
self.assertFalse(manager.addLayout(layout3))
108+
76109
def testCompositions(self):
77110
project = QgsProject()
78111
manager = QgsLayoutManager(project)
@@ -90,6 +123,23 @@ def testCompositions(self):
90123
manager.addComposition(composition3)
91124
self.assertEqual(set(manager.compositions()), {composition, composition2, composition3})
92125

126+
def testLayouts(self):
127+
project = QgsProject()
128+
manager = QgsLayoutManager(project)
129+
layout = QgsLayout(project)
130+
layout.setName('test layout')
131+
layout2 = QgsLayout(project)
132+
layout2.setName('test layout2')
133+
layout3 = QgsLayout(project)
134+
layout3.setName('test layout3')
135+
136+
manager.addLayout(layout)
137+
self.assertEqual(manager.layouts(), [layout])
138+
manager.addLayout(layout2)
139+
self.assertEqual(set(manager.layouts()), {layout, layout2})
140+
manager.addLayout(layout3)
141+
self.assertEqual(set(manager.layouts()), {layout, layout2, layout3})
142+
93143
def aboutToBeRemoved(self, name):
94144
# composition should still exist at this time
95145
self.assertEqual(name, 'test composition')
@@ -123,6 +173,39 @@ def testRemoveComposition(self):
123173
self.assertTrue(self.aboutFired)
124174
self.manager = None
125175

176+
def layoutAboutToBeRemoved(self, name):
177+
# layout should still exist at this time
178+
self.assertEqual(name, 'test layout')
179+
self.assertTrue(self.manager.layoutByName('test layout'))
180+
self.aboutFired = True
181+
182+
def testRemoveLayout(self):
183+
project = QgsProject()
184+
layout = QgsLayout(project)
185+
layout.setName('test layout')
186+
187+
self.manager = QgsLayoutManager(project)
188+
layout_removed_spy = QSignalSpy(self.manager.layoutRemoved)
189+
layout_about_to_be_removed_spy = QSignalSpy(self.manager.layoutAboutToBeRemoved)
190+
# tests that layout still exists when layoutAboutToBeRemoved is fired
191+
self.manager.layoutAboutToBeRemoved.connect(self.layoutAboutToBeRemoved)
192+
193+
# not added, should fail
194+
self.assertFalse(self.manager.removeLayout(layout))
195+
self.assertEqual(len(layout_removed_spy), 0)
196+
self.assertEqual(len(layout_about_to_be_removed_spy), 0)
197+
198+
self.assertTrue(self.manager.addLayout(layout))
199+
self.assertEqual(self.manager.layouts(), [layout])
200+
self.assertTrue(self.manager.removeLayout(layout))
201+
self.assertEqual(len(self.manager.layouts()), 0)
202+
self.assertEqual(len(layout_removed_spy), 1)
203+
self.assertEqual(layout_removed_spy[0][0], 'test layout')
204+
self.assertEqual(len(layout_about_to_be_removed_spy), 1)
205+
self.assertEqual(layout_about_to_be_removed_spy[0][0], 'test layout')
206+
self.assertTrue(self.aboutFired)
207+
self.manager = None
208+
126209
def testClear(self):
127210
project = QgsProject()
128211
manager = QgsLayoutManager(project)
@@ -134,17 +217,32 @@ def testClear(self):
134217
composition2.setName('test composition2')
135218
composition3 = QgsComposition(project)
136219
composition3.setName('test composition3')
220+
# add a bunch of layouts
221+
layout = QgsLayout(project)
222+
layout.setName('test layout')
223+
layout2 = QgsLayout(project)
224+
layout2.setName('test layout2')
225+
layout3 = QgsLayout(project)
226+
layout3.setName('test layout3')
137227

138228
manager.addComposition(composition)
139229
manager.addComposition(composition2)
140230
manager.addComposition(composition3)
231+
manager.addLayout(layout)
232+
manager.addLayout(layout2)
233+
manager.addLayout(layout3)
141234

142235
composition_removed_spy = QSignalSpy(manager.compositionRemoved)
143236
composition_about_to_be_removed_spy = QSignalSpy(manager.compositionAboutToBeRemoved)
237+
layout_removed_spy = QSignalSpy(manager.layoutRemoved)
238+
layout_about_to_be_removed_spy = QSignalSpy(manager.layoutAboutToBeRemoved)
144239
manager.clear()
145240
self.assertEqual(len(manager.compositions()), 0)
146241
self.assertEqual(len(composition_removed_spy), 3)
147242
self.assertEqual(len(composition_about_to_be_removed_spy), 3)
243+
self.assertEqual(len(manager.layouts()), 0)
244+
self.assertEqual(len(layout_removed_spy), 3)
245+
self.assertEqual(len(layout_about_to_be_removed_spy), 3)
148246

149247
def testCompositionByName(self):
150248
project = QgsProject()
@@ -167,6 +265,27 @@ def testCompositionByName(self):
167265
self.assertEqual(manager.compositionByName('test composition2'), composition2)
168266
self.assertEqual(manager.compositionByName('test composition3'), composition3)
169267

268+
def testLayoutsByName(self):
269+
project = QgsProject()
270+
manager = QgsLayoutManager(project)
271+
272+
# add a bunch of layouts
273+
layout = QgsLayout(project)
274+
layout.setName('test layout')
275+
layout2 = QgsLayout(project)
276+
layout2.setName('test layout2')
277+
layout3 = QgsLayout(project)
278+
layout3.setName('test layout3')
279+
280+
manager.addLayout(layout)
281+
manager.addLayout(layout2)
282+
manager.addLayout(layout3)
283+
284+
self.assertFalse(manager.layoutByName('asdf'))
285+
self.assertEqual(manager.layoutByName('test layout'), layout)
286+
self.assertEqual(manager.layoutByName('test layout2'), layout2)
287+
self.assertEqual(manager.layoutByName('test layout3'), layout3)
288+
170289
def testReadWriteXml(self):
171290
"""
172291
Test reading and writing layout manager state to XML
@@ -241,22 +360,22 @@ def testDuplicateComposition(self):
241360
def testGenerateUniqueTitle(self):
242361
project = QgsProject()
243362
manager = QgsLayoutManager(project)
244-
self.assertEqual(manager.generateUniqueTitle(), 'Composer 1')
363+
self.assertEqual(manager.generateUniqueTitle(), 'Layout 1')
245364

246-
composition = QgsComposition(project)
247-
composition.setName(manager.generateUniqueTitle())
248-
manager.addComposition(composition)
365+
layout = QgsLayout(project)
366+
layout.setName(manager.generateUniqueTitle())
367+
manager.addLayout(layout)
249368

250-
self.assertEqual(manager.generateUniqueTitle(), 'Composer 2')
251-
composition2 = QgsComposition(project)
252-
composition2.setName(manager.generateUniqueTitle())
253-
manager.addComposition(composition2)
369+
self.assertEqual(manager.generateUniqueTitle(), 'Layout 2')
370+
layout2 = QgsLayout(project)
371+
layout2.setName(manager.generateUniqueTitle())
372+
manager.addLayout(layout2)
254373

255-
self.assertEqual(manager.generateUniqueTitle(), 'Composer 3')
374+
self.assertEqual(manager.generateUniqueTitle(), 'Layout 3')
256375
manager.clear()
257-
self.assertEqual(manager.generateUniqueTitle(), 'Composer 1')
376+
self.assertEqual(manager.generateUniqueTitle(), 'Layout 1')
258377

259-
def testRenameSignal(self):
378+
def testRenameSignalCompositions(self):
260379
project = QgsProject()
261380
manager = QgsLayoutManager(project)
262381
composition = QgsComposition(project)
@@ -276,6 +395,25 @@ def testRenameSignal(self):
276395
self.assertEqual(composition_renamed_spy[1][0], composition2)
277396
self.assertEqual(composition_renamed_spy[1][1], 'd2')
278397

398+
def testRenameSignal(self):
399+
project = QgsProject()
400+
manager = QgsLayoutManager(project)
401+
layout = QgsLayout(project)
402+
layout.setName('c1')
403+
manager.addLayout(layout)
404+
layout2 = QgsLayout(project)
405+
layout2.setName('c2')
406+
manager.addLayout(layout2)
407+
408+
layout_renamed_spy = QSignalSpy(manager.layoutRenamed)
409+
layout.setName('d1')
410+
self.assertEqual(len(layout_renamed_spy), 1)
411+
#self.assertEqual(layout_renamed_spy[0][0], layout)
412+
self.assertEqual(layout_renamed_spy[0][1], 'd1')
413+
layout2.setName('d2')
414+
self.assertEqual(len(layout_renamed_spy), 2)
415+
#self.assertEqual(layout_renamed_spy[1][0], layout2)
416+
self.assertEqual(layout_renamed_spy[1][1], 'd2')
279417

280418
if __name__ == '__main__':
281419
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.