Skip to content

Commit 595de48

Browse files
committed
[composer] Use spin boxes for item position and size
1 parent ed70074 commit 595de48

File tree

3 files changed

+103
-68
lines changed

3 files changed

+103
-68
lines changed

src/app/composer/qgscomposeritemwidget.cpp

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ QgsComposerItemWidget::QgsComposerItemWidget( QWidget* parent, QgsComposerItem*
126126
buttonGroup->addButton( mLowerRightCheckBox );
127127
buttonGroup->setExclusive( true );
128128

129-
mXLineEdit->setValidator( new QDoubleValidator( 0 ) );
130-
mYLineEdit->setValidator( new QDoubleValidator( 0 ) );
131-
mWidthLineEdit->setValidator( new QDoubleValidator( 0 ) );
132-
mHeightLineEdit->setValidator( new QDoubleValidator( 0 ) );
133-
134129
setValuesForGuiElements();
135130
connect( mItem->composition(), SIGNAL( paperSizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
136131
connect( mItem, SIGNAL( sizeChanged() ), this, SLOT( setValuesForGuiPositionElements() ) );
@@ -251,18 +246,10 @@ void QgsComposerItemWidget::changeItemPosition()
251246
{
252247
mItem->beginCommand( tr( "Item position changed" ) );
253248

254-
bool convXSuccess, convYSuccess;
255-
double x = mXLineEdit->text().toDouble( &convXSuccess );
256-
double y = mYLineEdit->text().toDouble( &convYSuccess );
257-
258-
bool convSuccessWidth, convSuccessHeight;
259-
double width = mWidthLineEdit->text().toDouble( &convSuccessWidth );
260-
double height = mHeightLineEdit->text().toDouble( &convSuccessHeight );
261-
262-
if ( !convXSuccess || !convYSuccess || !convSuccessWidth || !convSuccessHeight )
263-
{
264-
return;
265-
}
249+
double x = mXPosSpin->value();
250+
double y = mYPosSpin->value();
251+
double width = mWidthSpin->value();
252+
double height = mHeightSpin->value();
266253

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

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

382-
mXLineEdit->blockSignals( true );
383-
mYLineEdit->blockSignals( true );
384-
mWidthLineEdit->blockSignals( true );
385-
mHeightLineEdit->blockSignals( true );
369+
mXPosSpin->blockSignals( true );
370+
mYPosSpin->blockSignals( true );
371+
mWidthSpin->blockSignals( true );
372+
mHeightSpin->blockSignals( true );
386373
mUpperLeftCheckBox->blockSignals( true );
387374
mUpperMiddleCheckBox->blockSignals( true );
388375
mUpperRightCheckBox->blockSignals( true );
@@ -399,75 +386,74 @@ void QgsComposerItemWidget::setValuesForGuiPositionElements()
399386
if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperLeft )
400387
{
401388
mUpperLeftCheckBox->setChecked( true );
402-
mXLineEdit->setText( QString::number( pos.x() ) );
403-
mYLineEdit->setText( QString::number( pos.y() ) );
389+
mXPosSpin->setValue( pos.x() );
390+
mYPosSpin->setValue( pos.y() );
404391
}
405392

406393
if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperMiddle )
407394
{
408395
mUpperMiddleCheckBox->setChecked( true );
409-
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() / 2.0 ) );
410-
mYLineEdit->setText( QString::number( pos.y() ) );
396+
mXPosSpin->setValue( pos.x() + mItem->rect().width() / 2.0 );
397+
mYPosSpin->setValue( pos.y() );
411398
}
412399

413400
if ( mItem->lastUsedPositionMode() == QgsComposerItem::UpperRight )
414401
{
415402
mUpperRightCheckBox->setChecked( true );
416-
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() ) );
417-
mYLineEdit->setText( QString::number( pos.y() ) );
403+
mXPosSpin->setValue( pos.x() + mItem->rect().width() );
404+
mYPosSpin->setValue( pos.y() );
418405
}
419406

420407
if ( mItem->lastUsedPositionMode() == QgsComposerItem::MiddleLeft )
421408
{
422409
mMiddleLeftCheckBox->setChecked( true );
423-
mXLineEdit->setText( QString::number( pos.x() ) );
424-
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() / 2.0 ) );
410+
mXPosSpin->setValue( pos.x() );
411+
mYPosSpin->setValue( pos.y() + mItem->rect().height() / 2.0 );
425412
}
426413

427414
if ( mItem->lastUsedPositionMode() == QgsComposerItem::Middle )
428415
{
429416
mMiddleCheckBox->setChecked( true );
430-
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() / 2.0 ) );
431-
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() / 2.0 ) );
417+
mXPosSpin->setValue( pos.x() + mItem->rect().width() / 2.0 );
418+
mYPosSpin->setValue( pos.y() + mItem->rect().height() / 2.0 );
432419
}
433420

434421
if ( mItem->lastUsedPositionMode() == QgsComposerItem::MiddleRight )
435422
{
436423
mMiddleRightCheckBox->setChecked( true );
437-
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() ) );
438-
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() / 2.0 ) );
424+
mXPosSpin->setValue( pos.x() + mItem->rect().width() );
425+
mYPosSpin->setValue( pos.y() + mItem->rect().height() / 2.0 );
439426
}
440427

441428
if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerLeft )
442429
{
443430
mLowerLeftCheckBox->setChecked( true );
444-
mXLineEdit->setText( QString::number( pos.x() ) );
445-
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() ) );
431+
mXPosSpin->setValue( pos.x() );
432+
mYPosSpin->setValue( pos.y() + mItem->rect().height() );
446433
}
447434

448435
if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerMiddle )
449436
{
450437
mLowerMiddleCheckBox->setChecked( true );
451-
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() / 2.0 ) );
452-
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() ) );
438+
mXPosSpin->setValue( pos.x() + mItem->rect().width() / 2.0 );
439+
mYPosSpin->setValue( pos.y() + mItem->rect().height() );
453440
}
454441

455442
if ( mItem->lastUsedPositionMode() == QgsComposerItem::LowerRight )
456443
{
457444
mLowerRightCheckBox->setChecked( true );
458-
mXLineEdit->setText( QString::number( pos.x() + mItem->rect().width() ) );
459-
mYLineEdit->setText( QString::number( pos.y() + mItem->rect().height() ) );
445+
mXPosSpin->setValue( pos.x() + mItem->rect().width() );
446+
mYPosSpin->setValue( pos.y() + mItem->rect().height() );
460447
}
461448

462-
mWidthLineEdit->setText( QString::number( mItem->rect().width() ) );
463-
mHeightLineEdit->setText( QString::number( mItem->rect().height() ) );
449+
mWidthSpin->setValue( mItem->rect().width() );
450+
mHeightSpin->setValue( mItem->rect().height() );
464451
mPageSpinBox->setValue( mItem->page() );
465452

466-
467-
mXLineEdit->blockSignals( false );
468-
mYLineEdit->blockSignals( false );
469-
mWidthLineEdit->blockSignals( false );
470-
mHeightLineEdit->blockSignals( false );
453+
mXPosSpin->blockSignals( false );
454+
mYPosSpin->blockSignals( false );
455+
mWidthSpin->blockSignals( false );
456+
mHeightSpin->blockSignals( false );
471457
mUpperLeftCheckBox->blockSignals( false );
472458
mUpperMiddleCheckBox->blockSignals( false );
473459
mUpperRightCheckBox->blockSignals( false );

src/app/composer/qgscomposeritemwidget.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ class QgsComposerItemWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo
9393

9494
//adjust coordinates in line edits
9595
void on_mPageSpinBox_valueChanged( int ) { changeItemPosition(); }
96-
void on_mXLineEdit_editingFinished() { changeItemPosition(); }
97-
void on_mYLineEdit_editingFinished() { changeItemPosition(); }
98-
void on_mWidthLineEdit_editingFinished() { changeItemPosition(); }
99-
void on_mHeightLineEdit_editingFinished() { changeItemPosition(); }
96+
void on_mXPosSpin_valueChanged( double ) { changeItemPosition(); }
97+
void on_mYPosSpin_valueChanged( double ) { changeItemPosition(); }
98+
void on_mWidthSpin_valueChanged( double ) { changeItemPosition(); }
99+
void on_mHeightSpin_valueChanged( double ) { changeItemPosition(); }
100100

101101
void on_mUpperLeftCheckBox_stateChanged( int state );
102102
void on_mUpperMiddleCheckBox_stateChanged( int state );

src/ui/qgscomposeritemwidgetbase.ui

100644100755
Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
<string>Global Options</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout_2">
17-
<property name="margin">
17+
<property name="leftMargin">
18+
<number>0</number>
19+
</property>
20+
<property name="topMargin">
21+
<number>0</number>
22+
</property>
23+
<property name="rightMargin">
24+
<number>0</number>
25+
</property>
26+
<property name="bottomMargin">
1827
<number>0</number>
1928
</property>
2029
<item>
@@ -170,9 +179,6 @@
170179
</item>
171180
<item row="0" column="0" rowspan="2">
172181
<layout class="QGridLayout" name="gridLayout_3">
173-
<item row="3" column="1">
174-
<widget class="QLineEdit" name="mWidthLineEdit"/>
175-
</item>
176182
<item row="3" column="0">
177183
<widget class="QLabel" name="mWidthLabel">
178184
<property name="text">
@@ -194,12 +200,6 @@
194200
</property>
195201
</widget>
196202
</item>
197-
<item row="1" column="1">
198-
<widget class="QLineEdit" name="mXLineEdit"/>
199-
</item>
200-
<item row="4" column="1">
201-
<widget class="QLineEdit" name="mHeightLineEdit"/>
202-
</item>
203203
<item row="2" column="0">
204204
<widget class="QLabel" name="mYLabel">
205205
<property name="text">
@@ -214,44 +214,93 @@
214214
</property>
215215
</widget>
216216
</item>
217-
<item row="2" column="1">
218-
<widget class="QLineEdit" name="mYLineEdit"/>
219-
</item>
220-
<item row="1" column="2">
217+
<item row="1" column="3">
221218
<widget class="QgsDataDefinedButton" name="mXPositionDDBtn">
222219
<property name="text">
223220
<string>...</string>
224221
</property>
225222
</widget>
226223
</item>
227-
<item row="2" column="2">
224+
<item row="2" column="3">
228225
<widget class="QgsDataDefinedButton" name="mYPositionDDBtn">
229226
<property name="text">
230227
<string>...</string>
231228
</property>
232229
</widget>
233230
</item>
234-
<item row="3" column="2">
231+
<item row="3" column="3">
235232
<widget class="QgsDataDefinedButton" name="mWidthDDBtn">
236233
<property name="text">
237234
<string>...</string>
238235
</property>
239236
</widget>
240237
</item>
241-
<item row="4" column="2">
238+
<item row="4" column="3">
242239
<widget class="QgsDataDefinedButton" name="mHeightDDBtn">
243240
<property name="text">
244241
<string>...</string>
245242
</property>
246243
</widget>
247244
</item>
248-
<item row="0" column="1" colspan="2">
245+
<item row="0" column="1" colspan="3">
249246
<widget class="QSpinBox" name="mPageSpinBox">
250247
<property name="minimum">
251248
<number>1</number>
252249
</property>
253250
</widget>
254251
</item>
252+
<item row="1" column="1" colspan="2">
253+
<widget class="QDoubleSpinBox" name="mXPosSpin">
254+
<property name="suffix">
255+
<string> mm</string>
256+
</property>
257+
<property name="decimals">
258+
<number>3</number>
259+
</property>
260+
<property name="maximum">
261+
<double>9999999.000000000000000</double>
262+
</property>
263+
</widget>
264+
</item>
265+
<item row="2" column="1" colspan="2">
266+
<widget class="QDoubleSpinBox" name="mYPosSpin">
267+
<property name="suffix">
268+
<string> mm</string>
269+
</property>
270+
<property name="decimals">
271+
<number>3</number>
272+
</property>
273+
<property name="maximum">
274+
<double>9999999.000000000000000</double>
275+
</property>
276+
</widget>
277+
</item>
278+
<item row="3" column="1" colspan="2">
279+
<widget class="QDoubleSpinBox" name="mWidthSpin">
280+
<property name="suffix">
281+
<string> mm</string>
282+
</property>
283+
<property name="decimals">
284+
<number>3</number>
285+
</property>
286+
<property name="maximum">
287+
<double>9999999.000000000000000</double>
288+
</property>
289+
</widget>
290+
</item>
291+
<item row="4" column="1" colspan="2">
292+
<widget class="QDoubleSpinBox" name="mHeightSpin">
293+
<property name="suffix">
294+
<string> mm</string>
295+
</property>
296+
<property name="decimals">
297+
<number>3</number>
298+
</property>
299+
<property name="maximum">
300+
<double>9999999.000000000000000</double>
301+
</property>
302+
</widget>
303+
</item>
255304
</layout>
256305
</item>
257306
</layout>

0 commit comments

Comments
 (0)