16
16
17
17
from qgis .PyQt .QtXml import QDomDocument
18
18
19
- from qgis .core import (QgsComposition ,
20
- QgsPrintLayout ,
19
+ from qgis .core import (QgsPrintLayout ,
21
20
QgsLayoutManager ,
22
21
QgsProject ,
23
22
QgsReport ,
@@ -43,38 +42,6 @@ def tearDown(self):
43
42
"""Run after each test."""
44
43
pass
45
44
46
- def testAddComposition (self ):
47
- project = QgsProject ()
48
- composition = QgsComposition (project )
49
- composition .setName ('test composition' )
50
-
51
- manager = QgsLayoutManager (project )
52
-
53
- composition_about_to_be_added_spy = QSignalSpy (manager .compositionAboutToBeAdded )
54
- composition_added_spy = QSignalSpy (manager .compositionAdded )
55
- self .assertTrue (manager .addComposition (composition ))
56
- self .assertEqual (len (composition_about_to_be_added_spy ), 1 )
57
- self .assertEqual (composition_about_to_be_added_spy [0 ][0 ], 'test composition' )
58
- self .assertEqual (len (composition_added_spy ), 1 )
59
- self .assertEqual (composition_added_spy [0 ][0 ], 'test composition' )
60
-
61
- # adding it again should fail
62
- self .assertFalse (manager .addComposition (composition ))
63
-
64
- # try adding a second composition
65
- composition2 = QgsComposition (project )
66
- composition2 .setName ('test composition2' )
67
- self .assertTrue (manager .addComposition (composition2 ))
68
- self .assertEqual (len (composition_added_spy ), 2 )
69
- self .assertEqual (composition_about_to_be_added_spy [1 ][0 ], 'test composition2' )
70
- self .assertEqual (len (composition_about_to_be_added_spy ), 2 )
71
- self .assertEqual (composition_added_spy [1 ][0 ], 'test composition2' )
72
-
73
- # adding a composition with duplicate name should fail
74
- composition3 = QgsComposition (project )
75
- composition3 .setName ('test composition2' )
76
- self .assertFalse (manager .addComposition (composition3 ))
77
-
78
45
def testAddLayout (self ):
79
46
project = QgsProject ()
80
47
layout = QgsPrintLayout (project )
@@ -107,23 +74,6 @@ def testAddLayout(self):
107
74
layout3 .setName ('test layout2' )
108
75
self .assertFalse (manager .addLayout (layout3 ))
109
76
110
- def testCompositions (self ):
111
- project = QgsProject ()
112
- manager = QgsLayoutManager (project )
113
- composition = QgsComposition (project )
114
- composition .setName ('test composition' )
115
- composition2 = QgsComposition (project )
116
- composition2 .setName ('test composition2' )
117
- composition3 = QgsComposition (project )
118
- composition3 .setName ('test composition3' )
119
-
120
- manager .addComposition (composition )
121
- self .assertEqual (manager .compositions (), [composition ])
122
- manager .addComposition (composition2 )
123
- self .assertEqual (set (manager .compositions ()), {composition , composition2 })
124
- manager .addComposition (composition3 )
125
- self .assertEqual (set (manager .compositions ()), {composition , composition2 , composition3 })
126
-
127
77
def testLayouts (self ):
128
78
project = QgsProject ()
129
79
manager = QgsLayoutManager (project )
@@ -147,33 +97,6 @@ def aboutToBeRemoved(self, name):
147
97
self .assertTrue (self .manager .compositionByName ('test composition' ))
148
98
self .aboutFired = True
149
99
150
- def testRemoveComposition (self ):
151
- project = QgsProject ()
152
- composition = QgsComposition (project )
153
- composition .setName ('test composition' )
154
-
155
- self .manager = QgsLayoutManager (project )
156
- composition_removed_spy = QSignalSpy (self .manager .compositionRemoved )
157
- composition_about_to_be_removed_spy = QSignalSpy (self .manager .compositionAboutToBeRemoved )
158
- # tests that composition still exists when compositionAboutToBeRemoved is fired
159
- self .manager .compositionAboutToBeRemoved .connect (self .aboutToBeRemoved )
160
-
161
- # not added, should fail
162
- self .assertFalse (self .manager .removeComposition (composition ))
163
- self .assertEqual (len (composition_removed_spy ), 0 )
164
- self .assertEqual (len (composition_about_to_be_removed_spy ), 0 )
165
-
166
- self .assertTrue (self .manager .addComposition (composition ))
167
- self .assertEqual (self .manager .compositions (), [composition ])
168
- self .assertTrue (self .manager .removeComposition (composition ))
169
- self .assertEqual (len (self .manager .compositions ()), 0 )
170
- self .assertEqual (len (composition_removed_spy ), 1 )
171
- self .assertEqual (composition_removed_spy [0 ][0 ], 'test composition' )
172
- self .assertEqual (len (composition_about_to_be_removed_spy ), 1 )
173
- self .assertEqual (composition_about_to_be_removed_spy [0 ][0 ], 'test composition' )
174
- self .assertTrue (self .aboutFired )
175
- self .manager = None
176
-
177
100
def layoutAboutToBeRemoved (self , name ):
178
101
# layout should still exist at this time
179
102
self .assertEqual (name , 'test layout' )
@@ -211,13 +134,6 @@ def testClear(self):
211
134
project = QgsProject ()
212
135
manager = QgsLayoutManager (project )
213
136
214
- # add a bunch of compositions
215
- composition = QgsComposition (project )
216
- composition .setName ('test composition' )
217
- composition2 = QgsComposition (project )
218
- composition2 .setName ('test composition2' )
219
- composition3 = QgsComposition (project )
220
- composition3 .setName ('test composition3' )
221
137
# add a bunch of layouts
222
138
layout = QgsPrintLayout (project )
223
139
layout .setName ('test layout' )
@@ -226,46 +142,17 @@ def testClear(self):
226
142
layout3 = QgsPrintLayout (project )
227
143
layout3 .setName ('test layout3' )
228
144
229
- manager .addComposition (composition )
230
- manager .addComposition (composition2 )
231
- manager .addComposition (composition3 )
232
145
manager .addLayout (layout )
233
146
manager .addLayout (layout2 )
234
147
manager .addLayout (layout3 )
235
148
236
- composition_removed_spy = QSignalSpy (manager .compositionRemoved )
237
- composition_about_to_be_removed_spy = QSignalSpy (manager .compositionAboutToBeRemoved )
238
149
layout_removed_spy = QSignalSpy (manager .layoutRemoved )
239
150
layout_about_to_be_removed_spy = QSignalSpy (manager .layoutAboutToBeRemoved )
240
151
manager .clear ()
241
- self .assertEqual (len (manager .compositions ()), 0 )
242
- self .assertEqual (len (composition_removed_spy ), 3 )
243
- self .assertEqual (len (composition_about_to_be_removed_spy ), 3 )
244
152
self .assertEqual (len (manager .layouts ()), 0 )
245
153
self .assertEqual (len (layout_removed_spy ), 3 )
246
154
self .assertEqual (len (layout_about_to_be_removed_spy ), 3 )
247
155
248
- def testCompositionByName (self ):
249
- project = QgsProject ()
250
- manager = QgsLayoutManager (project )
251
-
252
- # add a bunch of compositions
253
- composition = QgsComposition (project )
254
- composition .setName ('test composition' )
255
- composition2 = QgsComposition (project )
256
- composition2 .setName ('test composition2' )
257
- composition3 = QgsComposition (project )
258
- composition3 .setName ('test composition3' )
259
-
260
- manager .addComposition (composition )
261
- manager .addComposition (composition2 )
262
- manager .addComposition (composition3 )
263
-
264
- self .assertFalse (manager .compositionByName ('asdf' ))
265
- self .assertEqual (manager .compositionByName ('test composition' ), composition )
266
- self .assertEqual (manager .compositionByName ('test composition2' ), composition2 )
267
- self .assertEqual (manager .compositionByName ('test composition3' ), composition3 )
268
-
269
156
def testLayoutsByName (self ):
270
157
project = QgsProject ()
271
158
manager = QgsLayoutManager (project )
@@ -294,18 +181,6 @@ def testReadWriteXml(self):
294
181
project = QgsProject ()
295
182
manager = QgsLayoutManager (project )
296
183
297
- # add a bunch of compositions
298
- composition = QgsComposition (project )
299
- composition .setName ('test composition' )
300
- composition2 = QgsComposition (project )
301
- composition2 .setName ('test composition2' )
302
- composition3 = QgsComposition (project )
303
- composition3 .setName ('test composition3' )
304
-
305
- manager .addComposition (composition )
306
- manager .addComposition (composition2 )
307
- manager .addComposition (composition3 )
308
-
309
184
# add a bunch of layouts
310
185
layout = QgsPrintLayout (project )
311
186
layout .setName ('test layout' )
@@ -328,51 +203,32 @@ def testReadWriteXml(self):
328
203
manager2 = QgsLayoutManager (project2 )
329
204
self .assertTrue (manager2 .readXml (elem , doc ))
330
205
331
- self .assertEqual (len (manager2 .compositions ()), 3 )
332
- names = [c .name () for c in manager2 .compositions ()]
333
- self .assertEqual (set (names ), {'test composition' , 'test composition2' , 'test composition3' })
334
-
335
206
self .assertEqual (len (manager2 .layouts ()), 3 )
336
207
names = [c .name () for c in manager2 .layouts ()]
337
208
self .assertCountEqual (names , ['test layout' , 'test layout2' , 'test layout3' ])
338
209
339
- def testSaveAsTemplate (self ):
340
- """
341
- Test saving composition as template
342
- """
343
- project = QgsProject ()
344
- manager = QgsLayoutManager (project )
345
- doc = QDomDocument ("testdoc" )
346
- self .assertFalse (manager .saveAsTemplate ('not in manager' , doc ))
347
-
348
- composition = QgsComposition (project )
349
- composition .setName ('test composition' )
350
- manager .addComposition (composition )
351
- self .assertTrue (manager .saveAsTemplate ('test composition' , doc ))
352
-
353
- def testDuplicateComposition (self ):
210
+ def testDuplicateLayout (self ):
354
211
"""
355
- Test duplicating compositions
212
+ Test duplicating layouts
356
213
"""
357
214
project = QgsProject ()
358
215
manager = QgsLayoutManager (project )
359
216
doc = QDomDocument ("testdoc" )
360
- self .assertFalse (manager .duplicateComposition ( 'not in manager' , 'dest' ))
217
+ self .assertFalse (manager .duplicateLayout ( None , 'dest' ))
361
218
362
- composition = QgsComposition (project )
363
- composition .setName ('test composition ' )
364
- composition . setPaperSize ( 100 , 200 )
365
- manager .addComposition ( composition )
219
+ layout = QgsPrintLayout (project )
220
+ layout .setName ('test layout ' )
221
+ layout . initializeDefaults ( )
222
+ manager .addLayout ( layout )
366
223
# duplicate name
367
- self .assertFalse (manager .duplicateComposition ('test composition' , 'test composition' ))
224
+ self .assertFalse (manager .duplicateLayout (layout , 'test layout' ))
225
+ result = manager .duplicateLayout (layout , 'dupe layout' )
368
226
369
- result = manager .duplicateComposition ('test composition' , 'dupe composition' )
370
227
self .assertTrue (result )
371
228
# make sure result in stored in manager
372
- self .assertEqual (result , manager .compositionByName ('dupe composition' ))
373
- self .assertEqual (result .name (), 'dupe composition' )
374
- self .assertEqual (result .paperHeight (), 200 )
375
- self .assertEqual (result .paperWidth (), 100 )
229
+ self .assertEqual (result , manager .layoutByName ('dupe layout' ))
230
+ self .assertEqual (result .name (), 'dupe layout' )
231
+ self .assertEqual (result .pageCollection ().pageCount (), 1 )
376
232
377
233
def testGenerateUniqueTitle (self ):
378
234
project = QgsProject ()
@@ -401,26 +257,6 @@ def testGenerateUniqueTitle(self):
401
257
self .assertEqual (manager .generateUniqueTitle (), 'Layout 1' )
402
258
self .assertEqual (manager .generateUniqueTitle (QgsMasterLayoutInterface .Report ), 'Report 1' )
403
259
404
- def testRenameSignalCompositions (self ):
405
- project = QgsProject ()
406
- manager = QgsLayoutManager (project )
407
- composition = QgsComposition (project )
408
- composition .setName ('c1' )
409
- manager .addComposition (composition )
410
- composition2 = QgsComposition (project )
411
- composition2 .setName ('c2' )
412
- manager .addComposition (composition2 )
413
-
414
- composition_renamed_spy = QSignalSpy (manager .compositionRenamed )
415
- composition .setName ('d1' )
416
- self .assertEqual (len (composition_renamed_spy ), 1 )
417
- self .assertEqual (composition_renamed_spy [0 ][0 ], composition )
418
- self .assertEqual (composition_renamed_spy [0 ][1 ], 'd1' )
419
- composition2 .setName ('d2' )
420
- self .assertEqual (len (composition_renamed_spy ), 2 )
421
- self .assertEqual (composition_renamed_spy [1 ][0 ], composition2 )
422
- self .assertEqual (composition_renamed_spy [1 ][1 ], 'd2' )
423
-
424
260
def testRenameSignal (self ):
425
261
project = QgsProject ()
426
262
manager = QgsLayoutManager (project )
0 commit comments