Skip to content
Permalink
Browse files

Add rotation control to map views

  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 02a0e53 commit fa46e5abda69ec717f364e53c2953d2fa309fa13
Showing with 58 additions and 15 deletions.
  1. +1 −1 src/app/qgisapp.cpp
  2. +48 −10 src/app/qgsmapcanvasdockwidget.cpp
  3. +9 −4 src/app/qgsmapcanvasdockwidget.h
@@ -2560,7 +2560,7 @@ void QgisApp::createStatusBar()
"the rotation" ) );
mRotationEdit->setToolTip( tr( "Current clockwise map rotation in degrees" ) );
statusBar()->addPermanentWidget( mRotationEdit, 0 );
connect( mRotationEdit, SIGNAL( valueChanged( double ) ), this, SLOT( userRotation() ) );
connect( mRotationEdit, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgisApp::userRotation );

showRotation();

@@ -16,6 +16,7 @@
#include "qgsmapcanvas.h"
#include "qgsprojectionselectiondialog.h"
#include "qgsscalecombobox.h"
#include "qgsdoublespinbox.h"
#include <QMessageBox>
#include <QMenu>
#include <QToolBar>
@@ -51,9 +52,10 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
toolButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionMapSettings.svg" ) ) );
mToolbar->addWidget( toolButton );

QgsScaleComboAction *scaleAction = new QgsScaleComboAction( menu );
menu->addAction( scaleAction );
mScaleCombo = scaleAction->scaleCombo();
QgsMapSettingsAction *settingsAction = new QgsMapSettingsAction( menu );
menu->addAction( settingsAction );
mScaleCombo = settingsAction->scaleCombo();
mRotationEdit = settingsAction->rotationEdit();
connect( mScaleCombo, &QgsScaleComboBox::scaleChanged, this, [ = ]( double scale )
{
if ( !mBlockScaleUpdate )
@@ -72,6 +74,27 @@ QgsMapCanvasDockWidget::QgsMapCanvasDockWidget( const QString &name, QWidget *pa
mBlockScaleUpdate = false;
}
} );

connect( mRotationEdit, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, [ = ]( double value )
{
if ( !mBlockRotationUpdate )
{
mBlockRotationUpdate = true;
mMapCanvas->setRotation( value );
mMapCanvas->refresh();
mBlockRotationUpdate = false;
}
} );

connect( mMapCanvas, &QgsMapCanvas::rotationChanged, this, [ = ]( double rotation )
{
if ( !mBlockRotationUpdate )
{
mBlockRotationUpdate = true;
mRotationEdit->setValue( rotation );
mBlockRotationUpdate = false;
}
} );
}

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

QgsScaleComboAction::QgsScaleComboAction( QWidget *parent )
QgsMapSettingsAction::QgsMapSettingsAction( QWidget *parent )
: QWidgetAction( parent )
{
QGridLayout *gLayout = new QGridLayout();
gLayout->setContentsMargins( 3, 2, 3, 2 );
QLabel *label = new QLabel( tr( "Scale" ) );
gLayout->addWidget( label, 0, 0 );

mScaleCombo = new QgsScaleComboBox();
gLayout->addWidget( mScaleCombo, 0, 1 );

mRotationEdit = new QgsDoubleSpinBox();
mRotationEdit->setClearValue( 0.0 );
mRotationEdit->setKeyboardTracking( false );
mRotationEdit->setMaximumWidth( 120 );
mRotationEdit->setDecimals( 1 );
mRotationEdit->setRange( -180.0, 180.0 );
mRotationEdit->setWrapping( true );
mRotationEdit->setSingleStep( 5.0 );
mRotationEdit->setToolTip( tr( "Current clockwise map rotation in degrees" ) );

label = new QLabel( tr( "Rotation" ) );
gLayout->addWidget( label, 1, 0 );
gLayout->addWidget( mRotationEdit, 1, 1 );

QHBoxLayout *hLayout = new QHBoxLayout();
hLayout->setContentsMargins( 2, 2, 2, 2 );
QLabel *label = new QLabel( tr( "Scale" ) );
hLayout->addWidget( label );
hLayout->addWidget( mScaleCombo );
QWidget *w = new QWidget();
w->setLayout( hLayout );
w->setLayout( gLayout );
setDefaultWidget( w );
}
@@ -23,6 +23,7 @@

class QgsMapCanvas;
class QgsScaleComboBox;
class QgsDoubleSpinBox;

/**
* \class QgsMapCanvasDockWidget
@@ -66,27 +67,31 @@ class APP_EXPORT QgsMapCanvasDockWidget : public QgsDockWidget, private Ui::QgsM
QgsMapCanvas *mMainCanvas = nullptr;
bool mShowCloseWarning = true;
QgsScaleComboBox *mScaleCombo = nullptr;
QgsDoubleSpinBox *mRotationEdit = nullptr;
bool mBlockScaleUpdate = false;
bool mBlockRotationUpdate = false;
};

/**
* \class QgsScaleComboAction
* Allows embedding a scale combo into a menu.
* \class QgsMapSettingsAction
* Allows embedding a scale, rotation and other map settings into a menu.
* \note added in QGIS 3.0
*/

class QgsScaleComboAction: public QWidgetAction
class QgsMapSettingsAction: public QWidgetAction
{
Q_OBJECT

public:

QgsScaleComboAction( QWidget *parent = nullptr );
QgsMapSettingsAction( QWidget *parent = nullptr );

QgsScaleComboBox *scaleCombo() { return mScaleCombo; }
QgsDoubleSpinBox *rotationEdit() { return mRotationEdit; }

private:
QgsScaleComboBox *mScaleCombo = nullptr;
QgsDoubleSpinBox *mRotationEdit = nullptr;
};


0 comments on commit fa46e5a

Please sign in to comment.
You can’t perform that action at this time.