File tree Expand file tree Collapse file tree 5 files changed +36
-9
lines changed Expand file tree Collapse file tree 5 files changed +36
-9
lines changed Original file line number Diff line number Diff line change @@ -327,14 +327,18 @@ void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
327
327
}
328
328
else if ( hasRightButton && !hasShift && !hasCtrl )
329
329
{
330
+ zoom (dy);
331
+ }
332
+
333
+ mMousePos = QPoint ( mouse->x (), mouse->y () );
334
+ }
335
+
336
+ void QgsCameraController::zoom (float factor){
330
337
// zoom in/out
331
338
float dist = mCameraPose .distanceFromCenterPoint ();
332
- dist -= dist * dy * 0 .01f ;
339
+ dist -= dist * factor * 0 .01f ;
333
340
mCameraPose .setDistanceFromCenterPoint ( dist );
334
341
updateCameraFromPose ();
335
- }
336
-
337
- mMousePos = QPoint ( mouse->x (), mouse->y () );
338
342
}
339
343
340
344
void QgsCameraController::onWheel ( Qt3DInput::QWheelEvent *wheel )
Original file line number Diff line number Diff line change @@ -135,6 +135,8 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
135
135
// ! Reads camera configuration from the given DOM element
136
136
void readXml ( const QDomElement &elem );
137
137
138
+ void zoom (float factor);
139
+
138
140
private:
139
141
void rotateCamera ( float diffPitch, float diffYaw );
140
142
void updateCameraFromPose ( bool centerPointChanged = false );
Original file line number Diff line number Diff line change @@ -41,9 +41,7 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent )
41
41
} );
42
42
43
43
mContainer = QWidget::createWindowContainer ( mEngine ->window () );
44
-
45
- mNavigationWidget = new Qgs3DNavigationWidget ();
46
- mNavigationWidget ->setParent (this );
44
+ mNavigationWidget = new Qgs3DNavigationWidget (this );
47
45
48
46
QHBoxLayout *hLayout = new QHBoxLayout ( this );
49
47
hLayout->setMargin ( 0 );
Original file line number Diff line number Diff line change 1
1
#include < QGridLayout>
2
2
#include < QPushButton>
3
3
#include < QDial>
4
+ #include < QObject>
4
5
5
6
#include " qgs3dnavigationwidget.h"
7
+ #include " qgscameracontroller.h"
6
8
7
- Qgs3DNavigationWidget::Qgs3DNavigationWidget (QWidget *parent) : QWidget(parent)
9
+ Qgs3DNavigationWidget::Qgs3DNavigationWidget (Qgs3DMapCanvas *parent) : QWidget(parent)
8
10
{
9
11
// Zoom in button
10
12
mZoomInButton = new QPushButton (this );
11
13
mZoomInButton ->setText (QStringLiteral (" +" ));
12
14
mZoomInButton ->setToolTip (QStringLiteral (" Zoom In" ));
13
15
mZoomInButton ->setAutoRepeat (true );
14
16
17
+ QObject::connect (
18
+ mZoomInButton ,
19
+ &QPushButton::clicked,
20
+ parent,
21
+ [ = ]{
22
+ parent->cameraController ()->zoom (5 );
23
+ }
24
+ );
25
+
15
26
// Zoom out button
16
27
mZoomOutButton = new QPushButton (this );
17
28
mZoomOutButton ->setText (QStringLiteral (" -" ));
18
29
mZoomOutButton ->setToolTip (QStringLiteral (" Zoom Out" ));
19
30
mZoomOutButton ->setAutoRepeat (true );
20
31
32
+ QObject::connect (
33
+ mZoomOutButton ,
34
+ &QPushButton::clicked,
35
+ parent,
36
+ [ = ]{
37
+ parent->cameraController ()->zoom (-5 );
38
+ }
39
+ );
40
+
21
41
// Tilt up button
22
42
mTiltUpButton = new QPushButton (this );
23
43
mTiltUpButton ->setText (QString::fromUtf8 (" \u25B3 " ));
Original file line number Diff line number Diff line change 21
21
#include < QDial>
22
22
#include < QGridLayout>
23
23
24
+ #include " qgs3dmapcanvas.h"
25
+ #include " qgscameracontroller.h"
26
+
24
27
class Qgs3DNavigationWidget : public QWidget
25
28
{
26
29
Q_OBJECT
27
30
public:
28
- Qgs3DNavigationWidget (QWidget *parent = nullptr );
31
+ Qgs3DNavigationWidget (Qgs3DMapCanvas *parent = nullptr );
29
32
~Qgs3DNavigationWidget ();
30
33
31
34
signals:
You can’t perform that action at this time.
0 commit comments