Skip to content

Commit

Permalink
Don't disable page height/width controls when set to a known
Browse files Browse the repository at this point in the history
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 c89a15a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/app/layout/qgslayoutaddpagesdialog.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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:
Expand All @@ -116,6 +116,7 @@ void QgsLayoutAddPagesDialog::pageSizeChanged( int )
mHeightSpin->setValue( convertedSize.height() );
break;
}
mSettingPresetSize = false;
}
}

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

void QgsLayoutAddPagesDialog::setToCustomSize()
{
if ( mSettingPresetSize )
return;
whileBlocking( mPageSizeComboBox )->setCurrentIndex( mPageSizeComboBox->count() - 1 );
mPageOrientationComboBox->setEnabled( false );
}
3 changes: 3 additions & 0 deletions src/app/layout/qgslayoutaddpagesdialog.h
Expand Up @@ -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;

};
Expand Down
18 changes: 13 additions & 5 deletions src/app/layout/qgslayoutpagepropertieswidget.cpp
Expand Up @@ -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() );
Expand All @@ -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:
Expand All @@ -89,6 +88,7 @@ void QgsLayoutPagePropertiesWidget::pageSizeChanged( int )
mHeightSpin->setValue( convertedSize.height() );
break;
}
mSettingPresetSize = false;
}
updatePageSize();
}
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout/qgslayoutpagepropertieswidget.h
Expand Up @@ -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();

};
Expand Down

0 comments on commit c89a15a

Please sign in to comment.