Skip to content

Commit ee45ec9

Browse files
committed
Add page number selection to new item dialog
1 parent c4c0c83 commit ee45ec9

5 files changed

+111
-36
lines changed

python/gui/layout/qgslayoutnewitempropertiesdialog.sip

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class QgsLayoutItemPropertiesDialog : QDialog
4343
:rtype: QgsLayoutPoint
4444
%End
4545

46+
int page() const;
47+
%Docstring
48+
Returns the page number for the new item.
49+
:rtype: int
50+
%End
51+
4652
void setItemSize( QgsLayoutSize size );
4753
%Docstring
4854
Sets the item ``size`` to show in the dialog.

src/gui/layout/qgslayoutnewitempropertiesdialog.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ QgsLayoutItemPropertiesDialog::QgsLayoutItemPropertiesDialog( QWidget *parent, Q
5353

5454
void QgsLayoutItemPropertiesDialog::setItemPosition( QgsLayoutPoint position )
5555
{
56+
// page number
57+
QPointF layoutPoint = mLayout->convertToLayoutUnits( position );
58+
int page = mLayout->pageCollection()->pageNumberForPoint( layoutPoint );
59+
60+
// convert position to relative for current page
61+
position = mLayout->convertFromLayoutUnits( mLayout->pageCollection()->positionOnPage( layoutPoint ), position.units() );
62+
63+
mPageSpin->setValue( page + 1 );
5664
mPosUnitsComboBox->setUnit( position.units() );
5765
mXPosSpin->setValue( position.x() );
5866
mYPosSpin->setValue( position.y() );
@@ -63,6 +71,11 @@ QgsLayoutPoint QgsLayoutItemPropertiesDialog::itemPosition() const
6371
return QgsLayoutPoint( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
6472
}
6573

74+
int QgsLayoutItemPropertiesDialog::page() const
75+
{
76+
return mPageSpin->value() - 1;
77+
}
78+
6679
void QgsLayoutItemPropertiesDialog::setItemSize( QgsLayoutSize size )
6780
{
6881
mWidthSpin->setValue( size.width() );
@@ -162,4 +175,5 @@ void QgsLayoutItemPropertiesDialog::setLayout( QgsLayout *layout )
162175
{
163176
mSizeUnitsComboBox->setConverter( &layout->context().measurementConverter() );
164177
mPosUnitsComboBox->setConverter( &layout->context().measurementConverter() );
178+
mLayout = layout;
165179
}

src/gui/layout/qgslayoutnewitempropertiesdialog.h

+9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class GUI_EXPORT QgsLayoutItemPropertiesDialog : public QDialog, private Ui::Qgs
5656
*/
5757
QgsLayoutPoint itemPosition() const;
5858

59+
/**
60+
* Returns the page number for the new item.
61+
*/
62+
int page() const;
63+
5964
/**
6065
* Sets the item \a size to show in the dialog.
6166
* \see itemSize()
@@ -87,6 +92,10 @@ class GUI_EXPORT QgsLayoutItemPropertiesDialog : public QDialog, private Ui::Qgs
8792
*/
8893
void setLayout( QgsLayout *layout );
8994

95+
private:
96+
97+
QgsLayout *mLayout = nullptr;
98+
9099
};
91100

92101
#endif // QGSLAYOUTNEWITEMPROPERTIESDIALOG_H

src/gui/layout/qgslayoutviewtooladditem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even
9999
{
100100
item->setReferencePoint( dlg.referencePoint() );
101101
item->attemptResize( dlg.itemSize() );
102-
item->attemptMove( dlg.itemPosition() );
102+
item->attemptMove( dlg.itemPosition(), true, false, dlg.page() );
103103
}
104104
else
105105
{

src/ui/layout/qgslayoutnewitemproperties.ui

+81-35
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>848</width>
10-
<height>439</height>
9+
<width>525</width>
10+
<height>278</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -229,31 +229,35 @@
229229
</property>
230230
<layout class="QVBoxLayout" name="verticalLayout">
231231
<item>
232-
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,1,0,0,0">
233-
<item row="2" column="4" rowspan="2">
234-
<widget class="QgsLayoutUnitsComboBox" name="mSizeUnitsComboBox"/>
235-
</item>
236-
<item row="2" column="1" colspan="2">
237-
<widget class="QgsDoubleSpinBox" name="mWidthSpin">
232+
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,1,1,0,1">
233+
<item row="2" column="1" colspan="3">
234+
<widget class="QgsDoubleSpinBox" name="mYPosSpin">
238235
<property name="suffix">
239236
<string/>
240237
</property>
241238
<property name="decimals">
242239
<number>3</number>
243240
</property>
241+
<property name="minimum">
242+
<double>-9999999.000000000000000</double>
243+
</property>
244244
<property name="maximum">
245245
<double>9999999.000000000000000</double>
246246
</property>
247-
<property name="value">
248-
<double>100.000000000000000</double>
249-
</property>
250247
<property name="showClearButton" stdset="0">
251248
<bool>false</bool>
252249
</property>
253250
</widget>
254251
</item>
252+
<item row="4" column="0">
253+
<widget class="QLabel" name="mHeightLabel">
254+
<property name="text">
255+
<string>Height</string>
256+
</property>
257+
</widget>
258+
</item>
255259
<item row="3" column="1" colspan="2">
256-
<widget class="QgsDoubleSpinBox" name="mHeightSpin">
260+
<widget class="QgsDoubleSpinBox" name="mWidthSpin">
257261
<property name="suffix">
258262
<string/>
259263
</property>
@@ -271,38 +275,34 @@
271275
</property>
272276
</widget>
273277
</item>
274-
<item row="3" column="0">
275-
<widget class="QLabel" name="mHeightLabel">
276-
<property name="text">
277-
<string>Height</string>
278-
</property>
279-
</widget>
278+
<item row="3" column="4" rowspan="2">
279+
<widget class="QgsLayoutUnitsComboBox" name="mSizeUnitsComboBox"/>
280280
</item>
281-
<item row="0" column="0">
282-
<widget class="QLabel" name="mXLabel">
281+
<item row="3" column="0">
282+
<widget class="QLabel" name="mWidthLabel">
283283
<property name="text">
284-
<string>X</string>
284+
<string>Width</string>
285285
</property>
286286
</widget>
287287
</item>
288288
<item row="2" column="0">
289-
<widget class="QLabel" name="mWidthLabel">
289+
<widget class="QLabel" name="mYLabel">
290290
<property name="text">
291-
<string>Width</string>
291+
<string>Y</string>
292292
</property>
293293
</widget>
294294
</item>
295-
<item row="0" column="4" rowspan="2">
296-
<widget class="QgsLayoutUnitsComboBox" name="mPosUnitsComboBox"/>
297-
</item>
298295
<item row="1" column="0">
299-
<widget class="QLabel" name="mYLabel">
296+
<widget class="QLabel" name="mXLabel">
300297
<property name="text">
301-
<string>Y</string>
298+
<string>X</string>
302299
</property>
303300
</widget>
304301
</item>
305-
<item row="2" column="3" rowspan="2">
302+
<item row="1" column="4" rowspan="2">
303+
<widget class="QgsLayoutUnitsComboBox" name="mPosUnitsComboBox"/>
304+
</item>
305+
<item row="3" column="3" rowspan="2">
306306
<layout class="QHBoxLayout" name="_2">
307307
<property name="leftMargin">
308308
<number>2</number>
@@ -334,27 +334,27 @@
334334
</item>
335335
</layout>
336336
</item>
337-
<item row="0" column="1" colspan="3">
338-
<widget class="QgsDoubleSpinBox" name="mXPosSpin">
337+
<item row="4" column="1" colspan="2">
338+
<widget class="QgsDoubleSpinBox" name="mHeightSpin">
339339
<property name="suffix">
340340
<string/>
341341
</property>
342342
<property name="decimals">
343343
<number>3</number>
344344
</property>
345-
<property name="minimum">
346-
<double>-9999999.000000000000000</double>
347-
</property>
348345
<property name="maximum">
349346
<double>9999999.000000000000000</double>
350347
</property>
348+
<property name="value">
349+
<double>100.000000000000000</double>
350+
</property>
351351
<property name="showClearButton" stdset="0">
352352
<bool>false</bool>
353353
</property>
354354
</widget>
355355
</item>
356356
<item row="1" column="1" colspan="3">
357-
<widget class="QgsDoubleSpinBox" name="mYPosSpin">
357+
<widget class="QgsDoubleSpinBox" name="mXPosSpin">
358358
<property name="suffix">
359359
<string/>
360360
</property>
@@ -372,6 +372,46 @@
372372
</property>
373373
</widget>
374374
</item>
375+
<item row="0" column="1" colspan="4">
376+
<layout class="QHBoxLayout" name="horizontalLayout">
377+
<item>
378+
<widget class="QgsSpinBox" name="mPageSpin">
379+
<property name="minimumSize">
380+
<size>
381+
<width>100</width>
382+
<height>0</height>
383+
</size>
384+
</property>
385+
<property name="minimum">
386+
<number>1</number>
387+
</property>
388+
<property name="maximum">
389+
<number>9999</number>
390+
</property>
391+
</widget>
392+
</item>
393+
<item>
394+
<spacer name="horizontalSpacer_3">
395+
<property name="orientation">
396+
<enum>Qt::Horizontal</enum>
397+
</property>
398+
<property name="sizeHint" stdset="0">
399+
<size>
400+
<width>40</width>
401+
<height>20</height>
402+
</size>
403+
</property>
404+
</spacer>
405+
</item>
406+
</layout>
407+
</item>
408+
<item row="0" column="0">
409+
<widget class="QLabel" name="label">
410+
<property name="text">
411+
<string>Page</string>
412+
</property>
413+
</widget>
414+
</item>
375415
</layout>
376416
</item>
377417
</layout>
@@ -396,8 +436,14 @@
396436
<extends>QComboBox</extends>
397437
<header>qgslayoutunitscombobox.h</header>
398438
</customwidget>
439+
<customwidget>
440+
<class>QgsSpinBox</class>
441+
<extends>QSpinBox</extends>
442+
<header>qgsspinbox.h</header>
443+
</customwidget>
399444
</customwidgets>
400445
<tabstops>
446+
<tabstop>mPageSpin</tabstop>
401447
<tabstop>mXPosSpin</tabstop>
402448
<tabstop>mYPosSpin</tabstop>
403449
<tabstop>mPosUnitsComboBox</tabstop>

0 commit comments

Comments
 (0)