Skip to content

Commit a89119e

Browse files
committedJun 6, 2019
Fix code style.
1 parent c3dc72d commit a89119e

File tree

5 files changed

+229
-214
lines changed

5 files changed

+229
-214
lines changed
 

‎src/3d/qgscameracontroller.cpp

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,19 @@ void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
327327
}
328328
else if ( hasRightButton && !hasShift && !hasCtrl )
329329
{
330-
zoom(dy);
330+
zoom( dy );
331331
}
332332

333333
mMousePos = QPoint( mouse->x(), mouse->y() );
334334
}
335335

336-
void QgsCameraController::zoom(float factor){
337-
// zoom in/out
338-
float dist = mCameraPose.distanceFromCenterPoint();
339-
dist -= dist * factor * 0.01f;
340-
mCameraPose.setDistanceFromCenterPoint( dist );
341-
updateCameraFromPose();
336+
void QgsCameraController::zoom( float factor )
337+
{
338+
// zoom in/out
339+
float dist = mCameraPose.distanceFromCenterPoint();
340+
dist -= dist * factor * 0.01f;
341+
mCameraPose.setDistanceFromCenterPoint( dist );
342+
updateCameraFromPose();
342343
}
343344

344345
void QgsCameraController::onWheel( Qt3DInput::QWheelEvent *wheel )
@@ -395,13 +396,13 @@ void QgsCameraController::onKeyPressed( Qt3DInput::QKeyEvent *event )
395396
{
396397
if ( !hasShift && !hasCtrl )
397398
{
398-
moveView(tx, ty);
399+
moveView( tx, ty );
399400
}
400401
else if ( hasShift && !hasCtrl )
401402
{
402403
// rotate/tilt using keyboard (camera moves as it rotates around its view center)
403-
tiltUpAroundViewCenter(ty);
404-
rotateAroundViewCenter(tx);
404+
tiltUpAroundViewCenter( ty );
405+
rotateAroundViewCenter( tx );
405406
}
406407
else if ( hasCtrl && !hasShift )
407408
{
@@ -432,43 +433,47 @@ void QgsCameraController::onPickerMousePressed( Qt3DRender::QPickEvent *pick )
432433
mLastPressedHeight = pick->worldIntersection().y();
433434
}
434435

435-
void QgsCameraController::tiltUpAroundViewCenter(float deltaPitch){
436-
// Tilt up the view by deltaPitch around the view center (camera moves)
437-
float pitch = mCameraPose.pitchAngle();
438-
pitch -= deltaPitch; // down key = moving camera toward terrain
439-
mCameraPose.setPitchAngle( pitch );
440-
updateCameraFromPose();
436+
void QgsCameraController::tiltUpAroundViewCenter( float deltaPitch )
437+
{
438+
// Tilt up the view by deltaPitch around the view center (camera moves)
439+
float pitch = mCameraPose.pitchAngle();
440+
pitch -= deltaPitch; // down key = moving camera toward terrain
441+
mCameraPose.setPitchAngle( pitch );
442+
updateCameraFromPose();
441443
}
442444

443-
void QgsCameraController::rotateAroundViewCenter(float deltaYaw){
444-
// Rotate clockwise the view by deltaYaw around the view center (camera moves)
445-
float yaw = mCameraPose.headingAngle();
446-
yaw -= deltaYaw; // right key = moving camera clockwise
447-
mCameraPose.setHeadingAngle( yaw );
448-
updateCameraFromPose();
449-
qInfo() << "Delta yaw: " << deltaYaw;
450-
qInfo() << "Yaw: " << yaw;
445+
void QgsCameraController::rotateAroundViewCenter( float deltaYaw )
446+
{
447+
// Rotate clockwise the view by deltaYaw around the view center (camera moves)
448+
float yaw = mCameraPose.headingAngle();
449+
yaw -= deltaYaw; // right key = moving camera clockwise
450+
mCameraPose.setHeadingAngle( yaw );
451+
updateCameraFromPose();
452+
qInfo() << "Delta yaw: " << deltaYaw;
453+
qInfo() << "Yaw: " << yaw;
451454
}
452455

453-
void QgsCameraController::setCameraHeadingAngle(float angle){
454-
mCameraPose.setHeadingAngle( angle );
455-
updateCameraFromPose();
456+
void QgsCameraController::setCameraHeadingAngle( float angle )
457+
{
458+
mCameraPose.setHeadingAngle( angle );
459+
updateCameraFromPose();
456460
}
457461

458-
void QgsCameraController::moveView(float tx, float ty){
459-
float yaw = mCameraPose.headingAngle();
460-
float dist = mCameraPose.distanceFromCenterPoint();
461-
float x = tx * dist * 0.02f;
462-
float y = -ty * dist * 0.02f;
463-
464-
// moving with keyboard - take into account yaw of camera
465-
float t = sqrt( x * x + y * y );
466-
float a = atan2( y, x ) - yaw * M_PI / 180;
467-
float dx = cos( a ) * t;
468-
float dy = sin( a ) * t;
469-
470-
QgsVector3D center = mCameraPose.centerPoint();
471-
center.set( center.x() + dx, center.y(), center.z() + dy );
472-
mCameraPose.setCenterPoint( center );
473-
updateCameraFromPose( true );
462+
void QgsCameraController::moveView( float tx, float ty )
463+
{
464+
float yaw = mCameraPose.headingAngle();
465+
float dist = mCameraPose.distanceFromCenterPoint();
466+
float x = tx * dist * 0.02f;
467+
float y = -ty * dist * 0.02f;
468+
469+
// moving with keyboard - take into account yaw of camera
470+
float t = sqrt( x * x + y * y );
471+
float a = atan2( y, x ) - yaw * M_PI / 180;
472+
float dx = cos( a ) * t;
473+
float dy = sin( a ) * t;
474+
475+
QgsVector3D center = mCameraPose.centerPoint();
476+
center.set( center.x() + dx, center.y(), center.z() + dy );
477+
mCameraPose.setCenterPoint( center );
478+
updateCameraFromPose( true );
474479
}

‎src/3d/qgscameracontroller.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
135135
//! Reads camera configuration from the given DOM element
136136
void readXml( const QDomElement &elem );
137137

138-
void zoom(float factor);
139-
void tiltUpAroundViewCenter(float deltaPitch);
140-
void rotateAroundViewCenter(float deltaYaw);
141-
void setCameraHeadingAngle(float angle);
142-
void moveView(float tx, float ty);
138+
void zoom( float factor );
139+
void tiltUpAroundViewCenter( float deltaPitch );
140+
void rotateAroundViewCenter( float deltaYaw );
141+
void setCameraHeadingAngle( float angle );
142+
void moveView( float tx, float ty );
143143

144144
private:
145145
void rotateCamera( float diffPitch, float diffYaw );

‎src/app/3d/qgs3dmapcanvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Qgs3DMapCanvas : public QWidget
7676
/**
7777
* Set the visibility of on-screen navigation widget.
7878
*/
79-
void setOnScreenNavigationVisibility(bool visibility);
79+
void setOnScreenNavigationVisibility( bool visibility );
8080

8181
signals:
8282
//! Emitted when the 3D map canvas was successfully saved as image

‎src/app/3d/qgs3dnavigationwidget.cpp

Lines changed: 170 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -26,172 +26,182 @@
2626
#include "qgs3dnavigationwidget.h"
2727

2828

29-
Qgs3DNavigationWidget::Qgs3DNavigationWidget(Qgs3DMapCanvas *parent) : QWidget(parent)
29+
Qgs3DNavigationWidget::Qgs3DNavigationWidget( Qgs3DMapCanvas *parent ) : QWidget( parent )
3030
{
31-
mParent3DMapCanvas = parent;
32-
// Zoom in button
33-
mZoomInButton = new QToolButton(this);
34-
mZoomInButton->setToolTip(tr("Zoom In"));
35-
mZoomInButton->setAutoRepeat(true);
36-
mZoomInButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomIn.svg" ) ) );
37-
mZoomInButton->setAutoRaise(true);
38-
39-
QObject::connect(
40-
mZoomInButton,
41-
&QToolButton::clicked,
42-
parent,
43-
[ = ]{
44-
parent->cameraController()->zoom(5);
45-
}
46-
);
47-
48-
// Zoom out button
49-
mZoomOutButton = new QToolButton(this);
50-
mZoomOutButton->setToolTip(tr("Zoom Out"));
51-
mZoomOutButton->setAutoRepeat(true);
52-
mZoomOutButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomOut.svg" ) ) );
53-
mZoomOutButton->setAutoRaise(true);
54-
55-
QObject::connect(
56-
mZoomOutButton,
57-
&QToolButton::clicked,
58-
parent,
59-
[ = ]{
60-
parent->cameraController()->zoom(-5);
61-
}
62-
);
63-
64-
// Tilt up button
65-
mTiltUpButton = new QToolButton(this);
66-
mTiltUpButton->setToolTip(tr("Tilt Up"));
67-
mTiltUpButton->setAutoRepeat(true);
68-
mTiltUpButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionTiltUp.svg" ) ) );
69-
mTiltUpButton->setAutoRaise(true);
70-
71-
QObject::connect(
72-
mTiltUpButton,
73-
&QToolButton::clicked,
74-
parent,
75-
[ = ]{
76-
parent->cameraController()->tiltUpAroundViewCenter(1);
77-
}
78-
);
79-
80-
// Tilt down button
81-
mTiltDownButton = new QToolButton(this);
82-
mTiltDownButton->setToolTip(tr("Tilt Down"));
83-
mTiltDownButton->setAutoRepeat(true);
84-
mTiltDownButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionTiltDown.svg" ) ) );
85-
mTiltDownButton->setAutoRaise(true);
86-
87-
QObject::connect(
88-
mTiltDownButton,
89-
&QToolButton::clicked,
90-
parent,
91-
[ = ]{
92-
parent->cameraController()->tiltUpAroundViewCenter(-1);
93-
}
94-
);
95-
96-
// Compas
97-
QwtCompassMagnetNeedle *compasNeedle = new QwtCompassMagnetNeedle();
98-
mCompas = new QwtCompass(this);
99-
mCompas->setToolTip(tr("Rotate view"));
100-
mCompas->setWrapping(true);
101-
mCompas->setNeedle(compasNeedle);
102-
103-
QObject::connect(
104-
mCompas,
105-
&QwtDial::valueChanged,
106-
parent,
107-
[ = ]{
108-
parent->cameraController()->setCameraHeadingAngle(float(mCompas->value()));
109-
}
110-
);
111-
112-
// Move up button
113-
mMoveUpButton = new QToolButton(this);
114-
mMoveUpButton->setToolTip(tr("Move up"));
115-
mMoveUpButton->setAutoRepeat(true);
116-
mMoveUpButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowUp.svg" ) ) );
117-
mMoveUpButton->setAutoRaise(true);
118-
119-
QObject::connect(
120-
mMoveUpButton,
121-
&QToolButton::clicked,
122-
parent,
123-
[ = ]{
124-
parent->cameraController()->moveView(0, 1);
125-
}
126-
);
127-
128-
// Move right button
129-
mMoveRightButton = new QToolButton(this);
130-
mMoveRightButton->setToolTip(tr("Move right"));
131-
mMoveRightButton->setAutoRepeat(true);
132-
mMoveRightButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowRight.svg" ) ) );
133-
mMoveRightButton->setAutoRaise(true);
134-
135-
QObject::connect(
136-
mMoveRightButton,
137-
&QToolButton::clicked,
138-
parent,
139-
[ = ]{
140-
parent->cameraController()->moveView(1, 0);
141-
}
142-
);
143-
144-
// Move down button
145-
mMoveDownButton = new QToolButton(this);
146-
mMoveDownButton->setToolTip(tr("Move down"));
147-
mMoveDownButton->setAutoRepeat(true);
148-
mMoveDownButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowDown.svg" ) ) );
149-
mMoveDownButton->setAutoRaise(true);
150-
151-
QObject::connect(
152-
mMoveDownButton,
153-
&QToolButton::clicked,
154-
parent,
155-
[ = ]{
156-
parent->cameraController()->moveView(0, -1);
157-
}
158-
);
159-
160-
// Move left button
161-
mMoveLeftButton = new QToolButton(this);
162-
mMoveLeftButton->setToolTip(tr("Move left"));
163-
mMoveLeftButton->setAutoRepeat(true);
164-
mMoveLeftButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowLeft.svg" ) ) );
165-
mMoveLeftButton->setAutoRaise(true);
166-
167-
QObject::connect(
168-
mMoveLeftButton,
169-
&QToolButton::clicked,
170-
parent,
171-
[ = ]{
172-
parent->cameraController()->moveView(-1, 0);
173-
}
174-
);
175-
176-
QGridLayout *gridLayout = new QGridLayout(this);
177-
gridLayout->addWidget(mTiltUpButton, 0, 0);
178-
gridLayout->addWidget(mTiltDownButton, 3, 0);
179-
gridLayout->addWidget(mZoomInButton, 0, 3);
180-
gridLayout->addWidget(mZoomOutButton, 3, 3);
181-
gridLayout->addWidget(mCompas, 1, 1, 2, 2);
182-
gridLayout->addWidget(mMoveUpButton, 0, 1, 1, 2, Qt::AlignCenter);
183-
gridLayout->addWidget(mMoveRightButton, 1, 3, 2, 1, Qt::AlignCenter);
184-
gridLayout->addWidget(mMoveDownButton, 3, 1, 1, 2, Qt::AlignCenter);
185-
gridLayout->addWidget(mMoveLeftButton, 1, 0, 2, 1, Qt::AlignCenter);
186-
gridLayout->setAlignment(Qt::AlignTop);
31+
mParent3DMapCanvas = parent;
32+
// Zoom in button
33+
mZoomInButton = new QToolButton( this );
34+
mZoomInButton->setToolTip( tr( "Zoom In" ) );
35+
mZoomInButton->setAutoRepeat( true );
36+
mZoomInButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomIn.svg" ) ) );
37+
mZoomInButton->setAutoRaise( true );
38+
39+
QObject::connect(
40+
mZoomInButton,
41+
&QToolButton::clicked,
42+
parent,
43+
[ = ]
44+
{
45+
parent->cameraController()->zoom( 5 );
46+
}
47+
);
48+
49+
// Zoom out button
50+
mZoomOutButton = new QToolButton( this );
51+
mZoomOutButton->setToolTip( tr( "Zoom Out" ) );
52+
mZoomOutButton->setAutoRepeat( true );
53+
mZoomOutButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionZoomOut.svg" ) ) );
54+
mZoomOutButton->setAutoRaise( true );
55+
56+
QObject::connect(
57+
mZoomOutButton,
58+
&QToolButton::clicked,
59+
parent,
60+
[ = ]
61+
{
62+
parent->cameraController()->zoom( -5 );
63+
}
64+
);
65+
66+
// Tilt up button
67+
mTiltUpButton = new QToolButton( this );
68+
mTiltUpButton->setToolTip( tr( "Tilt Up" ) );
69+
mTiltUpButton->setAutoRepeat( true );
70+
mTiltUpButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionTiltUp.svg" ) ) );
71+
mTiltUpButton->setAutoRaise( true );
72+
73+
QObject::connect(
74+
mTiltUpButton,
75+
&QToolButton::clicked,
76+
parent,
77+
[ = ]
78+
{
79+
parent->cameraController()->tiltUpAroundViewCenter( 1 );
80+
}
81+
);
82+
83+
// Tilt down button
84+
mTiltDownButton = new QToolButton( this );
85+
mTiltDownButton->setToolTip( tr( "Tilt Down" ) );
86+
mTiltDownButton->setAutoRepeat( true );
87+
mTiltDownButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionTiltDown.svg" ) ) );
88+
mTiltDownButton->setAutoRaise( true );
89+
90+
QObject::connect(
91+
mTiltDownButton,
92+
&QToolButton::clicked,
93+
parent,
94+
[ = ]
95+
{
96+
parent->cameraController()->tiltUpAroundViewCenter( -1 );
97+
}
98+
);
99+
100+
// Compas
101+
QwtCompassMagnetNeedle *compasNeedle = new QwtCompassMagnetNeedle();
102+
mCompas = new QwtCompass( this );
103+
mCompas->setToolTip( tr( "Rotate view" ) );
104+
mCompas->setWrapping( true );
105+
mCompas->setNeedle( compasNeedle );
106+
107+
QObject::connect(
108+
mCompas,
109+
&QwtDial::valueChanged,
110+
parent,
111+
[ = ]
112+
{
113+
parent->cameraController()->setCameraHeadingAngle( float( mCompas->value() ) );
114+
}
115+
);
116+
117+
// Move up button
118+
mMoveUpButton = new QToolButton( this );
119+
mMoveUpButton->setToolTip( tr( "Move up" ) );
120+
mMoveUpButton->setAutoRepeat( true );
121+
mMoveUpButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowUp.svg" ) ) );
122+
mMoveUpButton->setAutoRaise( true );
123+
124+
QObject::connect(
125+
mMoveUpButton,
126+
&QToolButton::clicked,
127+
parent,
128+
[ = ]
129+
{
130+
parent->cameraController()->moveView( 0, 1 );
131+
}
132+
);
133+
134+
// Move right button
135+
mMoveRightButton = new QToolButton( this );
136+
mMoveRightButton->setToolTip( tr( "Move right" ) );
137+
mMoveRightButton->setAutoRepeat( true );
138+
mMoveRightButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowRight.svg" ) ) );
139+
mMoveRightButton->setAutoRaise( true );
140+
141+
QObject::connect(
142+
mMoveRightButton,
143+
&QToolButton::clicked,
144+
parent,
145+
[ = ]
146+
{
147+
parent->cameraController()->moveView( 1, 0 );
148+
}
149+
);
150+
151+
// Move down button
152+
mMoveDownButton = new QToolButton( this );
153+
mMoveDownButton->setToolTip( tr( "Move down" ) );
154+
mMoveDownButton->setAutoRepeat( true );
155+
mMoveDownButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowDown.svg" ) ) );
156+
mMoveDownButton->setAutoRaise( true );
157+
158+
QObject::connect(
159+
mMoveDownButton,
160+
&QToolButton::clicked,
161+
parent,
162+
[ = ]
163+
{
164+
parent->cameraController()->moveView( 0, -1 );
165+
}
166+
);
167+
168+
// Move left button
169+
mMoveLeftButton = new QToolButton( this );
170+
mMoveLeftButton->setToolTip( tr( "Move left" ) );
171+
mMoveLeftButton->setAutoRepeat( true );
172+
mMoveLeftButton->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionArrowLeft.svg" ) ) );
173+
mMoveLeftButton->setAutoRaise( true );
174+
175+
QObject::connect(
176+
mMoveLeftButton,
177+
&QToolButton::clicked,
178+
parent,
179+
[ = ]
180+
{
181+
parent->cameraController()->moveView( -1, 0 );
182+
}
183+
);
184+
185+
QGridLayout *gridLayout = new QGridLayout( this );
186+
gridLayout->addWidget( mTiltUpButton, 0, 0 );
187+
gridLayout->addWidget( mTiltDownButton, 3, 0 );
188+
gridLayout->addWidget( mZoomInButton, 0, 3 );
189+
gridLayout->addWidget( mZoomOutButton, 3, 3 );
190+
gridLayout->addWidget( mCompas, 1, 1, 2, 2 );
191+
gridLayout->addWidget( mMoveUpButton, 0, 1, 1, 2, Qt::AlignCenter );
192+
gridLayout->addWidget( mMoveRightButton, 1, 3, 2, 1, Qt::AlignCenter );
193+
gridLayout->addWidget( mMoveDownButton, 3, 1, 1, 2, Qt::AlignCenter );
194+
gridLayout->addWidget( mMoveLeftButton, 1, 0, 2, 1, Qt::AlignCenter );
195+
gridLayout->setAlignment( Qt::AlignTop );
187196
}
188197

189198
Qgs3DNavigationWidget::~Qgs3DNavigationWidget()
190199
{
191200

192201
}
193202

194-
void Qgs3DNavigationWidget::updateFromCamera(){
195-
// Make sure the angle is between 0 - 359
196-
mCompas->setValue((int(mParent3DMapCanvas->cameraController()->yaw()) % 360 + 360) % 360);
203+
void Qgs3DNavigationWidget::updateFromCamera()
204+
{
205+
// Make sure the angle is between 0 - 359
206+
mCompas->setValue( ( int( mParent3DMapCanvas->cameraController()->yaw() ) % 360 + 360 ) % 360 );
197207
}

‎src/app/3d/qgs3dnavigationwidget.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828
class Qgs3DNavigationWidget : public QWidget
2929
{
3030
Q_OBJECT
31-
public:
32-
Qgs3DNavigationWidget(Qgs3DMapCanvas *parent = nullptr);
31+
public:
32+
Qgs3DNavigationWidget( Qgs3DMapCanvas *parent = nullptr );
3333
~Qgs3DNavigationWidget();
3434

3535
/**
3636
* Update the state of navigation widget from camera's state
3737
*/
3838
void updateFromCamera();
3939

40-
signals:
40+
signals:
4141

42-
public slots:
42+
public slots:
4343

44-
private:
44+
private:
4545
Qgs3DMapCanvas *mParent3DMapCanvas = nullptr;
4646
QToolButton *mZoomInButton = nullptr;
4747
QToolButton *mZoomOutButton = nullptr;

0 commit comments

Comments
 (0)
Please sign in to comment.