Skip to content

Commit 2cf9911

Browse files
committed
Resurrect tests for html item
1 parent aec0326 commit 2cf9911

File tree

15 files changed

+333
-9
lines changed

15 files changed

+333
-9
lines changed

src/core/layout/qgslayout.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "qgslayoutitemundocommand.h"
2525
#include "qgslayoutitemgroup.h"
2626
#include "qgslayoutitemgroupundocommand.h"
27+
#include "qgslayoutmultiframe.h"
2728

2829
QgsLayout::QgsLayout( QgsProject *project )
2930
: mProject( project )
@@ -41,7 +42,7 @@ QgsLayout::QgsLayout( QgsProject *project )
4142
QgsLayout::~QgsLayout()
4243
{
4344
// no need for undo commands when we're destroying the layout
44-
mBlockUndoCommands = true;
45+
mBlockUndoCommandCount++;
4546

4647
deleteAndRemoveMultiFrames();
4748

@@ -402,7 +403,7 @@ void QgsLayout::addLayoutItem( QgsLayoutItem *item )
402403
void QgsLayout::removeLayoutItem( QgsLayoutItem *item )
403404
{
404405
std::unique_ptr< QgsLayoutItemDeleteUndoCommand > deleteCommand;
405-
if ( !mBlockUndoCommands )
406+
if ( mBlockUndoCommandCount == 0 )
406407
{
407408
mUndoStack->beginMacro( tr( "Delete Items" ) );
408409
deleteCommand.reset( new QgsLayoutItemDeleteUndoCommand( item, tr( "Delete Item" ) ) );

src/core/layout/qgslayout.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
551551
std::unique_ptr< QgsLayoutUndoStack > mUndoStack;
552552
QgsLayoutExporter mExporter;
553553

554-
bool mBlockUndoCommands = false;
554+
int mBlockUndoCommandCount = 0;
555555

556556
//! List of multiframe objects
557557
QSet<QgsLayoutMultiFrame *> mMultiFrames;
@@ -579,6 +579,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
579579
friend class QgsLayoutUndoCommand;
580580
friend class QgsLayoutItemGroupUndoCommand;
581581
friend class QgsLayoutModel;
582+
friend class QgsLayoutMultiFrame;
582583
};
583584

584585
#endif //QGSLAYOUT_H

src/core/layout/qgslayoutmultiframe.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void QgsLayoutMultiFrame::recalculateFrameSizes()
141141
while ( ( mResizeMode == RepeatOnEveryPage ) || currentY < totalHeight )
142142
{
143143
//find out on which page the lower left point of the last frame is
144-
int page = mLayout->pageCollection()->predictPageNumberForPoint( QPointF( 0, currentItem->pos().y() + currentItem->rect().height() ) );
144+
int page = mLayout->pageCollection()->predictPageNumberForPoint( QPointF( 0, currentItem->pos().y() + currentItem->rect().height() ) ) + 1;
145145

146146
if ( mResizeMode == RepeatOnEveryPage )
147147
{
@@ -343,14 +343,14 @@ void QgsLayoutMultiFrame::removeFrame( int i, const bool removeEmptyPages )
343343
mIsRecalculatingSize = true;
344344
int pageNumber = frameItem->page();
345345
//remove item, but don't create undo command
346-
#if 0 //TODO - block undo commands
347-
#endif
346+
mLayout->mBlockUndoCommandCount++;
348347
mLayout->removeLayoutItem( frameItem );
349348
//if frame was the only item on the page, remove the page
350349
if ( removeEmptyPages && mLayout->pageCollection()->pageIsEmpty( pageNumber ) )
351350
{
352351
mLayout->pageCollection()->deletePage( pageNumber );
353352
}
353+
mLayout->mBlockUndoCommandCount--;
354354
mIsRecalculatingSize = false;
355355
}
356356
mFrameItems.removeAt( i );
@@ -369,12 +369,12 @@ void QgsLayoutMultiFrame::deleteFrames()
369369
mBlockUpdates = true;
370370
ResizeMode bkResizeMode = mResizeMode;
371371
mResizeMode = UseExistingFrames;
372+
mLayout->mBlockUndoCommandCount++;
372373
for ( QgsLayoutFrame *frame : qgis::as_const( mFrameItems ) )
373374
{
374-
#if 0 //TODO -block undo commands
375-
#endif
376375
mLayout->removeLayoutItem( frame );
377376
}
377+
mLayout->mBlockUndoCommandCount--;
378378
mFrameItems.clear();
379379
mResizeMode = bkResizeMode;
380380
mBlockUpdates = false;

tests/src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ SET(TESTS
133133
testqgslayertree.cpp
134134
testqgslayout.cpp
135135
testqgslayoutcontext.cpp
136+
testqgslayouthtml.cpp
136137
testqgslayoutitem.cpp
137138
testqgslayoutitemgroup.cpp
138139
testqgslayoutlabel.cpp

0 commit comments

Comments
 (0)