Skip to content
Permalink
Browse files

[composer] Use spin boxes for item position and size

  • Loading branch information
nyalldawson committed Sep 30, 2014
1 parent ed70074 commit 595de4821ce3bd749cff0664342ac413d93ac2c3
@@ -126,11 +126,6 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem*
buttonGroup->addButton( mLowerRightCheckBox );
buttonGroup->setExclusive( true );

mXLineEdit->setValidator( new QDoubleValidator( 0 ) );
mYLineEdit->setValidator( new QDoubleValidator( 0 ) );
mWidthLineEdit->setValidator( new QDoubleValidator( 0 ) );
mHeightLineEdit->setValidator( new QDoubleValidator( 0 ) );

setValuesForGuiElements();
connect( mItem->composition(), SIGNAL( paperSizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
connect( mItem, SIGNAL( sizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
@@ -251,18 +246,10 @@ void QgsComposerItemWidget::changeItemPosition()
{
mItem->beginCommand( tr( "Item position changed" ) );

bool convXSuccess, convYSuccess;
double x = mXLineEdit->text().toDouble( &convXSuccess );
double y = mYLineEdit->text().toDouble( &convYSuccess );

bool convSuccessWidth, convSuccessHeight;
double width = mWidthLineEdit->text().toDouble( &convSuccessWidth );
double height = mHeightLineEdit->text().toDouble( &convSuccessHeight );

if ( !convXSuccess || !convYSuccess || !convSuccessWidth || !convSuccessHeight )
{
return;
}
double x = mXPosSpin->value();
double y = mYPosSpin->value();
double width = mWidthSpin->value();
double height = mHeightSpin->value();

mItem->setItemPosition( x, y, width, height, positionMode(), false, mPageSpinBox->value() );

@@ -379,10 +366,10 @@ void QgsComposerItemWidget::setValuesForGuiPositionElements()
return;
}

mXLineEdit->blockSignals( true );
mYLineEdit->blockSignals( true );
mWidthLineEdit->blockSignals( true );
mHeightLineEdit->blockSignals( true );
mXPosSpin->blockSignals( true );
mYPosSpin->blockSignals( true );
mWidthSpin->blockSignals( true );
mHeightSpin->blockSignals( true );
mUpperLeftCheckBox->blockSignals( true );
mUpperMiddleCheckBox->blockSignals( true );
mUpperRightCheckBox->blockSignals( true );
@@ -399,75 +386,74 @@ void QgsComposerItemWidget::setValuesForGuiPositionElements()
if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperLeft )
{
mUpperLeftCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() ) );
mYLineEdit->setText( QString::number( pos.y() ) );
mXPosSpin->setValue( pos.x() );
mYPosSpin->setValue( pos.y() );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperMiddle )
{
mUpperMiddleCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( pos.y() ) );
mXPosSpin->setValue( pos.x() + mItem->rect().width() / 2.0 );
mYPosSpin->setValue( pos.y() );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperRight )
{
mUpperRightCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( pos.y() ) );
mXPosSpin->setValue( pos.x() + mItem->rect().width() );
mYPosSpin->setValue( pos.y() );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::MiddleLeft )
{
mMiddleLeftCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() ) );
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() / 2.0 ) );
mXPosSpin->setValue( pos.x() );
mYPosSpin->setValue( pos.y() + mItem->rect().height() / 2.0 );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::Middle )
{
mMiddleCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() / 2.0 ) );
mXPosSpin->setValue( pos.x() + mItem->rect().width() / 2.0 );
mYPosSpin->setValue( pos.y() + mItem->rect().height() / 2.0 );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::MiddleRight )
{
mMiddleRightCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() / 2.0 ) );
mXPosSpin->setValue( pos.x() + mItem->rect().width() );
mYPosSpin->setValue( pos.y() + mItem->rect().height() / 2.0 );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerLeft )
{
mLowerLeftCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() ) );
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() ) );
mXPosSpin->setValue( pos.x() );
mYPosSpin->setValue( pos.y() + mItem->rect().height() );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerMiddle )
{
mLowerMiddleCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() / 2.0 ) );
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() ) );
mXPosSpin->setValue( pos.x() + mItem->rect().width() / 2.0 );
mYPosSpin->setValue( pos.y() + mItem->rect().height() );
}

if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerRight )
{
mLowerRightCheckBox->setChecked( true );
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() ) );
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() ) );
mXPosSpin->setValue( pos.x() + mItem->rect().width() );
mYPosSpin->setValue( pos.y() + mItem->rect().height() );
}

mWidthLineEdit->setText( QString::number( mItem->rect().width() ) );
mHeightLineEdit->setText( QString::number( mItem->rect().height() ) );
mWidthSpin->setValue( mItem->rect().width() );
mHeightSpin->setValue( mItem->rect().height() );
mPageSpinBox->setValue( mItem->page() );


mXLineEdit->blockSignals( false );
mYLineEdit->blockSignals( false );
mWidthLineEdit->blockSignals( false );
mHeightLineEdit->blockSignals( false );
mXPosSpin->blockSignals( false );
mYPosSpin->blockSignals( false );
mWidthSpin->blockSignals( false );
mHeightSpin->blockSignals( false );
mUpperLeftCheckBox->blockSignals( false );
mUpperMiddleCheckBox->blockSignals( false );
mUpperRightCheckBox->blockSignals( false );
@@ -93,10 +93,10 @@ class QgsComposerItemWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo

//adjust coordinates in line edits
void on_mPageSpinBox_valueChanged( int ) { changeItemPosition(); }
void on_mXLineEdit_editingFinished() { changeItemPosition(); }
void on_mYLineEdit_editingFinished() { changeItemPosition(); }
void on_mWidthLineEdit_editingFinished() { changeItemPosition(); }
void on_mHeightLineEdit_editingFinished() { changeItemPosition(); }
void on_mXPosSpin_valueChanged( double ) { changeItemPosition(); }
void on_mYPosSpin_valueChanged( double ) { changeItemPosition(); }
void on_mWidthSpin_valueChanged( double ) { changeItemPosition(); }
void on_mHeightSpin_valueChanged( double ) { changeItemPosition(); }

void on_mUpperLeftCheckBox_stateChanged( int state );
void on_mUpperMiddleCheckBox_stateChanged( int state );
@@ -14,7 +14,16 @@
<string>Global Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@@ -170,9 +179,6 @@
</item>
<item row="0" column="0" rowspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="3" column="1">
<widget class="QLineEdit" name="mWidthLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mWidthLabel">
<property name="text">
@@ -194,12 +200,6 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mXLineEdit"/>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="mHeightLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mYLabel">
<property name="text">
@@ -214,44 +214,93 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mYLineEdit"/>
</item>
<item row="1" column="2">
<item row="1" column="3">
<widget class="QgsDataDefinedButton" name="mXPositionDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="2">
<item row="2" column="3">
<widget class="QgsDataDefinedButton" name="mYPositionDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="2">
<item row="3" column="3">
<widget class="QgsDataDefinedButton" name="mWidthDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="4" column="2">
<item row="4" column="3">
<widget class="QgsDataDefinedButton" name="mHeightDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<item row="0" column="1" colspan="3">
<widget class="QSpinBox" name="mPageSpinBox">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="mXPosSpin">
<property name="suffix">
<string> mm</string>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="mYPosSpin">
<property name="suffix">
<string> mm</string>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="mWidthSpin">
<property name="suffix">
<string> mm</string>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="mHeightSpin">
<property name="suffix">
<string> mm</string>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>

0 comments on commit 595de48

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