Skip to content

Commit c89a15a

Browse files
committedJul 25, 2017
Don't disable page height/width controls when set to a known
page size Instead leave them enabled, and flick across to custom page size if they're changed.
1 parent e8514be commit c89a15a

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed
 

‎src/app/layout/qgslayoutaddpagesdialog.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ QgsLayoutAddPagesDialog::QgsLayoutAddPagesDialog( QWidget *parent, Qt::WindowFla
4848

4949
connect( mPageSizeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutAddPagesDialog::pageSizeChanged );
5050
connect( mPageOrientationComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutAddPagesDialog::orientationChanged );
51+
52+
connect( mWidthSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutAddPagesDialog::setToCustomSize );
53+
connect( mHeightSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutAddPagesDialog::setToCustomSize );
5154
}
5255

5356
void QgsLayoutAddPagesDialog::setLayout( QgsLayout *layout )
@@ -88,22 +91,19 @@ void QgsLayoutAddPagesDialog::pageSizeChanged( int )
8891
if ( mPageSizeComboBox->currentData().toString().isEmpty() )
8992
{
9093
//custom size
91-
mWidthSpin->setEnabled( true );
92-
mHeightSpin->setEnabled( true );
9394
mLockAspectRatio->setEnabled( true );
9495
mSizeUnitsComboBox->setEnabled( true );
9596
mPageOrientationComboBox->setEnabled( false );
9697
}
9798
else
9899
{
99-
mWidthSpin->setEnabled( false );
100-
mHeightSpin->setEnabled( false );
101100
mLockAspectRatio->setEnabled( false );
102101
mLockAspectRatio->setLocked( false );
103102
mSizeUnitsComboBox->setEnabled( false );
104103
mPageOrientationComboBox->setEnabled( true );
105104
QgsPageSize size = QgsApplication::pageSizeRegistry()->find( mPageSizeComboBox->currentData().toString() ).value( 0 );
106105
QgsLayoutSize convertedSize = mConverter.convert( size.size, mSizeUnitsComboBox->unit() );
106+
mSettingPresetSize = true;
107107
switch ( mPageOrientationComboBox->currentData().toInt() )
108108
{
109109
case QgsLayoutItemPage::Landscape:
@@ -116,6 +116,7 @@ void QgsLayoutAddPagesDialog::pageSizeChanged( int )
116116
mHeightSpin->setValue( convertedSize.height() );
117117
break;
118118
}
119+
mSettingPresetSize = false;
119120
}
120121
}
121122

@@ -145,3 +146,11 @@ void QgsLayoutAddPagesDialog::orientationChanged( int )
145146
break;
146147
}
147148
}
149+
150+
void QgsLayoutAddPagesDialog::setToCustomSize()
151+
{
152+
if ( mSettingPresetSize )
153+
return;
154+
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
155+
mPageOrientationComboBox->setEnabled( false );
156+
}

‎src/app/layout/qgslayoutaddpagesdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ class QgsLayoutAddPagesDialog : public QDialog, private Ui::QgsLayoutNewPageDial
7878
void positionChanged( int index );
7979
void pageSizeChanged( int index );
8080
void orientationChanged( int index );
81+
void setToCustomSize();
8182

8283
private:
8384

85+
bool mSettingPresetSize = false;
86+
8487
QgsLayoutMeasurementConverter mConverter;
8588

8689
};

‎src/app/layout/qgslayoutpagepropertieswidget.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
3333
mPageSizeComboBox->addItem( size.displayName, size.name );
3434
}
3535
mPageSizeComboBox->addItem( tr( "Custom" ) );
36-
showCurrentPageSize();
3736

3837
mWidthSpin->setValue( mPage->pageSize().width() );
3938
mHeightSpin->setValue( mPage->pageSize().height() );
@@ -53,30 +52,30 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
5352

5453
connect( mWidthSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::updatePageSize );
5554
connect( mHeightSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::updatePageSize );
55+
connect( mWidthSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
56+
connect( mHeightSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
5657

58+
showCurrentPageSize();
5759
}
5860

5961
void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
6062
{
6163
if ( mPageSizeComboBox->currentData().toString().isEmpty() )
6264
{
6365
//custom size
64-
mWidthSpin->setEnabled( true );
65-
mHeightSpin->setEnabled( true );
6666
mLockAspectRatio->setEnabled( true );
6767
mSizeUnitsComboBox->setEnabled( true );
6868
mPageOrientationComboBox->setEnabled( false );
6969
}
7070
else
7171
{
72-
mWidthSpin->setEnabled( false );
73-
mHeightSpin->setEnabled( false );
7472
mLockAspectRatio->setEnabled( false );
7573
mLockAspectRatio->setLocked( false );
7674
mSizeUnitsComboBox->setEnabled( false );
7775
mPageOrientationComboBox->setEnabled( true );
7876
QgsPageSize size = QgsApplication::pageSizeRegistry()->find( mPageSizeComboBox->currentData().toString() ).value( 0 );
7977
QgsLayoutSize convertedSize = mConverter.convert( size.size, mSizeUnitsComboBox->unit() );
78+
mSettingPresetSize = true;
8079
switch ( mPageOrientationComboBox->currentData().toInt() )
8180
{
8281
case QgsLayoutItemPage::Landscape:
@@ -89,6 +88,7 @@ void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
8988
mHeightSpin->setValue( convertedSize.height() );
9089
break;
9190
}
91+
mSettingPresetSize = false;
9292
}
9393
updatePageSize();
9494
}
@@ -128,6 +128,14 @@ void QgsLayoutPagePropertiesWidget::updatePageSize()
128128
mPage->layout()->pageCollection()->reflow();
129129
}
130130

131+
void QgsLayoutPagePropertiesWidget::setToCustomSize()
132+
{
133+
if ( mSettingPresetSize )
134+
return;
135+
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
136+
mPageOrientationComboBox->setEnabled( false );
137+
}
138+
131139
void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
132140
{
133141
QgsLayoutSize paperSize = mPage->pageSize();

‎src/app/layout/qgslayoutpagepropertieswidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ class QgsLayoutPagePropertiesWidget : public QgsLayoutItemBaseWidget, private Ui
4646
void pageSizeChanged( int index );
4747
void orientationChanged( int index );
4848
void updatePageSize();
49+
void setToCustomSize();
4950

5051
private:
5152

5253
QgsLayoutItemPage *mPage = nullptr;
5354

5455
QgsLayoutMeasurementConverter mConverter;
5556

57+
bool mSettingPresetSize = false;
58+
5659
void showCurrentPageSize();
5760

5861
};

0 commit comments

Comments
 (0)
Please sign in to comment.