Skip to content

Commit cf7714b

Browse files
committedNov 7, 2017
Restore tests, add button to set page background in ui
1 parent 4a1bcb3 commit cf7714b

File tree

11 files changed

+122
-22
lines changed

11 files changed

+122
-22
lines changed
 

‎python/core/layout/qgslayoutitempage.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class QgsLayoutItemPage : QgsLayoutItem
2828
Landscape
2929
};
3030

31+
enum UndoCommand
32+
{
33+
UndoPageSymbol,
34+
};
35+
3136
explicit QgsLayoutItemPage( QgsLayout *layout /TransferThis/ );
3237
%Docstring
3338
Constructor for QgsLayoutItemPage, with the specified parent ``layout``.

‎src/app/layout/qgslayoutpagepropertieswidget.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
4747
mLockAspectRatio->setWidthSpinBox( mWidthSpin );
4848
mLockAspectRatio->setHeightSpinBox( mHeightSpin );
4949

50+
mSymbolButton->setSymbolType( QgsSymbol::Fill );
51+
mSymbolButton->setSymbol( mPage->layout()->pageCollection()->pageStyleSymbol()->clone() );
52+
5053
connect( mPageSizeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutPagePropertiesWidget::pageSizeChanged );
5154
connect( mPageOrientationComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutPagePropertiesWidget::orientationChanged );
5255

@@ -55,6 +58,7 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
5558
connect( mWidthSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
5659
connect( mHeightSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
5760

61+
connect( mSymbolButton, &QgsSymbolButton::changed, this, &QgsLayoutPagePropertiesWidget::symbolChanged );
5862
registerDataDefinedButton( mPaperSizeDDBtn, QgsLayoutObject::PresetPaperSize );
5963
registerDataDefinedButton( mWidthDDBtn, QgsLayoutObject::ItemWidth );
6064
registerDataDefinedButton( mHeightDDBtn, QgsLayoutObject::ItemHeight );
@@ -142,6 +146,13 @@ void QgsLayoutPagePropertiesWidget::setToCustomSize()
142146
mPageOrientationComboBox->setEnabled( false );
143147
}
144148

149+
void QgsLayoutPagePropertiesWidget::symbolChanged()
150+
{
151+
mPage->layout()->undoStack()->beginCommand( mPage->layout()->pageCollection(), tr( "Change Page Background" ), QgsLayoutItemPage::UndoPageSymbol );
152+
mPage->layout()->pageCollection()->setPageStyleSymbol( static_cast< QgsFillSymbol * >( mSymbolButton->symbol() )->clone() );
153+
mPage->layout()->undoStack()->endCommand();
154+
}
155+
145156
void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
146157
{
147158
QgsLayoutSize paperSize = mPage->pageSize();

‎src/app/layout/qgslayoutpagepropertieswidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QgsLayoutPagePropertiesWidget : public QgsLayoutItemBaseWidget, private Ui
4747
void orientationChanged( int index );
4848
void updatePageSize();
4949
void setToCustomSize();
50+
void symbolChanged();
5051

5152
private:
5253

‎src/core/layout/qgslayoutitempage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ class CORE_EXPORT QgsLayoutItemPage : public QgsLayoutItem
6565
Landscape //!< Landscape orientation
6666
};
6767

68+
//! Page item undo commands, used for collapsing undo commands
69+
enum UndoCommand
70+
{
71+
UndoPageSymbol = 3000, //!< Layout page symbol change
72+
};
73+
6874
/**
6975
* Constructor for QgsLayoutItemPage, with the specified parent \a layout.
7076
*/

‎src/core/layout/qgslayoutpagecollection.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ void QgsLayoutPageCollection::setPageStyleSymbol( QgsFillSymbol *symbol )
4444
return;
4545

4646
mPageStyleSymbol.reset( static_cast<QgsFillSymbol *>( symbol->clone() ) );
47+
48+
for ( QgsLayoutItemPage *page : qgis::as_const( mPages ) )
49+
{
50+
page->update();
51+
}
52+
4753
}
4854

4955
void QgsLayoutPageCollection::reflow()

‎src/ui/layout/qgslayoutpagepropertieswidget.ui

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>660</width>
10-
<height>368</height>
9+
<width>397</width>
10+
<height>409</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>New Item Properties</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout_2">
17-
<item row="3" column="1">
16+
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,1">
17+
<item row="3" column="0">
1818
<spacer name="verticalSpacer">
1919
<property name="orientation">
2020
<enum>Qt::Vertical</enum>
@@ -27,7 +27,36 @@
2727
</property>
2828
</spacer>
2929
</item>
30-
<item row="2" column="0" colspan="3">
30+
<item row="2" column="0">
31+
<widget class="QLabel" name="label">
32+
<property name="text">
33+
<string>Background</string>
34+
</property>
35+
</widget>
36+
</item>
37+
<item row="2" column="1">
38+
<widget class="QgsSymbolButton" name="mSymbolButton">
39+
<property name="enabled">
40+
<bool>true</bool>
41+
</property>
42+
<property name="sizePolicy">
43+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
44+
<horstretch>0</horstretch>
45+
<verstretch>0</verstretch>
46+
</sizepolicy>
47+
</property>
48+
<property name="minimumSize">
49+
<size>
50+
<width>100</width>
51+
<height>0</height>
52+
</size>
53+
</property>
54+
<property name="text">
55+
<string/>
56+
</property>
57+
</widget>
58+
</item>
59+
<item row="0" column="0" colspan="2">
3160
<widget class="QGroupBox" name="groupBox">
3261
<property name="title">
3362
<string>Page size</string>
@@ -178,26 +207,31 @@
178207
</layout>
179208
</widget>
180209
<customwidgets>
210+
<customwidget>
211+
<class>QgsDoubleSpinBox</class>
212+
<extends>QDoubleSpinBox</extends>
213+
<header>qgsdoublespinbox.h</header>
214+
</customwidget>
215+
<customwidget>
216+
<class>QgsPropertyOverrideButton</class>
217+
<extends>QToolButton</extends>
218+
<header>qgspropertyoverridebutton.h</header>
219+
</customwidget>
181220
<customwidget>
182221
<class>QgsRatioLockButton</class>
183222
<extends>QToolButton</extends>
184223
<header>qgsratiolockbutton.h</header>
185224
<container>1</container>
186225
</customwidget>
187-
<customwidget>
188-
<class>QgsDoubleSpinBox</class>
189-
<extends>QDoubleSpinBox</extends>
190-
<header>qgsdoublespinbox.h</header>
191-
</customwidget>
192226
<customwidget>
193227
<class>QgsLayoutUnitsComboBox</class>
194228
<extends>QComboBox</extends>
195229
<header>qgslayoutunitscombobox.h</header>
196230
</customwidget>
197231
<customwidget>
198-
<class>QgsPropertyOverrideButton</class>
232+
<class>QgsSymbolButton</class>
199233
<extends>QToolButton</extends>
200-
<header>qgspropertyoverridebutton.h</header>
234+
<header>qgssymbolbutton.h</header>
201235
</customwidget>
202236
</customwidgets>
203237
<tabstops>

‎tests/src/core/testqgslayoutpage.cpp

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class TestQgsLayoutPage : public QObject
4242
void decodePageOrientation();
4343
void grid();
4444
void transparentPaper(); //test totally transparent paper style
45+
void borderedPaper(); //test page with border
46+
void markerLinePaper(); //test page with marker line borde
4547

4648
void hiddenPages(); //test hidden page boundaries
4749

@@ -187,6 +189,45 @@ void TestQgsLayoutPage::transparentPaper()
187189
QVERIFY( checker.testLayout( mReport ) );
188190
}
189191

192+
void TestQgsLayoutPage::borderedPaper()
193+
{
194+
QgsProject p;
195+
QgsLayout l( &p );
196+
std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );
197+
page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
198+
l.pageCollection()->addPage( page.release() );
199+
200+
QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer();
201+
std::unique_ptr< QgsFillSymbol > fillSymbol = qgis::make_unique< QgsFillSymbol >();
202+
fillSymbol->changeSymbolLayer( 0, simpleFill );
203+
simpleFill->setColor( Qt::white );
204+
simpleFill->setStrokeColor( Qt::black );
205+
simpleFill->setStrokeWidth( 6 );
206+
l.pageCollection()->setPageStyleSymbol( fillSymbol.get() );
207+
208+
QgsLayoutChecker checker( QStringLiteral( "composerpaper_bordered" ), &l );
209+
checker.setControlPathPrefix( QStringLiteral( "composer_paper" ) );
210+
QVERIFY( checker.testLayout( mReport ) );
211+
}
212+
213+
void TestQgsLayoutPage::markerLinePaper()
214+
{
215+
QgsProject p;
216+
QgsLayout l( &p );
217+
std::unique_ptr< QgsLayoutItemPage > page( new QgsLayoutItemPage( &l ) );
218+
page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
219+
l.pageCollection()->addPage( page.release() );
220+
221+
QgsMarkerLineSymbolLayer *markerLine = new QgsMarkerLineSymbolLayer();
222+
std::unique_ptr< QgsFillSymbol > markerLineSymbol = qgis::make_unique< QgsFillSymbol >();
223+
markerLineSymbol->changeSymbolLayer( 0, markerLine );
224+
l.pageCollection()->setPageStyleSymbol( markerLineSymbol.get() );
225+
226+
QgsLayoutChecker checker( QStringLiteral( "composerpaper_markerborder" ), &l );
227+
checker.setControlPathPrefix( QStringLiteral( "composer_paper" ) );
228+
QVERIFY( checker.testLayout( mReport, 0, 0 ) );
229+
}
230+
190231
void TestQgsLayoutPage::hiddenPages()
191232
{
192233
QgsProject p;
@@ -195,24 +236,20 @@ void TestQgsLayoutPage::hiddenPages()
195236
page->setPageSize( QgsLayoutSize( 297, 210, QgsUnitTypes::LayoutMillimeters ) );
196237
l.pageCollection()->addPage( page.release() );
197238

198-
#if 0 //TODO
199239
QgsSimpleFillSymbolLayer *simpleFill = new QgsSimpleFillSymbolLayer();
200-
QgsFillSymbol *fillSymbol = new QgsFillSymbol();
240+
std::unique_ptr< QgsFillSymbol > fillSymbol = qgis::make_unique< QgsFillSymbol >();
201241
fillSymbol->changeSymbolLayer( 0, simpleFill );
202242
simpleFill->setColor( Qt::blue );
203243
simpleFill->setStrokeColor( Qt::transparent );
204-
mComposition->setPageStyleSymbol( fillSymbol );
205-
delete fillSymbol;
206-
#endif
244+
l.pageCollection()->setPageStyleSymbol( fillSymbol.get() );
207245

208246
l.context().setPagesVisible( false );
209-
#if 0 //TODO
210-
QgsCompositionChecker checker( QStringLiteral( "composerpaper_hidden" ), mComposition );
247+
248+
QgsLayoutChecker checker( QStringLiteral( "composerpaper_hidden" ), &l );
211249
checker.setControlPathPrefix( QStringLiteral( "composer_paper" ) );
212-
bool result = checker.testComposition( mReport );
213-
mComposition->setPagesVisible( true );
250+
bool result = checker.testLayout( mReport );
214251
QVERIFY( result );
215-
#endif
252+
216253
}
217254

218255
QGSTEST_MAIN( TestQgsLayoutPage )

0 commit comments

Comments
 (0)
Please sign in to comment.