Skip to content
Permalink
Browse files

Add page number selection to new item dialog

  • Loading branch information
nyalldawson committed Oct 27, 2017
1 parent c4c0c83 commit ee45ec977213f6abcd9e7f0731beadf65a81aeba
@@ -43,6 +43,12 @@ class QgsLayoutItemPropertiesDialog : QDialog
:rtype: QgsLayoutPoint
%End

int page() const;
%Docstring
Returns the page number for the new item.
:rtype: int
%End

void setItemSize( QgsLayoutSize size );
%Docstring
Sets the item ``size`` to show in the dialog.
@@ -53,6 +53,14 @@ QgsLayoutItemPropertiesDialog::QgsLayoutItemPropertiesDialog( QWidget *parent, Q

void QgsLayoutItemPropertiesDialog::setItemPosition( QgsLayoutPoint position )
{
// page number
QPointF layoutPoint = mLayout->convertToLayoutUnits( position );
int page = mLayout->pageCollection()->pageNumberForPoint( layoutPoint );

// convert position to relative for current page
position = mLayout->convertFromLayoutUnits( mLayout->pageCollection()->positionOnPage( layoutPoint ), position.units() );

mPageSpin->setValue( page + 1 );
mPosUnitsComboBox->setUnit( position.units() );
mXPosSpin->setValue( position.x() );
mYPosSpin->setValue( position.y() );
@@ -63,6 +71,11 @@ QgsLayoutPoint QgsLayoutItemPropertiesDialog::itemPosition() const
return QgsLayoutPoint( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
}

int QgsLayoutItemPropertiesDialog::page() const
{
return mPageSpin->value() - 1;
}

void QgsLayoutItemPropertiesDialog::setItemSize( QgsLayoutSize size )
{
mWidthSpin->setValue( size.width() );
@@ -162,4 +175,5 @@ void QgsLayoutItemPropertiesDialog::setLayout( QgsLayout *layout )
{
mSizeUnitsComboBox->setConverter( &layout->context().measurementConverter() );
mPosUnitsComboBox->setConverter( &layout->context().measurementConverter() );
mLayout = layout;
}
@@ -56,6 +56,11 @@ class GUI_EXPORT QgsLayoutItemPropertiesDialog : public QDialog, private Ui::Qgs
*/
QgsLayoutPoint itemPosition() const;

/**
* Returns the page number for the new item.
*/
int page() const;

/**
* Sets the item \a size to show in the dialog.
* \see itemSize()
@@ -87,6 +92,10 @@ class GUI_EXPORT QgsLayoutItemPropertiesDialog : public QDialog, private Ui::Qgs
*/
void setLayout( QgsLayout *layout );

private:

QgsLayout *mLayout = nullptr;

};

#endif // QGSLAYOUTNEWITEMPROPERTIESDIALOG_H
@@ -99,7 +99,7 @@ void QgsLayoutViewToolAddItem::layoutReleaseEvent( QgsLayoutViewMouseEvent *even
{
item->setReferencePoint( dlg.referencePoint() );
item->attemptResize( dlg.itemSize() );
item->attemptMove( dlg.itemPosition() );
item->attemptMove( dlg.itemPosition(), true, false, dlg.page() );
}
else
{
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>848</width>
<height>439</height>
<width>525</width>
<height>278</height>
</rect>
</property>
<property name="windowTitle">
@@ -229,31 +229,35 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_3" columnstretch="0,1,0,0,0">
<item row="2" column="4" rowspan="2">
<widget class="QgsLayoutUnitsComboBox" name="mSizeUnitsComboBox"/>
</item>
<item row="2" column="1" colspan="2">
<widget class="QgsDoubleSpinBox" name="mWidthSpin">
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,1,1,0,1">
<item row="2" column="1" colspan="3">
<widget class="QgsDoubleSpinBox" name="mYPosSpin">
<property name="suffix">
<string/>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-9999999.000000000000000</double>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mHeightLabel">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QgsDoubleSpinBox" name="mHeightSpin">
<widget class="QgsDoubleSpinBox" name="mWidthSpin">
<property name="suffix">
<string/>
</property>
@@ -271,38 +275,34 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mHeightLabel">
<property name="text">
<string>Height</string>
</property>
</widget>
<item row="3" column="4" rowspan="2">
<widget class="QgsLayoutUnitsComboBox" name="mSizeUnitsComboBox"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mXLabel">
<item row="3" column="0">
<widget class="QLabel" name="mWidthLabel">
<property name="text">
<string>X</string>
<string>Width</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mWidthLabel">
<widget class="QLabel" name="mYLabel">
<property name="text">
<string>Width</string>
<string>Y</string>
</property>
</widget>
</item>
<item row="0" column="4" rowspan="2">
<widget class="QgsLayoutUnitsComboBox" name="mPosUnitsComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mYLabel">
<widget class="QLabel" name="mXLabel">
<property name="text">
<string>Y</string>
<string>X</string>
</property>
</widget>
</item>
<item row="2" column="3" rowspan="2">
<item row="1" column="4" rowspan="2">
<widget class="QgsLayoutUnitsComboBox" name="mPosUnitsComboBox"/>
</item>
<item row="3" column="3" rowspan="2">
<layout class="QHBoxLayout" name="_2">
<property name="leftMargin">
<number>2</number>
@@ -334,27 +334,27 @@
</item>
</layout>
</item>
<item row="0" column="1" colspan="3">
<widget class="QgsDoubleSpinBox" name="mXPosSpin">
<item row="4" column="1" colspan="2">
<widget class="QgsDoubleSpinBox" name="mHeightSpin">
<property name="suffix">
<string/>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-9999999.000000000000000</double>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
</property>
<property name="showClearButton" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="QgsDoubleSpinBox" name="mYPosSpin">
<widget class="QgsDoubleSpinBox" name="mXPosSpin">
<property name="suffix">
<string/>
</property>
@@ -372,6 +372,46 @@
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QgsSpinBox" name="mPageSpin">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Page</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@@ -396,8 +436,14 @@
<extends>QComboBox</extends>
<header>qgslayoutunitscombobox.h</header>
</customwidget>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mPageSpin</tabstop>
<tabstop>mXPosSpin</tabstop>
<tabstop>mYPosSpin</tabstop>
<tabstop>mPosUnitsComboBox</tabstop>

0 comments on commit ee45ec9

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