Skip to content

Commit

Permalink
Add rotation control to map views
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 13, 2017
1 parent 02a0e53 commit fa46e5a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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();

Expand Down
58 changes: 48 additions & 10 deletions src/app/qgsmapcanvasdockwidget.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgsmapcanvas.h"
#include "qgsprojectionselectiondialog.h"
#include "qgsscalecombobox.h"
#include "qgsdoublespinbox.h"
#include <QMessageBox>
#include <QMenu>
#include <QToolBar>
Expand Down Expand Up @@ -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 )
Expand All @@ -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()
Expand Down Expand Up @@ -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 );
}
13 changes: 9 additions & 4 deletions src/app/qgsmapcanvasdockwidget.h
Expand Up @@ -23,6 +23,7 @@

class QgsMapCanvas;
class QgsScaleComboBox;
class QgsDoubleSpinBox;

/**
* \class QgsMapCanvasDockWidget
Expand Down Expand Up @@ -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;
};


Expand Down

0 comments on commit fa46e5a

Please sign in to comment.