-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on integration of 3D map into QGIS application
One can create a 3D map view from menu similar to a new 3D map view
- Loading branch information
Showing
15 changed files
with
396 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "qgs3dmapcanvas.h" | ||
|
||
#include <QBoxLayout> | ||
#include <Qt3DExtras/Qt3DWindow> | ||
|
||
#include "cameracontroller.h" | ||
#include "map3d.h" | ||
#include "scene.h" | ||
|
||
|
||
Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent ) | ||
: QWidget( parent ) | ||
, mWindow3D( nullptr ) | ||
, mContainer( nullptr ) | ||
, mMap( nullptr ) | ||
, mScene( nullptr ) | ||
{ | ||
mWindow3D = new Qt3DExtras::Qt3DWindow; | ||
mContainer = QWidget::createWindowContainer( mWindow3D ); | ||
|
||
QHBoxLayout *hLayout = new QHBoxLayout( this ); | ||
hLayout->setMargin( 0 ); | ||
hLayout->addWidget( mContainer, 1 ); | ||
} | ||
|
||
Qgs3DMapCanvas::~Qgs3DMapCanvas() | ||
{ | ||
delete mMap; | ||
} | ||
|
||
void Qgs3DMapCanvas::resizeEvent( QResizeEvent *ev ) | ||
{ | ||
QWidget::resizeEvent( ev ); | ||
|
||
QRect viewportRect( QPoint( 0, 0 ), size() ); | ||
mScene->cameraController()->setViewport( viewportRect ); | ||
} | ||
|
||
void Qgs3DMapCanvas::setMap( Map3D *map ) | ||
{ | ||
QRect viewportRect( QPoint( 0, 0 ), size() ); | ||
Scene *newScene = new Scene( *map, mWindow3D->defaultFrameGraph(), mWindow3D->renderSettings(), mWindow3D->camera(), viewportRect ); | ||
|
||
mWindow3D->setRootEntity( newScene ); | ||
|
||
if ( mScene ) | ||
mScene->deleteLater(); | ||
mScene = newScene; | ||
|
||
delete mMap; | ||
mMap = map; | ||
} | ||
|
||
void Qgs3DMapCanvas::resetView() | ||
{ | ||
mScene->cameraController()->resetView(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef QGS3DMAPWIDGET_H | ||
#define QGS3DMAPWIDGET_H | ||
|
||
#include <QWidget> | ||
|
||
namespace Qt3DExtras | ||
{ | ||
class Qt3DWindow; | ||
} | ||
|
||
class Map3D; | ||
class Scene; | ||
|
||
|
||
class Qgs3DMapCanvas : public QWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
Qgs3DMapCanvas( QWidget *parent = nullptr ); | ||
~Qgs3DMapCanvas(); | ||
|
||
//! Configure map scene being displayed. Takes ownership. | ||
void setMap( Map3D *map ); | ||
|
||
//! Resets camera position to the default: looking down at the origin of world coordinates | ||
void resetView(); | ||
|
||
protected: | ||
void resizeEvent( QResizeEvent *ev ) override; | ||
|
||
private: | ||
//! 3D window with all the 3D magic inside | ||
Qt3DExtras::Qt3DWindow *mWindow3D; | ||
//! Container QWidget that encapsulates mWindow3D so we can use it embedded in ordinary widgets app | ||
QWidget *mContainer; | ||
//! Description of the 3D scene | ||
Map3D *mMap; | ||
//! Root entity of the 3D scene | ||
Scene *mScene; | ||
}; | ||
|
||
#endif // QGS3DMAPWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "qgs3dmapcanvasdockwidget.h" | ||
|
||
#include "qgs3dmapcanvas.h" | ||
|
||
#include <QBoxLayout> | ||
#include <QToolBar> | ||
|
||
Qgs3DMapCanvasDockWidget::Qgs3DMapCanvasDockWidget( QWidget *parent ) | ||
: QgsDockWidget( parent ) | ||
{ | ||
QWidget *contentsWidget = new QWidget( this ); | ||
|
||
QToolBar *toolBar = new QToolBar( contentsWidget ); | ||
toolBar->addAction( "Reset view", this, &Qgs3DMapCanvasDockWidget::resetView ); | ||
|
||
mCanvas = new Qgs3DMapCanvas( contentsWidget ); | ||
mCanvas->setMinimumSize( QSize( 200, 200 ) ); | ||
|
||
QVBoxLayout *layout = new QVBoxLayout( contentsWidget ); | ||
layout->setContentsMargins( 0, 0, 0, 0 ); | ||
layout->setSpacing( 0 ); | ||
layout->addWidget( toolBar ); | ||
layout->addWidget( mCanvas, 1 ); | ||
|
||
setWidget( contentsWidget ); | ||
} | ||
|
||
void Qgs3DMapCanvasDockWidget::setMap( Map3D *map ) | ||
{ | ||
mCanvas->setMap( map ); | ||
} | ||
|
||
void Qgs3DMapCanvasDockWidget::resetView() | ||
{ | ||
mCanvas->resetView(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef QGS3DMAPCANVASDOCKWIDGET_H | ||
#define QGS3DMAPCANVASDOCKWIDGET_H | ||
|
||
#include "qgsdockwidget.h" | ||
|
||
class Qgs3DMapCanvas; | ||
|
||
class Map3D; | ||
|
||
|
||
class Qgs3DMapCanvasDockWidget : public QgsDockWidget | ||
{ | ||
Q_OBJECT | ||
public: | ||
Qgs3DMapCanvasDockWidget( QWidget *parent = nullptr ); | ||
|
||
//! takes ownership | ||
void setMap( Map3D *map ); | ||
|
||
private slots: | ||
void resetView(); | ||
|
||
private: | ||
Qgs3DMapCanvas *mCanvas; | ||
}; | ||
|
||
#endif // QGS3DMAPCANVASDOCKWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.