Skip to content
Permalink
Browse files

fixes for position kit and coordinate transformer

  • Loading branch information
PeterPetrik committed May 23, 2018
1 parent 31e1514 commit 7828dc49ee6d23c5d9fd107887e63253f3d72c0a
@@ -109,8 +109,9 @@ IF(QMLPLUGINDUMP_FOUND)
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:qgis_quick_plugin> ${QGIS_QUICK_TYPEINFO_GENERATE_DIR}
COMMAND ${QMLPLUGINDUMP_EXECUTABLE}
ARGS QgsQuick ${QGIS_QUICK_VERSION} . --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
ARGS QgsQuick ${QGIS_QUICK_VERSION} . -noinstantiate --output ${QGIS_QUICK_PLUGIN_TYPEINFO}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Generating qgsquick.qmltypes with qmlplugindump"
POST_BUILD
)
ENDIF()
@@ -28,6 +28,7 @@
#include "qgsrelationmanager.h"
#include "qgscoordinatetransformcontext.h"
#include "qgsvectorlayer.h"
#include "qgsunittypes.h"

#include "qgsquickfeaturehighlight.h"
#include "qgsquickcoordinatetransformer.h"
@@ -60,6 +61,7 @@ void QgsQuickPlugin::registerTypes( const char *uri )
qRegisterMetaType< QgsPoint >( "QgsPoint" );
qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );
qRegisterMetaType< QgsUnitTypes::DistanceUnit >( "QgsUnitTypes::DistanceUnit" );

qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
@@ -47,7 +47,7 @@ Item {
/**
* Whether circle representing accuracy of the position should be rendered.
*/
property var withAccuracy: true
property bool withAccuracy: true

/**
* Icon for position marker.
@@ -14,12 +14,12 @@
***************************************************************************/

#include "qgsquickcoordinatetransformer.h"
#include "qgslogger.h"

QgsQuickCoordinateTransformer::QgsQuickCoordinateTransformer( QObject *parent )
: QObject( parent )
{
mCoordinateTransform.setSourceCrs( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ) );
mCoordinateTransform.setContext( QgsCoordinateTransformContext() );
}

QgsPoint QgsQuickCoordinateTransformer::projectedPosition() const
@@ -32,7 +32,7 @@ QgsPoint QgsQuickCoordinateTransformer::sourcePosition() const
return mSourcePosition;
}

void QgsQuickCoordinateTransformer::setSourcePosition( QgsPoint sourcePosition )
void QgsQuickCoordinateTransformer::setSourcePosition( const QgsPoint &sourcePosition )
{
if ( mSourcePosition == sourcePosition )
return;
@@ -74,6 +74,11 @@ void QgsQuickCoordinateTransformer::setSourceCrs( const QgsCoordinateReferenceSy
updatePosition();
}

void QgsQuickCoordinateTransformer::setTransformContext( const QgsCoordinateTransformContext &context )
{
mCoordinateTransform.setContext( context );
}

void QgsQuickCoordinateTransformer::updatePosition()
{
double x = mSourcePosition.x();
@@ -88,10 +93,14 @@ void QgsQuickCoordinateTransformer::updatePosition()
z = 0;
}

if ( mMapSettings )
mCoordinateTransform.setContext( mMapSettings->transformContext() );

mCoordinateTransform.transformInPlace( x, y, z );
try
{
mCoordinateTransform.transformInPlace( x, y, z );
}
catch ( const QgsCsException &exp )
{
QgsDebugMsg( exp.what() );
}

mProjectedPosition = QgsPoint( x, y );
mProjectedPosition.addZValue( mSourcePosition.z() );
@@ -21,12 +21,17 @@
#include "qgspoint.h"

#include "qgis_quick.h"
#include "qgsquickmapsettings.h"
#include "qgscoordinatetransformcontext.h"
#include "qgscoordinatereferencesystem.h"
#include "qgspoint.h"

/**
* \ingroup quick
* Helper class for transform of coordinates (QgsPoint) to a different coordinate reference system.
*
* It requires connection of transformation context from mapSettings, source position and source CRS to
* calculate projected position in desired destination CRS
*
* \note QML Type: CoordinateTransformer
*
* \since QGIS 3.2
@@ -47,8 +52,8 @@ class QUICK_EXPORT QgsQuickCoordinateTransformer : public QObject
//! Source CRS, default 4326
Q_PROPERTY( QgsCoordinateReferenceSystem sourceCrs READ sourceCrs WRITE setSourceCrs NOTIFY sourceCrsChanged )

//! Map settings, for getting transformation context
Q_PROPERTY( QgsQuickMapSettings *mapSettings MEMBER mMapSettings NOTIFY mapSettingsChanged )
//! Transformation context, can be set from QgsQuickMapSettings::transformContext()
Q_PROPERTY( QgsCoordinateTransformContext transformContext WRITE setTransformContext )

public:
//! Creates new coordinate transformer
@@ -61,7 +66,7 @@ class QUICK_EXPORT QgsQuickCoordinateTransformer : public QObject
QgsPoint sourcePosition() const;

//!\copydoc QgsQuickCoordinateTransformer::sourcePosition
void setSourcePosition( QgsPoint sourcePosition );
void setSourcePosition( const QgsPoint &sourcePosition );

//!\copydoc QgsQuickCoordinateTransformer::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const;
@@ -75,29 +80,31 @@ class QUICK_EXPORT QgsQuickCoordinateTransformer : public QObject
//!\copydoc QgsQuickCoordinateTransformer::sourceCrs
void setSourceCrs( const QgsCoordinateReferenceSystem &sourceCrs );

//!\copydoc QgsQuickCoordinateTransformer::transformContext
void setTransformContext( const QgsCoordinateTransformContext &context );

signals:
//! Projected position changed
//!\copydoc QgsQuickCoordinateTransformer::projectedPosition
void projectedPositionChanged();

//! Source position changed
//!\copydoc QgsQuickCoordinateTransformer::sourcePosition
void sourcePositionChanged();

//! Destination CRS changed
//!\copydoc QgsQuickCoordinateTransformer::destinationCrs
void destinationCrsChanged();

//! Source CRS changed
//!\copydoc QgsQuickCoordinateTransformer::sourceCrs
void sourceCrsChanged();

//! Map settings changed
void mapSettingsChanged();
//!\copydoc QgsQuickCoordinateTransformer::transformContext
void transformContextChanged();

private:
void updatePosition();

QgsPoint mProjectedPosition;
QgsPoint mSourcePosition;
QgsCoordinateTransform mCoordinateTransform;
QgsQuickMapSettings *mMapSettings = nullptr;
};

#endif // QGSQUICKCOORDINATETRANSFORMER_H

0 comments on commit 7828dc4

Please sign in to comment.
You can’t perform that action at this time.