QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
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 "moc_qgslayoutnewitempropertiesdialog.cpp"
18#include "qgssettings.h"
19#include "qgslayout.h"
21#include "qgshelp.h"
22#include "qgsgui.h"
24
25#include <QButtonGroup>
26
27QgsLayoutItemPropertiesDialog::QgsLayoutItemPropertiesDialog( QWidget *parent, Qt::WindowFlags flags )
28 : QDialog( parent, flags )
29{
30 setupUi( this );
31
33
34 //make button exclusive
35 QButtonGroup *buttonGroup = new QButtonGroup( this );
36 buttonGroup->addButton( mUpperLeftRadioButton );
37 buttonGroup->addButton( mUpperMiddleRadioButton );
38 buttonGroup->addButton( mUpperRightRadioButton );
39 buttonGroup->addButton( mMiddleLeftRadioButton );
40 buttonGroup->addButton( mMiddleRadioButton );
41 buttonGroup->addButton( mMiddleRightRadioButton );
42 buttonGroup->addButton( mLowerLeftRadioButton );
43 buttonGroup->addButton( mLowerMiddleRadioButton );
44 buttonGroup->addButton( mLowerRightRadioButton );
45 buttonGroup->setExclusive( true );
46
47 QgsSettings settings;
48 const double lastWidth = settings.value( QStringLiteral( "LayoutDesigner/lastItemWidth" ), QStringLiteral( "50" ) ).toDouble();
49 const double lastHeight = settings.value( QStringLiteral( "LayoutDesigner/lastItemHeight" ), QStringLiteral( "50" ) ).toDouble();
50 const Qgis::LayoutUnit lastSizeUnit = settings.enumValue( QStringLiteral( "LayoutDesigner/lastSizeUnit" ), Qgis::LayoutUnit::Millimeters );
51 setItemSize( QgsLayoutSize( lastWidth, lastHeight, lastSizeUnit ) );
52
53 mPosUnitsComboBox->linkToWidget( mXPosSpin );
54 mPosUnitsComboBox->linkToWidget( mYPosSpin );
55 mSizeUnitsComboBox->linkToWidget( mWidthSpin );
56 mSizeUnitsComboBox->linkToWidget( mHeightSpin );
57
58 mLockAspectRatio->setWidthSpinBox( mWidthSpin );
59 mLockAspectRatio->setHeightSpinBox( mHeightSpin );
60
61 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutItemPropertiesDialog::showHelp );
62}
63
65{
66 // page number
67 const QPointF layoutPoint = mLayout->convertToLayoutUnits( position );
68 const int page = mLayout->pageCollection()->pageNumberForPoint( layoutPoint );
69
70 // convert position to relative for current page
71 position = mLayout->convertFromLayoutUnits( mLayout->pageCollection()->positionOnPage( layoutPoint ), position.units() );
72
73 mPageSpin->setValue( page + 1 );
74 whileBlocking( mPosUnitsComboBox )->setUnit( position.units() );
75 mXPosSpin->setValue( position.x() );
76 mYPosSpin->setValue( position.y() );
77}
78
80{
81 return QgsLayoutPoint( mXPosSpin->value(), mYPosSpin->value(), mPosUnitsComboBox->unit() );
82}
83
85{
86 return mPageSpin->value() - 1;
87}
88
90{
91 mWidthSpin->setValue( size.width() );
92 mHeightSpin->setValue( size.height() );
93 whileBlocking( mSizeUnitsComboBox )->setUnit( size.units() );
94}
95
97{
98 return QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
99}
100
102{
103 if ( mUpperLeftRadioButton->isChecked() )
104 {
106 }
107 else if ( mUpperMiddleRadioButton->isChecked() )
108 {
110 }
111 else if ( mUpperRightRadioButton->isChecked() )
112 {
114 }
115 else if ( mMiddleLeftRadioButton->isChecked() )
116 {
118 }
119 else if ( mMiddleRadioButton->isChecked() )
120 {
122 }
123 else if ( mMiddleRightRadioButton->isChecked() )
124 {
126 }
127 else if ( mLowerLeftRadioButton->isChecked() )
128 {
130 }
131 else if ( mLowerMiddleRadioButton->isChecked() )
132 {
134 }
135 else if ( mLowerRightRadioButton->isChecked() )
136 {
138 }
140}
141
143{
144 switch ( point )
145 {
147 mUpperLeftRadioButton->setChecked( true );
148 break;
149
151 mUpperMiddleRadioButton->setChecked( true );
152 break;
153
155 mUpperRightRadioButton->setChecked( true );
156 break;
157
159 mMiddleLeftRadioButton->setChecked( true );
160 break;
161
163 mMiddleRadioButton->setChecked( true );
164 break;
165
167 mMiddleRightRadioButton->setChecked( true );
168 break;
169
171 mLowerLeftRadioButton->setChecked( true );
172 break;
173
175 mLowerMiddleRadioButton->setChecked( true );
176 break;
177
179 mLowerRightRadioButton->setChecked( true );
180 break;
181 }
182}
183
185{
186 mSizeUnitsComboBox->setConverter( &layout->renderContext().measurementConverter() );
187 mPosUnitsComboBox->setConverter( &layout->renderContext().measurementConverter() );
188 mLayout = layout;
189}
190
191void QgsLayoutItemPropertiesDialog::showHelp()
192{
193 QgsHelp::openHelp( QStringLiteral( "print_composer/composer_items/composer_items_options.html#creating-a-layout-item" ) );
194}
LayoutUnit
Layout measurement units.
Definition qgis.h:4867
@ 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:209
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...
double height() const
Returns the height of the size.
Qgis::LayoutUnit units() const
Returns the units for the size.
double width() const
Returns the width of the size.
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 ...
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
double convertToLayoutUnits(QgsLayoutMeasurement measurement) const
Converts a measurement into the layout's native units.
QgsLayoutMeasurement convertFromLayoutUnits(double length, Qgis::LayoutUnit unit) const
Converts a length measurement from the layout's native units to a specified target unit.
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.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
Definition qgis.h:5862