Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Added identify and highlight feature #10

Closed
wants to merge 12 commits into from
9 changes: 0 additions & 9 deletions src/3d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SET(QGIS_3D_SRCS
qgscameracontroller.cpp
qgsphongmaterialsettings.cpp
qgstessellatedpolygongeometry.cpp
qgstessellator.cpp
qgstilingscheme.cpp
qgsvectorlayer3drenderer.cpp

Expand Down Expand Up @@ -41,12 +40,6 @@ SET(QGIS_3D_SRCS
terrain/qgsterraintileloader_p.cpp
#terrain/quantizedmeshgeometry.cpp
#terrain/quantizedmeshterraingenerator.cpp

${CMAKE_SOURCE_DIR}/external/poly2tri/common/shapes.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/advancing_front.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/cdt.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep_context.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep.cc
)

SET(QGIS_3D_MOC_HDRS
Expand Down Expand Up @@ -82,7 +75,6 @@ SET(QGIS_3D_HDRS
qgscameracontroller.h
qgsphongmaterialsettings.h
qgstessellatedpolygongeometry.h
qgstessellator.h
qgstilingscheme.h
qgsvectorlayer3drenderer.h

Expand Down Expand Up @@ -127,7 +119,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/3d
${CMAKE_SOURCE_DIR}/external/poly2tri
${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/3d
)
Expand Down
10 changes: 10 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ SET(QGIS_CORE_SRCS
${CMAKE_SOURCE_DIR}/external/nmea/time.c
${CMAKE_SOURCE_DIR}/external/nmea/tok.c

${CMAKE_SOURCE_DIR}/external/poly2tri/common/shapes.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/advancing_front.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/cdt.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep_context.cc
${CMAKE_SOURCE_DIR}/external/poly2tri/sweep/sweep.cc

gps/qgsgpsconnection.cpp
gps/qgsgpsconnectionregistry.cpp
gps/qgsgpsdconnection.cpp
Expand Down Expand Up @@ -291,6 +297,7 @@ SET(QGIS_CORE_SRCS
qgsstringstatisticalsummary.cpp
qgsstringutils.cpp
qgstaskmanager.cpp
qgstessellator.cpp
qgstextlabelfeature.cpp
qgstextrenderer.cpp
qgstolerance.cpp
Expand Down Expand Up @@ -808,6 +815,8 @@ SET(QGIS_CORE_HDRS
expression/qgsexpressionnodeimpl.h
expression/qgsexpressionfunction.h

qgstessellator.h

qgis.h
qgis_sip.h
qgsaction.h
Expand Down Expand Up @@ -1198,6 +1207,7 @@ INCLUDE_DIRECTORIES(
metadata
mesh
${CMAKE_SOURCE_DIR}/external/nmea
${CMAKE_SOURCE_DIR}/external/poly2tri
)
IF (WITH_INTERNAL_QEXTSERIALPORT)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/external/qextserialport)
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/3d/qgstessellator.h → src/core/qgstessellator.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#ifndef QGSTESSELLATOR_H
#define QGSTESSELLATOR_H

#include "qgis_3d.h"
#include "qgis_core.h"

class QgsPolygon;
class QgsMultiPolygon;
Expand All @@ -33,9 +33,9 @@ class QgsMultiPolygon;
*
* Optionally provides extrusion by adding triangles that serve as walls when extrusion height is non-zero.
*
* \since QGIS 3.0
* \since QGIS 3.2 (since QGIS 3.0 in QGIS_3D library)
*/
class _3D_EXPORT QgsTessellator
class CORE_EXPORT QgsTessellator
{
public:
//! Creates tessellator with a specified origin point of the world (in map coordinates)
Expand Down
13 changes: 11 additions & 2 deletions src/quickgui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
############################################################
# sources
SET(QGIS_QUICK_GUI_MOC_HDRS
qgsquickfeaturelayerpair.h
qgsquickfeaturehighlight.h
qgsquickidentifykit.h
qgsquickmapcanvasmap.h
qgsquickmapsettings.h
qgsquickmaptransform.h
qgsquickmessagelogmodel.h
qgsquickscalebarkit.h
qgsquickutils.h
)

SET(QGIS_QUICK_GUI_HDRS
qgsquickhighlightsgnode.h
)

SET(QGIS_QUICK_GUI_SRC
qgsquickfeaturelayerpair.cpp
qgsquickfeaturehighlight.cpp
qgsquickhighlightsgnode.cpp
qgsquickidentifykit.cpp
qgsquickmapcanvasmap.cpp
qgsquickmapsettings.cpp
qgsquickmaptransform.cpp
qgsquickmessagelogmodel.cpp
qgsquickscalebarkit.cpp
qgsquickutils.cpp
Expand Down Expand Up @@ -85,7 +95,6 @@ GENERATE_EXPORT_HEADER(
BASE_NAME QUICK
EXPORT_FILE_NAME qgis_quick.h
)
SET(QGIS_CORE_HDRS ${QGIS_QUICK_GUI_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/qgis_core.h)

# Installation
INSTALL(TARGETS qgis_quick
Expand All @@ -96,7 +105,7 @@ INSTALL(TARGETS qgis_quick
PUBLIC_HEADER DESTINATION ${QGIS_INCLUDE_DIR})

IF(NOT APPLE)
INSTALL(FILES ${QGIS_QUICK_GUI_HDRS} ${QGIS_QUICK_GUI_MOC_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/qgis_quick.h ${QGIS_QUICK_GUI_HDRS} ${QGIS_QUICK_GUI_MOC_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
ELSE(NOT APPLE)
SET_TARGET_PROPERTIES(qgis_quick PROPERTIES
CLEAN_DIRECT_OUTPUT 1
Expand Down
8 changes: 8 additions & 0 deletions src/quickgui/plugin/qgsquickplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
#include "qgscoordinatetransformcontext.h"
#include "qgsvectorlayer.h"

#include "qgsquickfeaturehighlight.h"
#include "qgsquickidentifykit.h"
#include "qgsquickfeaturelayerpair.h"
#include "qgsquickmapcanvasmap.h"
#include "qgsquickmapsettings.h"
#include "qgsquickmaptransform.h"
#include "qgsquickmessagelogmodel.h"
#include "qgsquickplugin.h"
#include "qgsquickscalebarkit.h"
Expand All @@ -53,10 +57,14 @@ void QgsQuickPlugin::registerTypes( const char *uri )
qRegisterMetaType< QgsFeatureId > ( "QgsFeatureId" );
qRegisterMetaType< QgsPoint >( "QgsPoint" );
qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );

qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
qmlRegisterType< QgsQuickIdentifyKit >( uri, 0, 1, "IdentifyKit" );
qmlRegisterType< QgsQuickMapCanvasMap >( uri, 0, 1, "MapCanvasMap" );
qmlRegisterType< QgsQuickMapSettings >( uri, 0, 1, "MapSettings" );
qmlRegisterType< QgsQuickMapTransform >( uri, 0, 1, "MapTransform" );
qmlRegisterType< QgsQuickMessageLogModel >( uri, 0, 1, "MessageLogModel" );
qmlRegisterType< QgsQuickScaleBarKit >( uri, 0, 1, "ScaleBarKit" );
qmlRegisterType< QgsVectorLayer >( uri, 0, 1, "VectorLayer" );
Expand Down
68 changes: 68 additions & 0 deletions src/quickgui/qgsquickfeaturehighlight.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/***************************************************************************
qgsqguickfeaturehighlight.cpp
--------------------------------------
Date : May 2018
Copyright : (C) 2018 by Peter Petrik
Email : zilolv at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <memory>

#include "qgsvectorlayer.h"

#include "qgsquickfeaturehighlight.h"
#include "qgsquickmapsettings.h"
#include "qgsquickhighlightsgnode.h"


QgsQuickFeatureHighlight::QgsQuickFeatureHighlight( QQuickItem *parent )
: QQuickItem( parent )
{
setFlags( QQuickItem::ItemHasContents );
setAntialiasing( true );

connect( this, &QgsQuickFeatureHighlight::mapSettingsChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::featureLayerPairChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::colorChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::widthChanged, this, &QgsQuickFeatureHighlight::markDirty );
}

void QgsQuickFeatureHighlight::markDirty()
{
mDirty = true;
update();
}

QSGNode *QgsQuickFeatureHighlight::updatePaintNode( QSGNode *n, QQuickItem::UpdatePaintNodeData * )
{
if ( !mDirty || !mMapSettings || !mFeatureLayerPair.isValid() )
return n;

delete n;
n = new QSGNode;

QgsVectorLayer *layer = mFeatureLayerPair.layer();
Q_ASSERT( layer ); // we checked the validity of feature-layer pair
QgsCoordinateTransform transf( layer->crs(), mMapSettings->destinationCrs(), mMapSettings->transformContext() );

QgsFeature feature = mFeatureLayerPair.feature();
if ( feature.hasGeometry() )
{
QgsGeometry geom( feature.geometry() );
geom.transform( transf );
std::unique_ptr<QgsQuickHighlightSGNode> rb( new QgsQuickHighlightSGNode( geom, mColor, mWidth ) );
rb->setFlag( QSGNode::OwnedByParent );
n->appendChildNode( rb.release() );
}

mDirty = false;

return n;
}
95 changes: 95 additions & 0 deletions src/quickgui/qgsquickfeaturehighlight.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/***************************************************************************
qgsqguickfeaturehighlight.h
---------------------------
Date : May 2018
Copyright : (C) 2018 by Peter Petrik
Email : zilolv at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSQUICKFEATUREHIGHLIGHT_H
#define QGSQUICKFEATUREHIGHLIGHT_H

#include <QQuickItem>

#include "qgsquickfeaturelayerpair.h"
#include "qgis_quick.h"

class QgsQuickMapSettings;

/**
* \ingroup quick
*
* Creates map highlights for a geometry provided by a FeatureModel.
*
* The highlights are compatible with the QtQuick scene graph.
*
* \note QML Type: FeatureModelHighlight
*
* \since QGIS 3.2
*/
class QUICK_EXPORT QgsQuickFeatureHighlight : public QQuickItem
{
Q_OBJECT

/**
* Associated map settings. Should be initialized from QML component before the first use.
*/
Q_PROPERTY( QgsQuickMapSettings *mapSettings MEMBER mMapSettings NOTIFY mapSettingsChanged )

/**
* Feature to highlight
*/
Q_PROPERTY( QgsQuickFeatureLayerPair featureLayerPair MEMBER mFeatureLayerPair NOTIFY featureLayerPairChanged )

/**
* Color of the highlighted geometry (feature).
*
* Default is yellow color
*/
Q_PROPERTY( QColor color MEMBER mColor NOTIFY colorChanged )

/**
* Pen width of the highlighted geometry (feature).
*
* Default is 20, see QSGGeometry::setLineWidth()
*/
Q_PROPERTY( float width MEMBER mWidth NOTIFY widthChanged )

public:
//! Creates a new feature highlight
explicit QgsQuickFeatureHighlight( QQuickItem *parent = nullptr );

signals:
//! \copydoc QgsQuickFeatureHighlight::featureLayerPair
void featureLayerPairChanged();

//! \copydoc QgsQuickFeatureHighlight::color
void colorChanged();

//! \copydoc QgsQuickFeatureHighlight::width
void widthChanged();

//! \copydoc QgsQuickFeatureHighlight::mapSettings
void mapSettingsChanged();

private slots:
void markDirty();

private:
QSGNode *updatePaintNode( QSGNode *n, UpdatePaintNodeData * ) override;

QColor mColor = Qt::yellow;
bool mDirty = false;
float mWidth = 20;
QgsQuickFeatureLayerPair mFeatureLayerPair;
QgsQuickMapSettings *mMapSettings = nullptr; // not owned
};

#endif // QGSQUICKFEATUREHIGHLIGHT_H
Loading