Skip to content

Commit

Permalink
binding values to cpp measurement tool
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ committed Aug 28, 2024
1 parent 7d27bcc commit d2e0e45
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 102 deletions.
49 changes: 46 additions & 3 deletions app/maptools/measurementmaptool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ const QgsGeometry &MeasurementMapTool::recordedGeometry() const
return mRecordedGeometry;
}

double MeasurementMapTool::area() const
{
return mArea;
}

double MeasurementMapTool::perimeter() const
{
return mPerimeter;
}

double MeasurementMapTool::length() const
{
return mLength;
}

void MeasurementMapTool::setRecordedGeometry( const QgsGeometry &newRecordedGeometry )
{
if ( mRecordedGeometry.equals( newRecordedGeometry ) )
Expand All @@ -69,10 +84,10 @@ void MeasurementMapTool::setRecordedGeometry( const QgsGeometry &newRecordedGeom
emit recordedGeometryChanged( mRecordedGeometry );
}

double MeasurementMapTool::updateDistance( const QgsPoint &crosshairPoint )
void MeasurementMapTool::updateDistance( const QgsPoint &crosshairPoint )
{
if ( mPoints.isEmpty() )
return 0.0;
setLength(0.0);

if ( mPoints.count() >= 3 )
{
Expand All @@ -99,7 +114,9 @@ double MeasurementMapTool::updateDistance( const QgsPoint &crosshairPoint )
mDistanceArea.setSourceCrs( mActiveLayer->crs(), QgsCoordinateTransformContext() );
//mDistanceArea.setSourceCrs(mapSettings()->destinationCrs(), QgsCoordinateTransformContext() );

return mDistanceArea.measureLength( mRecordedGeometry ) + mDistanceArea.measureLine( crosshairPoint, lastPoint );
double calculatedLength = mDistanceArea.measureLength( mRecordedGeometry ) + mDistanceArea.measureLine( crosshairPoint, lastPoint );

setLength(calculatedLength);
}

void MeasurementMapTool::closeShape()
Expand Down Expand Up @@ -152,6 +169,32 @@ void MeasurementMapTool::setActiveLayer( QgsVectorLayer *newActiveLayer )
emit activeLayerChanged( mActiveLayer );
}

void MeasurementMapTool::setLength( const double &length ) {
if ( mLength == length )
return;

mLength = length;
emit lengthChanged( length );
}

void MeasurementMapTool::setArea( const double &area ) {
if ( mArea == area )
return;

mArea = area;
emit areaChanged( area );
}

void MeasurementMapTool::setPerimeter( const double &perimeter ) {
if ( mPerimeter == perimeter )
return;

mPerimeter = perimeter;
emit perimeterChanged( perimeter );
}



QgsVectorLayer *MeasurementMapTool::activeLayer() const
{
return mActiveLayer;
Expand Down
29 changes: 24 additions & 5 deletions app/maptools/measurementmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class MeasurementMapTool : public AbstractMapTool

Q_PROPERTY( QgsGeometry recordedGeometry READ recordedGeometry WRITE setRecordedGeometry NOTIFY recordedGeometryChanged )
Q_PROPERTY( QgsVectorLayer *activeLayer READ activeLayer WRITE setActiveLayer NOTIFY activeLayerChanged )
Q_PROPERTY( double length READ length WRITE setLength NOTIFY lengthChanged)
Q_PROPERTY( double perimeter READ perimeter WRITE setPerimeter NOTIFY perimeterChanged)
Q_PROPERTY( double area READ area WRITE setArea NOTIFY areaChanged)

public:
explicit MeasurementMapTool( QObject *parent = nullptr );
Expand All @@ -46,7 +49,17 @@ class MeasurementMapTool : public AbstractMapTool
Q_INVOKABLE void removePoint();

Q_INVOKABLE void closeShape();
Q_INVOKABLE void repeat();
Q_INVOKABLE void repeat();

double length() const;
void setLength(const double &length);

double perimeter() const;
void setPerimeter(const double &perimeter);

double area() const;
void setArea(const double &area);


const QgsGeometry &recordedGeometry() const;
void setRecordedGeometry( const QgsGeometry &newRecordedGeometry );
Expand All @@ -56,25 +69,31 @@ class MeasurementMapTool : public AbstractMapTool
void fixZM( QgsPoint &point ) const;

signals:
void lengthChanged(const double &length);
void perimeterChanged(const double &perimeter);
void areaChanged(const double &area);

void activeLayerChanged( QgsVectorLayer *activeLayer );
void recordedGeometryChanged( const QgsGeometry &recordedGeometry );

void canCloseShape( bool canClose );
void canUndo( bool canUndo );

void shapeAreaAndPerimeter( double area, double perimeter );

void activeLayerChanged( QgsVectorLayer *activeLayer );

protected:
void rebuildGeometry();

public slots:
double updateDistance( const QgsPoint &crosshairPoint );
void updateDistance( const QgsPoint &crosshairPoint );

private:
QVector<QgsPoint> mPoints;
QgsGeometry mRecordedGeometry;
QgsVectorLayer *mActiveLayer = nullptr; // not owned
QgsVectorLayer *mActiveLayer = nullptr;
double mLength = 0;
double mPerimeter = 0;
double mArea = 0;
};

#endif // MEASUREMENTMAPTOOL_H
18 changes: 9 additions & 9 deletions app/qml/gps/MMMeasureDrawer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ MMDrawer {

readonly property alias panelHeight: root.height

property bool canCloseShape: false
property bool closeShapeDone: false
property bool canUndo: false
property bool canCloseShape: mapCanvas.mapToolComponent.mapTool.canCloseShape
property bool closeShapeDone: mapCanvas.mapToolComponent.mapTool.closeShapeDone
property bool canUndo: mapCanvas.mapToolComponent.mapTool.canUndo

property string length: qsTr( "0.0 m" )
property string perimeter: qsTr( "0.0 m" )
property string area: qsTr( "0.0 m²" )
property string length: __inputUtils.formatDistanceInProjectUnit( mapCanvas.mapToolComponent.mapTool.length, 1 )
property string perimeter: __inputUtils.formatDistanceInProjectUnit( mapCanvas.mapToolComponent.mapTool.perimeter, 1 )
property string area: __inputUtils.formatAreaInProjectUnit( mapCanvas.mapToolComponent.mapTool.area, 1 )

signal addMeasurePoint()
//signal addMeasurePoint()
signal measureFinished()
signal measureDone()
signal closeShape()
Expand All @@ -57,7 +57,7 @@ MMDrawer {
leftButtonIcon: closeShapeDone ? __style.syncIcon : __style.undoIcon
leftButtonType: MMButton.Types.Primary
leftButtonEnabled: closeShapeDone || canUndo
onLeftButtonClicked: closeShapeDone ? root.repeatMeasure() : root.undo()
onLeftButtonClicked: closeShapeDone ? root.mapCanvas.mapToolComponent.repeatMeasure() : root.mapCanvas.mapToolComponent.removePoint()

drawerHeader.title: qsTr( "Measurement" )

Expand Down Expand Up @@ -95,7 +95,7 @@ MMDrawer {
MMButton {
text: root.canCloseShape ? qsTr( "Close shape" ) : qsTr( "Add point" )
iconSourceLeft: canCloseShape ? __style.closeShapeIcon : __style.plusIcon
onClicked: canCloseShape ? root.closeShape() : root.addMeasurePoint()
onClicked: canCloseShape ? root.mapCanvas.mapToolComponent.closeShape() : root.mapCanvas.mapToolComponent.addPoint()
}

MMButton {
Expand Down
61 changes: 35 additions & 26 deletions app/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ ApplicationWindow {
// if stakeout panel is opened
return stakeoutPanelLoader.item.panelHeight - mapToolbar.height
}
else if ( map.measureLoader.active )
else if ( measurePanelLoader.active )
{
return map.measureLoader.item.measurePanel.panelHeight - mapToolbar.height
return measurePanelLoader.item.panelHeight - mapToolbar.height
}
else if ( formsStackManager.takenVerticalSpace > 0 )
{
Expand Down Expand Up @@ -224,7 +224,8 @@ ApplicationWindow {
}

onMeasureStarted: function( pair ) {
console.log(" measure started")
measurePanelLoader.active = true
measurePanelLoader.focus = true
}

onLocalChangesPanelRequested: {
Expand Down Expand Up @@ -467,7 +468,7 @@ ApplicationWindow {
mapSettings: map.mapSettings

// disable the receivers button when staking out
showReceiversButton: !stakeoutPanelLoader.active
showReceiversButton: !stakeoutPanelLoader.active || !measurePanelLoader.active

onManageReceiversClicked: {
gpsDataDrawer.close()
Expand Down Expand Up @@ -613,34 +614,33 @@ ApplicationWindow {
}
}

// Loader {
// id: stakeoutPanelLoader
Loader {
id: measurePanelLoader

focus: true
active: false
asynchronous: true

// focus: true
// active: false
// asynchronous: true
sourceComponent: measurePanelComponent
}

// sourceComponent: stakeoutPanelComponent
// }
Component {
id: measurePanelComponent

// Component {
// id: stakeoutPanelComponent
MMMeasureDrawer {
id: measurePanel

// MMMeasureDrawer {
// id: measurePanel
width: window.width
mapCanvas: map

// width: window.width
// mapCanvas: root.map
onMeasureDone: finishMeasurementDialog.open()

// //bind length and area to mapTool.length and mapTool.area / iconSource === or closeShape
// onAddMeasurePoint: mapTool.addPoint( crosshair.recordPoint )
// onMeasureDone: finishMeasurementDialog.open()
// onMeasureFinished: root.finishMeasurement()
// onCloseShape: root.closeShape()
// onRepeat: root.repeatMeasure()
// onUndo: mapTool.removePoint()
// }
// }
onMeasureFinished: {
measurePanelLoader.active = false
map.finishMeasure()
}
}
}

MMFormStackController {
id: formsStackManager
Expand Down Expand Up @@ -773,6 +773,15 @@ ApplicationWindow {
}
}

MMFinishMeasurementDialog {
id: finishMeasurementDialog

onFinishMeasurementRequested: {
measurePanelLoader.active = false
map.finishMeasure()
}
}

MMNotificationView {}

MMListDrawer {
Expand Down
30 changes: 18 additions & 12 deletions app/qml/map/MMMapController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Item {
property bool isStreaming: recordingToolsLoader.active ? recordingToolsLoader.item.recordingMapTool.recordingType === MM.RecordingMapTool.StreamMode : false
property bool centeredToGPS: false

property var mapToolComponent: {
state === "measure" ? measurementToolsLoader.item : null
}

property MM.PositionTrackingManager trackingManager: tracking.item?.manager ?? null

signal featureIdentified( var pair )
Expand Down Expand Up @@ -296,17 +300,6 @@ Item {
sourceComponent: stakeoutToolsComponent
}

Loader {
id: measureLoader

anchors.fill: mapCanvas

asynchronous: true
active: root.state === "measure"

sourceComponent: measurementToolsComponent
}

Loader {
id: tracking

Expand Down Expand Up @@ -401,6 +394,17 @@ Item {
sourceComponent: splittingToolsComponent
}

Loader {
id: measurementToolsLoader

anchors.fill: mapCanvas

asynchronous: true
active: root.state === "measure"

sourceComponent: measurementToolsComponent
}

// map available content within safe area
Item {
anchors {
Expand Down Expand Up @@ -1148,8 +1152,10 @@ Item {

function measure() {
internal.extentBeforeStakeout = mapCanvas.mapSettings.extent

state = "measure"
console.log(" MAP TOOL: ", root.mapTool)
root.mapToolComponent = measurementToolsLoader.item
console.log(" MAP TOOL: ", root.mapTool)
}

function toggleStreaming() {
Expand Down
Loading

0 comments on commit d2e0e45

Please sign in to comment.