Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/mmtypeutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ struct ForeignGeometry
QML_VALUE_TYPE( qgsGeometry );
};

struct ForeignPoint
{
Q_GADGET
QML_FOREIGN( QgsPoint )
QML_VALUE_TYPE( qgsPoint );
};

#endif //MMTYPEUTILS_H
20 changes: 9 additions & 11 deletions app/qml/map/components/MMCrosshair.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,34 @@
import QtQuick
import QtQuick.Controls.impl

import mm 1.0 as MM
import MMInput

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we wanted to always import our cpp like:

Suggested change
import MMInput
import MMInput as MM


Item {
id: root

/*required*/ property var qgsProject
/*required*/ property var mapSettings
required property var qgsProject
required property var mapSettings
property bool shouldUseSnapping: false

property point center: Qt.point( root.width / 2, root.height / 2 )

property var recordPoint: snapUtils.recordPoint

property point screenPoint: snapUtils.snapped && __activeLayer.vectorLayer ? __inputUtils.transformPointToScreenCoordinates(__activeLayer.vectorLayer.crs, mapSettings, recordPoint) : center
property qgsPoint recordPoint : snapUtils.recordPoint
property point screenPoint : snapUtils.snapped ? snapUtils.snapPoint : root.center

property real outerSize: 60 * __dp
property real innerDotSize: 10 * __dp

property alias crosshairForeground: crosshairForeground
property alias snapUtils: snapUtils

MM.SnapUtils {
SnapUtils {
id: snapUtils

centerPosition: root.center
mapSettings: root.mapSettings
qgsProject: root.qgsProject
useSnapping: root.shouldUseSnapping
destinationLayer: __activeLayer.vectorLayer

}

Image {
Expand Down Expand Up @@ -166,7 +164,7 @@ Item {
}
}

opacity: snapUtils.snapped && ( snapUtils.snapType === MM.SnapUtils.Vertex || snapUtils.snapType === MM.SnapUtils.Other ) ? 100 : 0
opacity: snapUtils.snapped && ( snapUtils.snapType === SnapUtils.Vertex || snapUtils.snapType === SnapUtils.Other ) ? 100 : 0

Behavior on opacity {
PropertyAnimation {
Expand All @@ -176,7 +174,7 @@ Item {
}
}

rotation: snapUtils.snapType === MM.SnapUtils.Other ? 0 : 45
rotation: snapUtils.snapType === SnapUtils.Other ? 0 : 45

Behavior on rotation {
PropertyAnimation {
Expand Down Expand Up @@ -217,7 +215,7 @@ Item {
}
}

opacity: snapUtils.snapped && snapUtils.snapType === MM.SnapUtils.Segment ? 100 : 0
opacity: snapUtils.snapped && snapUtils.snapType === SnapUtils.Segment ? 100 : 0

Behavior on opacity {
PropertyAnimation {
Expand Down
12 changes: 12 additions & 0 deletions app/snaputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void SnapUtils::getsnap()
}

setRecordPoint( layerPoint );
setSnapPoint( InputUtils::transformPointToScreenCoordinates( mDestinationLayer->crs(), mMapSettings, layerPoint ) );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear snap point when no snap plz


if ( snap.hasVertex() )
{
Expand Down Expand Up @@ -186,6 +187,17 @@ void SnapUtils::setCenterPosition( QPointF newCenterPosition )
initializeRecordPosition();
}

QPointF SnapUtils::snapPoint() const
{
return mSnapPoint;
}

void SnapUtils::setSnapPoint( QPointF newSnapPoint )
{
mSnapPoint = newSnapPoint;
emit snapPointChanged( mSnapPoint );
}

QgsPoint SnapUtils::recordPoint() const
{
return mRecordPoint;
Expand Down
11 changes: 11 additions & 0 deletions app/snaputils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <QObject>
#include <qglobal.h>
#include <qqmlintegration.h>

#include "qgspoint.h"
#include "qgsproject.h"
Expand All @@ -23,6 +24,7 @@
class SnapUtils : public QObject
{
Q_OBJECT
QML_ELEMENT

Q_PROPERTY( QgsProject *qgsProject READ qgsProject WRITE setQgsProject NOTIFY qgsProjectChanged )
Q_PROPERTY( InputMapSettings *mapSettings READ mapSettings WRITE setMapSettings NOTIFY mapSettingsChanged )
Expand All @@ -32,7 +34,10 @@ class SnapUtils : public QObject
Q_PROPERTY( QgsVectorLayer *destinationLayer READ destinationLayer WRITE setDestinationLayer NOTIFY destinationLayerChanged )

Q_PROPERTY( bool snapped READ snapped WRITE setSnapped NOTIFY snappedChanged )
// point in map CRS which will be recorded
Q_PROPERTY( QgsPoint recordPoint READ recordPoint WRITE setRecordPoint NOTIFY recordPointChanged )
// point in screen CRS where the crosshair should point if snapping is enabled
Q_PROPERTY( QPointF snapPoint READ snapPoint WRITE setSnapPoint NOTIFY snapPointChanged )

public:
SnapUtils( QObject *parent = nullptr );
Expand All @@ -58,6 +63,9 @@ class SnapUtils : public QObject
QPointF centerPosition() const;
void setCenterPosition( QPointF newCenterPosition );

QPointF snapPoint() const;
void setSnapPoint( QPointF newSnapPoint );

QgsPoint recordPoint() const;
void setRecordPoint( QgsPoint newRecordPoint );

Expand All @@ -84,6 +92,8 @@ class SnapUtils : public QObject

void centerPositionChanged( QPointF centerPosition );

void snapPointChanged( QPointF snapPoint );

void recordPointChanged( QgsPoint recordPoint );

void useSnappingChanged( bool useSnapping );
Expand All @@ -105,6 +115,7 @@ class SnapUtils : public QObject
QgsVectorLayer *mDestinationLayer = nullptr; // not owned

QPointF mCenterPosition = QPointF( -1, -1 );
QPointF mSnapPoint = QPointF( -1, -1 );
QgsPoint mRecordPoint = QgsPoint( -1, -1 );

bool mSnapped = false;
Expand Down
Loading