Skip to content

Commit fa46e5a

Browse files
committed
Add rotation control to map views
1 parent 02a0e53 commit fa46e5a

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,7 @@ void QgisApp::createStatusBar()
25602560
"the rotation" ) );
25612561
mRotationEdit->setToolTip( tr( "Current clockwise map rotation in degrees" ) );
25622562
statusBar()->addPermanentWidget( mRotationEdit, 0 );
2563-
connect( mRotationEdit, SIGNAL( valueChanged( double ) ), this, SLOT( userRotation() ) );
2563+
connect( mRotationEdit, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgisApp::userRotation );
25642564

25652565
showRotation();
25662566

src/app/qgsmapcanvasdockwidget.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "qgsmapcanvas.h"
1717
#include "qgsprojectionselectiondialog.h"
1818
#include "qgsscalecombobox.h"
19+
#include "qgsdoublespinbox.h"
1920
#include <QMessageBox>
2021
#include <QMenu>
2122
#include <QToolBar>
@@ -51,9 +52,10 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
5152
toolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapSettings.svg" ) ) );
5253
mToolbar->addWidget( toolButton );
5354

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();
5759
connect( mScaleCombo, &QgsScaleComboBox::scaleChanged, this, [ = ]( double scale )
5860
{
5961
if ( !mBlockScaleUpdate )
@@ -72,6 +74,27 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
7274
mBlockScaleUpdate = false;
7375
}
7476
} );
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+
} );
7598
}
7699

77100
QgsMapCanvas *QgsMapCanvasDockWidget::mapCanvas()
@@ -141,17 +164,32 @@ void QgsMapCanvasDockWidget::mapExtentChanged()
141164
syncView( true );
142165
}
143166

144-
QgsScaleComboAction::QgsScaleComboAction( QWidget *parent )
167+
QgsMapSettingsAction::QgsMapSettingsAction( QWidget *parent )
145168
: QWidgetAction( parent )
146169
{
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+
147175
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 );
148191

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 );
154192
QWidget *w = new QWidget();
155-
w->setLayout( hLayout );
193+
w->setLayout( gLayout );
156194
setDefaultWidget( w );
157195
}

src/app/qgsmapcanvasdockwidget.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class QgsMapCanvas;
2525
class QgsScaleComboBox;
26+
class QgsDoubleSpinBox;
2627

2728
/**
2829
* \class QgsMapCanvasDockWidget
@@ -66,27 +67,31 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
6667
QgsMapCanvas *mMainCanvas = nullptr;
6768
bool mShowCloseWarning = true;
6869
QgsScaleComboBox *mScaleCombo = nullptr;
70+
QgsDoubleSpinBox *mRotationEdit = nullptr;
6971
bool mBlockScaleUpdate = false;
72+
bool mBlockRotationUpdate = false;
7073
};
7174

7275
/**
73-
* \class QgsScaleComboAction
74-
* Allows embedding a scale combo into a menu.
76+
* \class QgsMapSettingsAction
77+
* Allows embedding a scale, rotation and other map settings into a menu.
7578
* \note added in QGIS 3.0
7679
*/
7780

78-
class QgsScaleComboAction: public QWidgetAction
81+
class QgsMapSettingsAction: public QWidgetAction
7982
{
8083
Q_OBJECT
8184

8285
public:
8386

84-
QgsScaleComboAction( QWidget *parent = nullptr );
87+
QgsMapSettingsAction( QWidget *parent = nullptr );
8588

8689
QgsScaleComboBox *scaleCombo() { return mScaleCombo; }
90+
QgsDoubleSpinBox *rotationEdit() { return mRotationEdit; }
8791

8892
private:
8993
QgsScaleComboBox *mScaleCombo = nullptr;
94+
QgsDoubleSpinBox *mRotationEdit = nullptr;
9095
};
9196

9297

0 commit comments

Comments
 (0)