QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgslayoutnewitempropertiesdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutnewitempropertiesdialog.cpp
3 ------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgssettings.h"
18#include "qgslayout.h"
20#include "qgshelp.h"
21#include "qgsgui.h"
23
24#include <QButtonGroup>
25
26QgsLayoutItemPropertiesDialog::QgsLayoutItemPropertiesDialog( QWidget *parent, Qt::WindowFlags flags )
27 : QDialog( parent, flags )
28{
29 setupUi( this );
30
32
33 //make button exclusive
34 QButtonGroup *buttonGroup = new QButtonGroup( this );
35 buttonGroup->addButton( mUpperLeftRadioButton );
36 buttonGroup->addButton( mUpperMiddleRadioButton );
37 buttonGroup->addButton( mUpperRightRadioButton );
38 buttonGroup->addButton( mMiddleLeftRadioButton );
39 buttonGroup->addButton( mMiddleRadioButton );
40 buttonGroup->addButton( mMiddleRightRadioButton );
41 buttonGroup->addButton( mLowerLeftRadioButton );
42 buttonGroup->addButton( mLowerMiddleRadioButton );
43 buttonGroup->addButton( mLowerRightRadioButton );
44 buttonGroup->setExclusive( true );
45
46 QgsSettings settings;
47 const double lastWidth = settings.value( QStringLiteral( "LayoutDesigner/lastItemWidth" ), QStringLiteral( "50" ) ).toDouble();
48 const double lastHeight = settings.value( QStringLiteral( "LayoutDesigner/lastItemHeight" ), QStringLiteral( "50" ) ).toDouble();
49 const Qgis::LayoutUnit lastSizeUnit = settings.enumValue( QStringLiteral( "LayoutDesigner/lastSizeUnit" ), Qgis::LayoutUnit::Millimeters );
50 setItemSize( QgsLayoutSize( lastWidth, lastHeight, lastSizeUnit ) );
51
52 mPosUnitsComboBox->linkToWidget( mXPosSpin );
53 mPosUnitsComboBox->linkToWidget( mYPosSpin );
54 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
55 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
56
57 mLockAspectRatio->setWidthSpinBox( mWidthSpin );
58 mLockAspectRatio->setHeightSpinBox( mHeightSpin );
59
60 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutItemPropertiesDialog::showHelp );
61}
62
64{
65 // page number
66 const QPointF layoutPoint = mLayout->convertToLayoutUnits( position );
67 const int page = mLayout->pageCollection()->pageNumberForPoint( layoutPoint );
68
69 // convert position to relative for current page
70 position = mLayout->convertFromLayoutUnits( mLayout->pageCollection()->positionOnPage( layoutPoint ), position.units() );
71
72 mPageSpin->setValue( page + 1 );
73 whileBlocking( mPosUnitsComboBox )->setUnit( position.units() );
74 mXPosSpin->setValue( position.x() );
75 mYPosSpin->setValue( position.y() );
76}
77
79{
80 return QgsLayoutPoint( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
81}
82
84{
85 return mPageSpin->value() - 1;
86}
87
89{
90 mWidthSpin->setValue( size.width() );
91 mHeightSpin->setValue( size.height() );
92 whileBlocking( mSizeUnitsComboBox )->setUnit( size.units() );
93}
94
96{
97 return QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
98}
99
101{
102 if ( mUpperLeftRadioButton->isChecked() )
103 {
105 }
106 else if ( mUpperMiddleRadioButton->isChecked() )
107 {
109 }
110 else if ( mUpperRightRadioButton->isChecked() )
111 {
113 }
114 else if ( mMiddleLeftRadioButton->isChecked() )
115 {
117 }
118 else if ( mMiddleRadioButton->isChecked() )
119 {
121 }
122 else if ( mMiddleRightRadioButton->isChecked() )
123 {
125 }
126 else if ( mLowerLeftRadioButton->isChecked() )
127 {
129 }
130 else if ( mLowerMiddleRadioButton->isChecked() )
131 {
133 }
134 else if ( mLowerRightRadioButton->isChecked() )
135 {
137 }
139}
140
142{
143 switch ( point )
144 {
146 mUpperLeftRadioButton->setChecked( true );
147 break;
148
150 mUpperMiddleRadioButton->setChecked( true );
151 break;
152
154 mUpperRightRadioButton->setChecked( true );
155 break;
156
158 mMiddleLeftRadioButton->setChecked( true );
159 break;
160
162 mMiddleRadioButton->setChecked( true );
163 break;
164
166 mMiddleRightRadioButton->setChecked( true );
167 break;
168
170 mLowerLeftRadioButton->setChecked( true );
171 break;
172
174 mLowerMiddleRadioButton->setChecked( true );
175 break;
176
178 mLowerRightRadioButton->setChecked( true );
179 break;
180 }
181}
182
184{
185 mSizeUnitsComboBox->setConverter( &layout->renderContext().measurementConverter() );
186 mPosUnitsComboBox->setConverter( &layout->renderContext().measurementConverter() );
187 mLayout = layout;
188}
189
190void QgsLayoutItemPropertiesDialog::showHelp()
191{
192 QgsHelp::openHelp( QStringLiteral( "print_composer/composer_items/composer_items_options.html#creating-a-layout-item" ) );
193}
LayoutUnit
Layout measurement units.
Definition: qgis.h:4275
@ Millimeters
Millimeters.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:194
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:39
QgsLayoutItemPropertiesDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsLayoutNewItemPropertiesDialog.
QgsLayoutSize itemSize() const
Returns the item size defined by the dialog.
void setReferencePoint(QgsLayoutItem::ReferencePoint point)
Sets the item reference point defined to show in the dialog.
QgsLayoutItem::ReferencePoint referencePoint() const
Returns the item reference point defined by the dialog.
void setItemSize(QgsLayoutSize size)
Sets the item size to show in the dialog.
void setLayout(QgsLayout *layout)
Sets the layout associated with the dialog.
QgsLayoutPoint itemPosition() const
Returns the current item position defined by the dialog.
int page() const
Returns the page number for the new item.
void setItemPosition(QgsLayoutPoint position)
Sets the item position to show in the dialog.
ReferencePoint
Fixed position reference point.
@ LowerMiddle
Lower center of item.
@ MiddleLeft
Middle left of item.
@ Middle
Center of item.
@ UpperRight
Upper right corner of item.
@ LowerLeft
Lower left corner of item.
@ UpperLeft
Upper left corner of item.
@ UpperMiddle
Upper center of item.
@ MiddleRight
Middle right of item.
@ LowerRight
Lower right corner of item.
int pageNumberForPoint(QPointF point) const
Returns the page number corresponding to a point in the layout (in layout units).
QPointF positionOnPage(QPointF point) const
Returns the position within a page of a point in the layout (in layout units).
This class provides a method of storing points, consisting of an x and y coordinate,...
double x() const
Returns x coordinate of point.
double y() const
Returns y coordinate of point.
Qgis::LayoutUnit units() const
Returns the units for the point.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
double height() const
Returns the height of the size.
Definition: qgslayoutsize.h:89
Qgis::LayoutUnit units() const
Returns the units for the size.
double width() const
Returns the width of the size.
Definition: qgslayoutsize.h:75
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
Definition: qgslayout.cpp:376
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
Definition: qgslayout.cpp:476
double convertToLayoutUnits(QgsLayoutMeasurement measurement) const
Converts a measurement into the layout's native units.
Definition: qgslayout.cpp:346
QgsLayoutMeasurement convertFromLayoutUnits(double length, Qgis::LayoutUnit unit) const
Converts a length measurement from the layout's native units to a specified target unit.
Definition: qgslayout.cpp:361
This class is a composition of two QSettings instances:
Definition: qgssettings.h:64
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
T enumValue(const QString &key, const T &defaultValue, const Section section=NoSection)
Returns the setting value for a setting based on an enum.
Definition: qgssettings.h:263
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition: qgis.h:5111