Skip to content
Permalink
Browse files

apply map transform directly in the feature highligh c++ code

  • Loading branch information
PeterPetrik committed May 29, 2018
1 parent 093d53a commit 8494c67a20d733126cc379550fd5d97df5970534
@@ -28,7 +28,10 @@ QgsQuickFeatureHighlight::QgsQuickFeatureHighlight( QQuickItem *parent )
setFlags( QQuickItem::ItemHasContents );
setAntialiasing( true );

connect( this, &QgsQuickFeatureHighlight::mapSettingsChanged, this, &QgsQuickFeatureHighlight::markDirty );
// transform to device coords
mTransform.appendToItem(this);

connect( this, &QgsQuickFeatureHighlight::mapSettingsChanged, this, &QgsQuickFeatureHighlight::onMapSettingsChanged );
connect( this, &QgsQuickFeatureHighlight::featureLayerPairChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::colorChanged, this, &QgsQuickFeatureHighlight::markDirty );
connect( this, &QgsQuickFeatureHighlight::widthChanged, this, &QgsQuickFeatureHighlight::markDirty );
@@ -40,6 +43,12 @@ void QgsQuickFeatureHighlight::markDirty()
update();
}

void QgsQuickFeatureHighlight::onMapSettingsChanged()
{
mTransform.setMapSettings(mMapSettings);
markDirty();
}

QSGNode *QgsQuickFeatureHighlight::updatePaintNode( QSGNode *n, QQuickItem::UpdatePaintNodeData * )
{
if ( !mDirty || !mMapSettings || !mFeatureLayerPair.isValid() )
@@ -20,6 +20,7 @@

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

class QgsQuickMapSettings;

@@ -28,9 +29,10 @@ class QgsQuickMapSettings;
*
* Creates map highlights for a geometry provided by a FeatureModel.
*
* The highlights are compatible with the QtQuick scene graph.
* The highlights are compatible with the QtQuick scene graph and
* can be direcly shown on map canvas
*
* \note QML Type: FeatureModelHighlight
* \note QML Type: FeatureHighlight
*
* \since QGIS 3.4
*/
@@ -81,6 +83,7 @@ class QUICK_EXPORT QgsQuickFeatureHighlight : public QQuickItem

private slots:
void markDirty();
void onMapSettingsChanged();

private:
QSGNode *updatePaintNode( QSGNode *n, UpdatePaintNodeData * ) override;
@@ -90,6 +93,7 @@ class QUICK_EXPORT QgsQuickFeatureHighlight : public QQuickItem
float mWidth = 20;
QgsQuickFeatureLayerPair mFeatureLayerPair;
QgsQuickMapSettings *mMapSettings = nullptr; // not owned
QgsQuickMapTransform mTransform;
};

#endif // QGSQUICKFEATUREHIGHLIGHT_H
@@ -46,10 +46,11 @@ void QgsQuickMapTransform::setMapSettings( QgsQuickMapSettings *mapSettings )
void QgsQuickMapTransform::updateMatrix()
{
QMatrix4x4 matrix;
float scaleFactor = 1 / mMapSettings->mapUnitsPerPixel();
float scaleFactor = static_cast<float>(1.0 / mMapSettings->mapUnitsPerPixel());

matrix.scale( scaleFactor, -scaleFactor );
matrix.translate( -mMapSettings->visibleExtent().xMinimum(), -mMapSettings->visibleExtent().yMaximum() );
matrix.translate( static_cast<float>(-mMapSettings->visibleExtent().xMinimum( )),
static_cast<float>(-mMapSettings->visibleExtent().yMaximum() ));

mMatrix = matrix;
update();
@@ -25,10 +25,10 @@ class QgsQuickMapSettings;

/**
* \ingroup quick
* The QgsQuickMapTransform is transformation that can be attached to any QQuickItem. Transformation scales and translates
* Item based on the current QgsQuickMapSettings settings.
* The QgsQuickMapTransform is transformation that can be attached to any QQuickItem.
*
* For example it can be used on QgsQuickFeatureHighlight to place it correctly on the map canvas.
* If the item is based on the map coordinates, QgsQuickMapTransform will
* transform it to the device coordintes based on the attached map settings.
*
* \note QML Type: MapTransform
*
@@ -44,19 +44,12 @@ ApplicationWindow {
}
}

Item {
QgsQuick.FeatureHighlight {
anchors.fill: mapCanvas
transform: QgsQuick.MapTransform {
mapSettings: mapCanvas.mapSettings
}

QgsQuick.FeatureHighlight {
id: highlight
color: "red"
mapSettings: mapCanvas.mapSettings
}

z: 1 // make sure items from here are on top of the Z-order
id: highlight
color: "red"
mapSettings: mapCanvas.mapSettings
z: 1
}

Drawer {

0 comments on commit 8494c67

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