16
16
#include " qgsmapcanvas.h"
17
17
#include " qgsprojectionselectiondialog.h"
18
18
#include " qgsscalecombobox.h"
19
+ #include " qgsdoublespinbox.h"
19
20
#include < QMessageBox>
20
21
#include < QMenu>
21
22
#include < QToolBar>
@@ -51,9 +52,10 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
51
52
toolButton->setIcon ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionMapSettings.svg" ) ) );
52
53
mToolbar ->addWidget ( toolButton );
53
54
54
- QgsScaleComboAction *scaleAction = new QgsScaleComboAction ( menu );
55
- menu->addAction ( scaleAction );
56
- mScaleCombo = scaleAction->scaleCombo ();
55
+ QgsMapSettingsAction *settingsAction = new QgsMapSettingsAction ( menu );
56
+ menu->addAction ( settingsAction );
57
+ mScaleCombo = settingsAction->scaleCombo ();
58
+ mRotationEdit = settingsAction->rotationEdit ();
57
59
connect ( mScaleCombo , &QgsScaleComboBox::scaleChanged, this , [ = ]( double scale )
58
60
{
59
61
if ( !mBlockScaleUpdate )
@@ -72,6 +74,27 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
72
74
mBlockScaleUpdate = false ;
73
75
}
74
76
} );
77
+
78
+ connect ( mRotationEdit , static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this , [ = ]( double value )
79
+ {
80
+ if ( !mBlockRotationUpdate )
81
+ {
82
+ mBlockRotationUpdate = true ;
83
+ mMapCanvas ->setRotation ( value );
84
+ mMapCanvas ->refresh ();
85
+ mBlockRotationUpdate = false ;
86
+ }
87
+ } );
88
+
89
+ connect ( mMapCanvas , &QgsMapCanvas::rotationChanged, this , [ = ]( double rotation )
90
+ {
91
+ if ( !mBlockRotationUpdate )
92
+ {
93
+ mBlockRotationUpdate = true ;
94
+ mRotationEdit ->setValue ( rotation );
95
+ mBlockRotationUpdate = false ;
96
+ }
97
+ } );
75
98
}
76
99
77
100
QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas ()
@@ -141,17 +164,32 @@ void QgsMapCanvasDockWidget::mapExtentChanged()
141
164
syncView ( true );
142
165
}
143
166
144
- QgsScaleComboAction::QgsScaleComboAction ( QWidget *parent )
167
+ QgsMapSettingsAction::QgsMapSettingsAction ( QWidget *parent )
145
168
: QWidgetAction( parent )
146
169
{
170
+ QGridLayout *gLayout = new QGridLayout ();
171
+ gLayout ->setContentsMargins ( 3 , 2 , 3 , 2 );
172
+ QLabel *label = new QLabel ( tr ( " Scale" ) );
173
+ gLayout ->addWidget ( label, 0 , 0 );
174
+
147
175
mScaleCombo = new QgsScaleComboBox ();
176
+ gLayout ->addWidget ( mScaleCombo , 0 , 1 );
177
+
178
+ mRotationEdit = new QgsDoubleSpinBox ();
179
+ mRotationEdit ->setClearValue ( 0.0 );
180
+ mRotationEdit ->setKeyboardTracking ( false );
181
+ mRotationEdit ->setMaximumWidth ( 120 );
182
+ mRotationEdit ->setDecimals ( 1 );
183
+ mRotationEdit ->setRange ( -180.0 , 180.0 );
184
+ mRotationEdit ->setWrapping ( true );
185
+ mRotationEdit ->setSingleStep ( 5.0 );
186
+ mRotationEdit ->setToolTip ( tr ( " Current clockwise map rotation in degrees" ) );
187
+
188
+ label = new QLabel ( tr ( " Rotation" ) );
189
+ gLayout ->addWidget ( label, 1 , 0 );
190
+ gLayout ->addWidget ( mRotationEdit , 1 , 1 );
148
191
149
- QHBoxLayout *hLayout = new QHBoxLayout ();
150
- hLayout->setContentsMargins ( 2 , 2 , 2 , 2 );
151
- QLabel *label = new QLabel ( tr ( " Scale" ) );
152
- hLayout->addWidget ( label );
153
- hLayout->addWidget ( mScaleCombo );
154
192
QWidget *w = new QWidget ();
155
- w->setLayout ( hLayout );
193
+ w->setLayout ( gLayout );
156
194
setDefaultWidget ( w );
157
195
}
0 commit comments