2424QgsLayoutPageCollection::QgsLayoutPageCollection ( QgsLayout *layout )
2525 : QObject( layout )
2626 , mLayout( layout )
27+ , mGuideCollection( new QgsLayoutGuideCollection( layout, this ) )
2728{
2829 createDefaultPageStyleSymbol ();
2930}
@@ -151,6 +152,8 @@ bool QgsLayoutPageCollection::writeXml( QDomElement &parentElement, QDomDocument
151152 page->writeXml ( element, document, context );
152153 }
153154
155+ mGuideCollection ->writeXml ( element, document, context );
156+
154157 parentElement.appendChild ( element );
155158 return true ;
156159}
@@ -168,6 +171,8 @@ bool QgsLayoutPageCollection::readXml( const QDomElement &e, const QDomDocument
168171 return false ;
169172 }
170173
174+ mBlockUndoCommands = true ;
175+
171176 int i = 0 ;
172177 for ( QgsLayoutItemPage *page : qgsAsConst ( mPages ) )
173178 {
@@ -195,9 +200,23 @@ bool QgsLayoutPageCollection::readXml( const QDomElement &e, const QDomDocument
195200 }
196201
197202 reflow ();
203+
204+ mGuideCollection ->readXml ( element, document, context );
205+
206+ mBlockUndoCommands = false ;
198207 return true ;
199208}
200209
210+ QgsLayoutGuideCollection &QgsLayoutPageCollection::guides ()
211+ {
212+ return *mGuideCollection ;
213+ }
214+
215+ const QgsLayoutGuideCollection &QgsLayoutPageCollection::guides () const
216+ {
217+ return *mGuideCollection ;
218+ }
219+
201220void QgsLayoutPageCollection::redraw ()
202221{
203222 Q_FOREACH ( QgsLayoutItemPage *page, mPages )
@@ -257,16 +276,19 @@ QList<int> QgsLayoutPageCollection::visiblePageNumbers( QRectF region ) const
257276
258277void QgsLayoutPageCollection::addPage ( QgsLayoutItemPage *page )
259278{
260- mLayout ->undoStack ()->beginCommand ( this , tr ( " Add page" ) );
279+ if ( !mBlockUndoCommands )
280+ mLayout ->undoStack ()->beginCommand ( this , tr ( " Add page" ) );
261281 mPages .append ( page );
262282 mLayout ->addItem ( page );
263283 reflow ();
264- mLayout ->undoStack ()->endCommand ();
284+ if ( !mBlockUndoCommands )
285+ mLayout ->undoStack ()->endCommand ();
265286}
266287
267288void QgsLayoutPageCollection::insertPage ( QgsLayoutItemPage *page, int beforePage )
268289{
269- mLayout ->undoStack ()->beginCommand ( this , tr ( " Add page" ) );
290+ if ( !mBlockUndoCommands )
291+ mLayout ->undoStack ()->beginCommand ( this , tr ( " Add page" ) );
270292
271293 if ( beforePage < 0 )
272294 beforePage = 0 ;
@@ -281,83 +303,51 @@ void QgsLayoutPageCollection::insertPage( QgsLayoutItemPage *page, int beforePag
281303 }
282304 mLayout ->addItem ( page );
283305 reflow ();
284- mLayout ->undoStack ()->endCommand ();
306+ if ( ! mBlockUndoCommands )
307+ mLayout ->undoStack ()->endCommand ();
285308}
286309
287- // /@cond PRIVATE
288-
289- class QgsLayoutItemDeletePageUndoCommand : public QgsLayoutItemDeleteUndoCommand
290- {
291- public:
292-
293- QgsLayoutItemDeletePageUndoCommand ( QgsLayoutItemPage *page, const QString &text, int id = 0 , QUndoCommand *parent SIP_TRANSFERTHIS = nullptr )
294- : QgsLayoutItemDeleteUndoCommand( page, text, id, parent )
295- {}
296-
297- void redo () override
298- {
299- if ( mFirstRun )
300- {
301- mFirstRun = false ;
302- return ;
303- }
304-
305- // remove from page collection
306- QgsLayoutItemPage *page = dynamic_cast < QgsLayoutItemPage *>( layout ()->itemByUuid ( itemUuid () ) );
307- layout ()->pageCollection ()->takePage ( page );
308-
309- QgsLayoutItemDeleteUndoCommand::redo ();
310- layout ()->pageCollection ()->reflow ();
311- }
312-
313- void undo () override
314- {
315- QgsLayoutItemDeleteUndoCommand::undo ();
316- layout ()->pageCollection ()->reflow ();
317- }
318-
319- QgsLayoutItem *recreateItem ( int , QgsLayout *layout ) override
320- {
321- QgsLayoutItemPage *page = new QgsLayoutItemPage ( layout );
322- layout->pageCollection ()->addPage ( page );
323- return page;
324- }
325-
326- };
327-
328- // /@endcond
329-
330310void QgsLayoutPageCollection::deletePage ( int pageNumber )
331311{
332312 if ( pageNumber < 0 || pageNumber >= mPages .count () )
333313 return ;
334314
335- mLayout ->undoStack ()->beginMacro ( tr ( " Remove page" ) );
336- mLayout ->undoStack ()->beginCommand ( this , tr ( " Remove page" ) );
315+ if ( !mBlockUndoCommands )
316+ {
317+ mLayout ->undoStack ()->beginMacro ( tr ( " Remove page" ) );
318+ mLayout ->undoStack ()->beginCommand ( this , tr ( " Remove page" ) );
319+ }
337320 emit pageAboutToBeRemoved ( pageNumber );
338321 QgsLayoutItemPage *page = mPages .takeAt ( pageNumber );
339- // mLayout->undoStack()->stack()->push( new QgsLayoutItemDeletePageUndoCommand( page, tr( "Remove page" ) ) );
340322 mLayout ->removeItem ( page );
341323 page->deleteLater ();
342324 reflow ();
343- mLayout ->undoStack ()->endCommand ();
344- mLayout ->undoStack ()->endMacro ();
325+ if ( ! mBlockUndoCommands )
326+ {
327+ mLayout ->undoStack ()->endCommand ();
328+ mLayout ->undoStack ()->endMacro ();
329+ }
345330}
346331
347332void QgsLayoutPageCollection::deletePage ( QgsLayoutItemPage *page )
348333{
349334 if ( !mPages .contains ( page ) )
350335 return ;
351336
352- mLayout ->undoStack ()->beginMacro ( tr ( " Remove page" ) );
353- mLayout ->undoStack ()->beginCommand ( this , tr ( " Remove page" ) );
337+ if ( !mBlockUndoCommands )
338+ {
339+ mLayout ->undoStack ()->beginMacro ( tr ( " Remove page" ) );
340+ mLayout ->undoStack ()->beginCommand ( this , tr ( " Remove page" ) );
341+ }
354342 emit pageAboutToBeRemoved ( mPages .indexOf ( page ) );
355- // mLayout->undoStack()->stack()->push( new QgsLayoutItemDeletePageUndoCommand( page, tr( "Remove page" ) ) );
356343 mPages .removeAll ( page );
357344 page->deleteLater ();
358345 reflow ();
359- mLayout ->undoStack ()->endCommand ();
360- mLayout ->undoStack ()->endMacro ();
346+ if ( !mBlockUndoCommands )
347+ {
348+ mLayout ->undoStack ()->endCommand ();
349+ mLayout ->undoStack ()->endMacro ();
350+ }
361351}
362352
363353QgsLayoutItemPage *QgsLayoutPageCollection::takePage ( QgsLayoutItemPage *page )
0 commit comments