Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent e8514be commit c89a15a24781e1c966c035818430e5f303193d74
@@ -48,6 +48,9 @@ QgsLayoutAddPagesDialog::QgsLayoutAddPagesDialog( QWidget *parent, Qt::WindowFla

connect( mPageSizeComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutAddPagesDialog::pageSizeChanged );
connect( mPageOrientationComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutAddPagesDialog::orientationChanged );

connect( mWidthSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutAddPagesDialog::setToCustomSize );
connect( mHeightSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutAddPagesDialog::setToCustomSize );
}

void QgsLayoutAddPagesDialog::setLayout( QgsLayout *layout )
@@ -88,22 +91,19 @@ void QgsLayoutAddPagesDialog::pageSizeChanged( int )
if ( mPageSizeComboBox->currentData().toString().isEmpty() )
{
//custom size
mWidthSpin->setEnabled( true );
mHeightSpin->setEnabled( true );
mLockAspectRatio->setEnabled( true );
mSizeUnitsComboBox->setEnabled( true );
mPageOrientationComboBox->setEnabled( false );
}
else
{
mWidthSpin->setEnabled( false );
mHeightSpin->setEnabled( false );
mLockAspectRatio->setEnabled( false );
mLockAspectRatio->setLocked( false );
mSizeUnitsComboBox->setEnabled( false );
mPageOrientationComboBox->setEnabled( true );
QgsPageSize size = QgsApplication::pageSizeRegistry()->find( mPageSizeComboBox->currentData().toString() ).value( 0 );
QgsLayoutSize convertedSize = mConverter.convert( size.size, mSizeUnitsComboBox->unit() );
mSettingPresetSize = true;
switch ( mPageOrientationComboBox->currentData().toInt() )
{
case QgsLayoutItemPage::Landscape:
@@ -116,6 +116,7 @@ void QgsLayoutAddPagesDialog::pageSizeChanged( int )
mHeightSpin->setValue( convertedSize.height() );
break;
}
mSettingPresetSize = false;
}
}

@@ -145,3 +146,11 @@ void QgsLayoutAddPagesDialog::orientationChanged( int )
break;
}
}

void QgsLayoutAddPagesDialog::setToCustomSize()
{
if ( mSettingPresetSize )
return;
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
mPageOrientationComboBox->setEnabled( false );
}
@@ -78,9 +78,12 @@ class QgsLayoutAddPagesDialog : public QDialog, private Ui::QgsLayoutNewPageDial
void positionChanged( int index );
void pageSizeChanged( int index );
void orientationChanged( int index );
void setToCustomSize();

private:

bool mSettingPresetSize = false;

QgsLayoutMeasurementConverter mConverter;

};
@@ -33,7 +33,6 @@ QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, Q
mPageSizeComboBox->addItem( size.displayName, size.name );
}
mPageSizeComboBox->addItem( tr( "Custom" ) );
showCurrentPageSize();

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

connect( mWidthSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::updatePageSize );
connect( mHeightSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::updatePageSize );
connect( mWidthSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::setToCustomSize );
connect( mHeightSpin, static_cast< void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutPagePropertiesWidget::setToCustomSize );

showCurrentPageSize();
}

void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
{
if ( mPageSizeComboBox->currentData().toString().isEmpty() )
{
//custom size
mWidthSpin->setEnabled( true );
mHeightSpin->setEnabled( true );
mLockAspectRatio->setEnabled( true );
mSizeUnitsComboBox->setEnabled( true );
mPageOrientationComboBox->setEnabled( false );
}
else
{
mWidthSpin->setEnabled( false );
mHeightSpin->setEnabled( false );
mLockAspectRatio->setEnabled( false );
mLockAspectRatio->setLocked( false );
mSizeUnitsComboBox->setEnabled( false );
mPageOrientationComboBox->setEnabled( true );
QgsPageSize size = QgsApplication::pageSizeRegistry()->find( mPageSizeComboBox->currentData().toString() ).value( 0 );
QgsLayoutSize convertedSize = mConverter.convert( size.size, mSizeUnitsComboBox->unit() );
mSettingPresetSize = true;
switch ( mPageOrientationComboBox->currentData().toInt() )
{
case QgsLayoutItemPage::Landscape:
@@ -89,6 +88,7 @@ void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
mHeightSpin->setValue( convertedSize.height() );
break;
}
mSettingPresetSize = false;
}
updatePageSize();
}
@@ -128,6 +128,14 @@ void QgsLayoutPagePropertiesWidget::updatePageSize()
mPage->layout()->pageCollection()->reflow();
}

void QgsLayoutPagePropertiesWidget::setToCustomSize()
{
if ( mSettingPresetSize )
return;
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
mPageOrientationComboBox->setEnabled( false );
}

void QgsLayoutPagePropertiesWidget::showCurrentPageSize()
{
QgsLayoutSize paperSize = mPage->pageSize();
@@ -46,13 +46,16 @@ class QgsLayoutPagePropertiesWidget : public QgsLayoutItemBaseWidget, private Ui
void pageSizeChanged( int index );
void orientationChanged( int index );
void updatePageSize();
void setToCustomSize();

private:

QgsLayoutItemPage *mPage = nullptr;

QgsLayoutMeasurementConverter mConverter;

bool mSettingPresetSize = false;

void showCurrentPageSize();

};

0 comments on commit c89a15a

Please sign in to comment.
You can’t perform that action at this time.