Skip to content

Commit

Permalink
Sync rotation between 3D map and rotation widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Jun 6, 2019
1 parent 59172b2 commit 690bdd5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -86,6 +86,16 @@ void Qgs3DMapCanvas::setMap( Qgs3DMapSettings *map )
mMap = map;

resetView();

// Connect the camera to the navigation widget.
QObject::connect(
this->cameraController(),
&QgsCameraController::cameraChanged,
mNavigationWidget,
[ = ]{
mNavigationWidget->updateFromCamera();
}
);
}

QgsCameraController *Qgs3DMapCanvas::cameraController()
Expand Down
9 changes: 8 additions & 1 deletion src/app/3d/qgs3dnavigationwidget.cpp
Expand Up @@ -11,6 +11,7 @@

Qgs3DNavigationWidget::Qgs3DNavigationWidget(Qgs3DMapCanvas *parent) : QWidget(parent)
{
mParent3DMapCanvas = parent;
// Zoom in button
mZoomInButton = new QToolButton(this);
mZoomInButton->setToolTip(QStringLiteral("Zoom In"));
Expand Down Expand Up @@ -80,14 +81,15 @@ Qgs3DNavigationWidget::Qgs3DNavigationWidget(Qgs3DMapCanvas *parent) : QWidget(p
mRotateSceneDial->setToolTip(QStringLiteral("Rotate view"));
mRotateSceneDial->setWrapping(true);
mRotateSceneDial->setMaximum(359);
// To make it pointing to the top
mRotateSceneDial->setValue(180);

QObject::connect(
mRotateSceneDial,
&QDial::valueChanged,
parent,
[ = ]{
qInfo() << "Dial value: " << mRotateSceneDial->value();
// Subtract 180 since we "rotate" the QDial so that 0 is pointing at top.
parent->cameraController()->setCameraHeadingAngle(mRotateSceneDial->value() - 180);
}
);
Expand Down Expand Up @@ -173,3 +175,8 @@ Qgs3DNavigationWidget::~Qgs3DNavigationWidget()
{

}

void Qgs3DNavigationWidget::updateRotateSceneDialAngle(){
// Adding 180 since we "rotate" the QDial so that 0 is pointing at top.
mRotateSceneDial->setValue((mParent3DMapCanvas->cameraController()->yaw() + 180));
}
2 changes: 2 additions & 0 deletions src/app/3d/qgs3dnavigationwidget.h
Expand Up @@ -30,12 +30,14 @@ class Qgs3DNavigationWidget : public QWidget
public:
Qgs3DNavigationWidget(Qgs3DMapCanvas *parent = nullptr);
~Qgs3DNavigationWidget();
void updateRotateSceneDialAngle();

signals:

public slots:

private:
Qgs3DMapCanvas *mParent3DMapCanvas = nullptr;
QToolButton *mZoomInButton = nullptr;
QToolButton *mZoomOutButton = nullptr;
QToolButton *mTiltUpButton = nullptr;
Expand Down

0 comments on commit 690bdd5

Please sign in to comment.