|
| 1 | +/*************************************************************************** |
| 2 | + qgs3dmaptoolidentify.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : Sep 2018 |
| 5 | + Copyright : (C) 2018 by Martin Dobias |
| 6 | + Email : wonder dot sk at gmail dot com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#include "qgs3dmaptoolidentify.h" |
| 17 | + |
| 18 | +#include "qgs3dmapcanvas.h" |
| 19 | +#include "qgs3dmapscene.h" |
| 20 | +#include "qgs3dutils.h" |
| 21 | +#include "qgsterrainentity_p.h" |
| 22 | + |
| 23 | +#include "qgisapp.h" |
| 24 | +#include "qgsmaptoolidentifyaction.h" |
| 25 | + |
| 26 | +#include <Qt3DRender/QObjectPicker> |
| 27 | +#include <Qt3DRender/QPickEvent> |
| 28 | + |
| 29 | +Qgs3DMapToolIdentify::Qgs3DMapToolIdentify( Qgs3DMapCanvas *canvas ) |
| 30 | + : Qgs3DMapTool( canvas ) |
| 31 | +{ |
| 32 | + connect( mCanvas->scene(), &Qgs3DMapScene::terrainEntityChanged, this, &Qgs3DMapToolIdentify::onTerrainEntityChanged ); |
| 33 | +} |
| 34 | + |
| 35 | +void Qgs3DMapToolIdentify::mousePressEvent( QMouseEvent *event ) |
| 36 | +{ |
| 37 | + Q_UNUSED( event ); |
| 38 | + |
| 39 | + QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool(); |
| 40 | + identifyTool2D->clearResults(); |
| 41 | +} |
| 42 | + |
| 43 | +void Qgs3DMapToolIdentify::activate() |
| 44 | +{ |
| 45 | + Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker(); |
| 46 | + connect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapToolIdentify::onTerrainPicked ); |
| 47 | +} |
| 48 | + |
| 49 | +void Qgs3DMapToolIdentify::deactivate() |
| 50 | +{ |
| 51 | + Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker(); |
| 52 | + disconnect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapToolIdentify::onTerrainPicked ); |
| 53 | +} |
| 54 | + |
| 55 | +void Qgs3DMapToolIdentify::onTerrainPicked( Qt3DRender::QPickEvent *event ) |
| 56 | +{ |
| 57 | + QgsVector3D mapCoords = Qgs3DUtils::worldToMapCoordinates( event->worldIntersection(), mCanvas->map()->origin() ); |
| 58 | + |
| 59 | + QgsGeometry geom = QgsGeometry::fromPointXY( QgsPointXY( mapCoords.x(), mapCoords.y() ) ); |
| 60 | + |
| 61 | + QgsMapToolIdentifyAction *identifyTool2D = QgisApp::instance()->identifyMapTool(); |
| 62 | + |
| 63 | + identifyTool2D->identifyAndShowResults( geom ); |
| 64 | +} |
| 65 | + |
| 66 | +void Qgs3DMapToolIdentify::onTerrainEntityChanged() |
| 67 | +{ |
| 68 | + // no need to disconnect from the previous entity: it has been destroyed |
| 69 | + // start listening to the new terrain entity |
| 70 | + Qt3DRender::QObjectPicker *picker = mCanvas->scene()->terrainEntity()->terrainPicker(); |
| 71 | + connect( picker, &Qt3DRender::QObjectPicker::pressed, this, &Qgs3DMapToolIdentify::onTerrainPicked ); |
| 72 | +} |
0 commit comments