-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgslayoutnewitempropertiesdialog.cpp
182 lines (157 loc) · 6.07 KB
/
qgslayoutnewitempropertiesdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/***************************************************************************
qgslayoutnewitempropertiesdialog.cpp
------------------------------------
Date : July 2017
Copyright : (C) 2017 Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgslayoutnewitempropertiesdialog.h"
#include "qgssettings.h"
#include "qgslayout.h"
#include "qgslayoutpagecollection.h"
#include "qgsgui.h"
QgsLayoutItemPropertiesDialog::QgsLayoutItemPropertiesDialog( QWidget *parent, Qt::WindowFlags flags )
: QDialog( parent, flags )
{
setupUi( this );
QgsGui::instance()->enableAutoGeometryRestore( this );
//make button exclusive
QButtonGroup *buttonGroup = new QButtonGroup( this );
buttonGroup->addButton( mUpperLeftRadioButton );
buttonGroup->addButton( mUpperMiddleRadioButton );
buttonGroup->addButton( mUpperRightRadioButton );
buttonGroup->addButton( mMiddleLeftRadioButton );
buttonGroup->addButton( mMiddleRadioButton );
buttonGroup->addButton( mMiddleRightRadioButton );
buttonGroup->addButton( mLowerLeftRadioButton );
buttonGroup->addButton( mLowerMiddleRadioButton );
buttonGroup->addButton( mLowerRightRadioButton );
buttonGroup->setExclusive( true );
QgsSettings settings;
double lastWidth = settings.value( QStringLiteral( "LayoutDesigner/lastItemWidth" ), QStringLiteral( "50" ) ).toDouble();
double lastHeight = settings.value( QStringLiteral( "LayoutDesigner/lastItemHeight" ), QStringLiteral( "50" ) ).toDouble();
QgsUnitTypes::LayoutUnit lastSizeUnit = settings.enumValue( QStringLiteral( "LayoutDesigner/lastSizeUnit" ), QgsUnitTypes::LayoutMillimeters );
setItemSize( QgsLayoutSize( lastWidth, lastHeight, lastSizeUnit ) );
mPosUnitsComboBox->linkToWidget( mXPosSpin );
mPosUnitsComboBox->linkToWidget( mYPosSpin );
mSizeUnitsComboBox->linkToWidget( mWidthSpin );
mSizeUnitsComboBox->linkToWidget( mHeightSpin );
mLockAspectRatio->setWidthSpinBox( mWidthSpin );
mLockAspectRatio->setHeightSpinBox( mHeightSpin );
}
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 );
whileBlocking( mPosUnitsComboBox )->setUnit( position.units() );
mXPosSpin->setValue( position.x() );
mYPosSpin->setValue( position.y() );
}
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() );
mHeightSpin->setValue( size.height() );
whileBlocking( mSizeUnitsComboBox )->setUnit( size.units() );
}
QgsLayoutSize QgsLayoutItemPropertiesDialog::itemSize() const
{
return QgsLayoutSize( mWidthSpin->value(), mHeightSpin->value(), mSizeUnitsComboBox->unit() );
}
QgsLayoutItem::ReferencePoint QgsLayoutItemPropertiesDialog::referencePoint() const
{
if ( mUpperLeftRadioButton->isChecked() )
{
return QgsLayoutItem::UpperLeft;
}
else if ( mUpperMiddleRadioButton->isChecked() )
{
return QgsLayoutItem::UpperMiddle;
}
else if ( mUpperRightRadioButton->isChecked() )
{
return QgsLayoutItem::UpperRight;
}
else if ( mMiddleLeftRadioButton->isChecked() )
{
return QgsLayoutItem::MiddleLeft;
}
else if ( mMiddleRadioButton->isChecked() )
{
return QgsLayoutItem::Middle;
}
else if ( mMiddleRightRadioButton->isChecked() )
{
return QgsLayoutItem::MiddleRight;
}
else if ( mLowerLeftRadioButton->isChecked() )
{
return QgsLayoutItem::LowerLeft;
}
else if ( mLowerMiddleRadioButton->isChecked() )
{
return QgsLayoutItem::LowerMiddle;
}
else if ( mLowerRightRadioButton->isChecked() )
{
return QgsLayoutItem::LowerRight;
}
return QgsLayoutItem::UpperLeft;
}
void QgsLayoutItemPropertiesDialog::setReferencePoint( QgsLayoutItem::ReferencePoint point )
{
switch ( point )
{
case QgsLayoutItem::UpperLeft:
mUpperLeftRadioButton->setChecked( true );
break;
case QgsLayoutItem::UpperMiddle:
mUpperMiddleRadioButton->setChecked( true );
break;
case QgsLayoutItem::UpperRight:
mUpperRightRadioButton->setChecked( true );
break;
case QgsLayoutItem::MiddleLeft:
mMiddleLeftRadioButton->setChecked( true );
break;
case QgsLayoutItem::Middle:
mMiddleRadioButton->setChecked( true );
break;
case QgsLayoutItem::MiddleRight:
mMiddleRightRadioButton->setChecked( true );
break;
case QgsLayoutItem::LowerLeft:
mLowerLeftRadioButton->setChecked( true );
break;
case QgsLayoutItem::LowerMiddle:
mLowerMiddleRadioButton->setChecked( true );
break;
case QgsLayoutItem::LowerRight:
mLowerRightRadioButton->setChecked( true );
break;
}
}
void QgsLayoutItemPropertiesDialog::setLayout( QgsLayout *layout )
{
mSizeUnitsComboBox->setConverter( &layout->renderContext().measurementConverter() );
mPosUnitsComboBox->setConverter( &layout->renderContext().measurementConverter() );
mLayout = layout;
}