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
2 changes: 2 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ set(MM_HDRS
workspacesmodel.h
workspacesproxymodel.h
mmstyle.h
externalTypes/mmgeometry.h
)

if (NOT WIN32)
Expand Down Expand Up @@ -331,6 +332,7 @@ target_include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/layer
${CMAKE_CURRENT_SOURCE_DIR}/maptools
${CMAKE_CURRENT_SOURCE_DIR}/position
${CMAKE_CURRENT_SOURCE_DIR}/externalTypes
)

qt_policy(SET QTP0002 NEW)
Expand Down
40 changes: 40 additions & 0 deletions app/externalTypes/mmgeometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***************************************************************************
* *
* 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 MMGEOMETRY_H
#define MMGEOMETRY_H

#include <QtQml/qqmlregistration.h>

#include <qgsgeometry.h>

/**
* MMGeometry is just a wrapper around QgsGeometry, which adds equals operator that is missing.
* We expose this type to QML instead of QgsGeometry. The reason is that QML in Qt 6.9+ also checks equality, when firing
* onChanged signal. The missing operator is breaking property bindings.
*/
class MMGeometry: public QgsGeometry
{
Q_GADGET
QML_VALUE_TYPE( mmGeometry );

public:
using QgsGeometry::QgsGeometry;

MMGeometry() = default;
MMGeometry( const QgsGeometry &geom ) : QgsGeometry( geom ) {}
MMGeometry( QgsGeometry &geom ) : QgsGeometry( geom ) {}

bool operator==( const MMGeometry &rhs ) const
{
return equals( rhs );
}
};

#endif //MMGEOMETRY_H
4 changes: 2 additions & 2 deletions app/guidelinecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ void GuidelineController::buildGuideline()
}
}

const QgsGeometry &GuidelineController::guidelineGeometry() const
const MMGeometry &GuidelineController::guidelineGeometry() const
{
return mGuidelineGeometry;
}

void GuidelineController::setGuidelineGeometry( const QgsGeometry &newGuidelineGeometry )
void GuidelineController::setGuidelineGeometry( const MMGeometry &newGuidelineGeometry )
{
if ( mGuidelineGeometry.equals( newGuidelineGeometry ) )
return;
Expand Down
10 changes: 5 additions & 5 deletions app/guidelinecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class GuidelineController : public QObject
Q_PROPERTY( bool allowed READ allowed WRITE setAllowed NOTIFY allowedChanged )

// output properties (real geometry + crosshair position ) in map CRS
Q_PROPERTY( QgsGeometry guidelineGeometry READ guidelineGeometry WRITE setGuidelineGeometry NOTIFY guidelineGeometryChanged )
Q_PROPERTY( MMGeometry guidelineGeometry READ guidelineGeometry WRITE setGuidelineGeometry NOTIFY guidelineGeometryChanged )

public:
explicit GuidelineController( QObject *parent = nullptr );

const QgsGeometry &guidelineGeometry() const;
void setGuidelineGeometry( const QgsGeometry &newGuidelineGeometry );
const MMGeometry &guidelineGeometry() const;
void setGuidelineGeometry( const MMGeometry &newGuidelineGeometry );

QPointF crosshairPosition() const;
void setCrosshairPosition( QPointF newCrosshairPosition );
Expand Down Expand Up @@ -71,7 +71,7 @@ class GuidelineController : public QObject

signals:

void guidelineGeometryChanged( const QgsGeometry &guidelineGeometry );
void guidelineGeometryChanged( const MMGeometry &guidelineGeometry );
void crosshairPositionChanged( QPointF crosshairPosition );

void realGeometryChanged( const QgsGeometry &realGeometry );
Expand All @@ -93,7 +93,7 @@ class GuidelineController : public QObject

private:

QgsGeometry mGuidelineGeometry;
MMGeometry mGuidelineGeometry;
QPointF mCrosshairPosition;
QgsGeometry mRealGeometry;
InputMapSettings *mMapSettings = nullptr; // not owned
Expand Down
20 changes: 10 additions & 10 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@ QgsGeometry InputUtils::transformGeometry( const QgsGeometry &geometry, const Qg
return transformGeometry( geometry, sourceCRS, targetLayer->crs(), targetLayer->transformContext() );
}

QgsGeometry InputUtils::transformGeometryToMapWithLayer( const QgsGeometry &geometry, QgsVectorLayer *sourceLayer, InputMapSettings *targetSettings )
MMGeometry InputUtils::transformGeometryToMapWithLayer( const QgsGeometry &geometry, QgsVectorLayer *sourceLayer, InputMapSettings *targetSettings )
{
if ( !sourceLayer || !sourceLayer->isValid() || !targetSettings )
{
return QgsGeometry();
return {};
}

return transformGeometry( geometry, sourceLayer->crs(), targetSettings->destinationCrs(), targetSettings->transformContext() );
return MMGeometry( transformGeometry( geometry, sourceLayer->crs(), targetSettings->destinationCrs(), targetSettings->transformContext() ) );
}

QgsGeometry InputUtils::transformGeometryToMapWithCRS( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &sourceCRS, InputMapSettings *targetSettings )
Expand Down Expand Up @@ -816,9 +816,9 @@ QgsPoint InputUtils::point( double x, double y, double z, double m )
return QgsPoint( x, y, z, m );
}

QgsGeometry InputUtils::emptyGeometry()
MMGeometry InputUtils::emptyGeometry()
{
return QgsGeometry();
return {};
}

QgsFeature InputUtils::emptyFeature()
Expand Down Expand Up @@ -1667,15 +1667,15 @@ QgsRectangle InputUtils::stakeoutPathExtent(
return extent;
}

QgsGeometry InputUtils::stakeoutGeometry( const QgsPoint &mapPosition, const FeatureLayerPair &target, InputMapSettings *mapSettings )
MMGeometry InputUtils::stakeoutGeometry( const QgsPoint &mapPosition, const FeatureLayerPair &target, InputMapSettings *mapSettings )
{
if ( !mapSettings || !target.isValid() )
return QgsGeometry();
return {};

QgsPointXY targetInLayerCoordinates = target.feature().geometry().asPoint();
QgsPointXY t = transformPointXY( target.layer()->crs(), mapSettings->destinationCrs(), mapSettings->transformContext(), targetInLayerCoordinates );
const QgsPointXY targetInLayerCoordinates = target.feature().geometry().asPoint();
const QgsPointXY t = transformPointXY( target.layer()->crs(), mapSettings->destinationCrs(), mapSettings->transformContext(), targetInLayerCoordinates );

QVector<QgsPoint> points { mapPosition, QgsPoint( t ) };
const QVector<QgsPoint> points { mapPosition, QgsPoint( t ) };

return QgsGeometry::fromPolyline( points );
}
Expand Down
7 changes: 4 additions & 3 deletions app/inpututils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "inputmapsettings.h"
#include "featurelayerpair.h"
#include "qgscoordinateformatter.h"
#include "externalTypes/mmgeometry.h"
#include "position/mapposition.h"

class QgsFeature;
Expand Down Expand Up @@ -114,7 +115,7 @@ class InputUtils: public QObject
static QgsGeometry transformGeometry( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &sourceCRS, const QgsCoordinateReferenceSystem &destinationCRS, const QgsCoordinateTransformContext &context );

//! Helper methods to use for transforming geometry from QML as overriding does not work properly there
Q_INVOKABLE static QgsGeometry transformGeometryToMapWithLayer( const QgsGeometry &geometry, QgsVectorLayer *sourceLayer, InputMapSettings *targetSettings );
Q_INVOKABLE static MMGeometry transformGeometryToMapWithLayer( const QgsGeometry &geometry, QgsVectorLayer *sourceLayer, InputMapSettings *targetSettings );
Q_INVOKABLE static QgsGeometry transformGeometryToMapWithCRS( const QgsGeometry &geometry, const QgsCoordinateReferenceSystem &sourceCRS, InputMapSettings *targetSettings );

/**
Expand Down Expand Up @@ -270,7 +271,7 @@ class InputUtils: public QObject
/**
* Creates empty geometry
*/
Q_INVOKABLE static QgsGeometry emptyGeometry();
Q_INVOKABLE static MMGeometry emptyGeometry();

/**
* Creates empty feature
Expand Down Expand Up @@ -522,7 +523,7 @@ class InputUtils: public QObject
Q_INVOKABLE QgsRectangle stakeoutPathExtent( MapPosition *mapPosition, const FeatureLayerPair &targetFeature, InputMapSettings *mapSettings, double mapExtentOffset );

//! Returns geometry created out of the two points and converts it to map canvas screen pixels.
Q_INVOKABLE static QgsGeometry stakeoutGeometry( const QgsPoint &mapPosition, const FeatureLayerPair &target, InputMapSettings *mapSettings );
Q_INVOKABLE static MMGeometry stakeoutGeometry( const QgsPoint &mapPosition, const FeatureLayerPair &target, InputMapSettings *mapSettings );

// Translates distance to target point into scale factor that should be used for map canvas during stakeout
qreal distanceToScale( qreal distance );
Expand Down
6 changes: 3 additions & 3 deletions app/mapsketchingcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void MapSketchingController::updateHighlight( const QPointF &oldPoint, const QPo
ls->addZValue();
ls->addMValue();
QgsMultiLineString *mls = new QgsMultiLineString( QList<QgsLineString *>() << ls );
mHighlight = QgsGeometry( mls );
mHighlight = MMGeometry( mls );

mScreenPoints = QgsGeometry( new QgsLineString( { QgsPointXY( oldPoint.x(), oldPoint.y() ) } ) );
}
Expand Down Expand Up @@ -139,7 +139,7 @@ void MapSketchingController::undo() const
mLayer->undoStack()->undo();
}

QgsGeometry MapSketchingController::highlightGeometry() const
MMGeometry MapSketchingController::highlightGeometry() const
{
return mHighlight;
}
Expand All @@ -152,7 +152,7 @@ QStringList MapSketchingController::availableColors() const

void MapSketchingController::clearHighlight()
{
mHighlight = QgsGeometry( new QgsMultiLineString() );
mHighlight = MMGeometry( new QgsMultiLineString() );
emit highlightGeometryChanged();
}

Expand Down
7 changes: 4 additions & 3 deletions app/mapsketchingcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QColor>

#include "qgsgeometry.h"
#include "externalTypes/mmgeometry.h"

class QgsVectorLayer;
class InputMapSettings;
Expand All @@ -22,7 +23,7 @@ class MapSketchingController : public QObject
Q_OBJECT

Q_PROPERTY( InputMapSettings *mapSettings READ mapSettings WRITE setMapSettings NOTIFY mapSettingsChanged )
Q_PROPERTY( QgsGeometry highlightGeometry READ highlightGeometry NOTIFY highlightGeometryChanged )
Q_PROPERTY( MMGeometry highlightGeometry READ highlightGeometry NOTIFY highlightGeometryChanged )
Q_PROPERTY( QColor activeColor READ activeColor WRITE setActiveColor NOTIFY activeColorChanged )
Q_PROPERTY( bool canRedo READ canRedo NOTIFY canRedoChanged )
Q_PROPERTY( bool canUndo READ canUndo NOTIFY canUndoChanged )
Expand Down Expand Up @@ -51,7 +52,7 @@ class MapSketchingController : public QObject
void eraserActiveChanged();

private:
QgsGeometry highlightGeometry() const;
MMGeometry highlightGeometry() const;
void clearHighlight();
void setMapSettings( InputMapSettings *settings );
InputMapSettings *mapSettings() const;
Expand All @@ -65,7 +66,7 @@ class MapSketchingController : public QObject
InputMapSettings *mMapSettings = nullptr;
QgsVectorLayer *mLayer = nullptr;

QgsGeometry mHighlight;
MMGeometry mHighlight;

QgsGeometry mScreenPoints;
QColor mColor;
Expand Down
8 changes: 4 additions & 4 deletions app/maptools/measurementmaptool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,17 @@ void MeasurementMapTool::updateMapSettings( InputMapSettings *newMapSettings )
}
}

const QgsGeometry &MeasurementMapTool::recordedGeometry() const
const MMGeometry &MeasurementMapTool::recordedGeometry() const
{
return mRecordedGeometry;
}

QgsGeometry MeasurementMapTool::existingVertices() const
MMGeometry MeasurementMapTool::existingVertices() const
{
return mExistingVertices;
}

void MeasurementMapTool::setExistingVertices( const QgsGeometry &vertices )
void MeasurementMapTool::setExistingVertices( const MMGeometry &vertices )
{
if ( mExistingVertices.equals( vertices ) )
return;
Expand Down Expand Up @@ -273,7 +273,7 @@ void MeasurementMapTool::setMeasurementFinalized( bool newMeasurementFinalized )
emit measurementFinalizedChanged( mMeasurementFinalized );
}

void MeasurementMapTool::setRecordedGeometry( const QgsGeometry &newRecordedGeometry )
void MeasurementMapTool::setRecordedGeometry( const MMGeometry &newRecordedGeometry )
{
if ( mRecordedGeometry.equals( newRecordedGeometry ) )
return;
Expand Down
21 changes: 11 additions & 10 deletions app/maptools/measurementmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
#include "qgsgeometry.h"
#include "qgsvectorlayer.h"
#include "qgsmultipoint.h"
#include "externalTypes/mmgeometry.h"

const double CLOSE_THRESHOLD = 10.0; // in pixels

class MeasurementMapTool : public AbstractMapTool
{
Q_OBJECT

Q_PROPERTY( QgsGeometry recordedGeometry READ recordedGeometry WRITE setRecordedGeometry NOTIFY recordedGeometryChanged )
Q_PROPERTY( QgsGeometry existingVertices READ existingVertices WRITE setExistingVertices NOTIFY existingVerticesChanged )
Q_PROPERTY( MMGeometry recordedGeometry READ recordedGeometry WRITE setRecordedGeometry NOTIFY recordedGeometryChanged )
Q_PROPERTY( MMGeometry existingVertices READ existingVertices WRITE setExistingVertices NOTIFY existingVerticesChanged )
Q_PROPERTY( QPointF crosshairPoint READ crosshairPoint WRITE setCrosshairPoint NOTIFY crosshairPointChanged )

Q_PROPERTY( double lengthWithGuideline READ lengthWithGuideline WRITE setLengthWithGuideline NOTIFY lengthWithGuidelineChanged )
Expand Down Expand Up @@ -93,11 +94,11 @@ class MeasurementMapTool : public AbstractMapTool
bool measurementFinalized() const;
void setMeasurementFinalized( bool newMeasurementFinalized );

const QgsGeometry &recordedGeometry() const;
void setRecordedGeometry( const QgsGeometry &newRecordedGeometry );
const MMGeometry &recordedGeometry() const;
void setRecordedGeometry( const MMGeometry &newRecordedGeometry );

QgsGeometry existingVertices() const;
void setExistingVertices( const QgsGeometry &vertices );
MMGeometry existingVertices() const;
void setExistingVertices( const MMGeometry &vertices );

void resetMapSettings();
void updateMapSettings( InputMapSettings *newMapSettings );
Expand All @@ -109,8 +110,8 @@ class MeasurementMapTool : public AbstractMapTool
void canUndoChanged( bool canUndo );
void canCloseShapeChanged( bool canUndo );
void measurementFinalizedChanged( bool measurementFinalized );
void recordedGeometryChanged( const QgsGeometry &recordedGeometry );
void existingVerticesChanged( const QgsGeometry &vertices );
void recordedGeometryChanged( const MMGeometry &recordedGeometry );
void existingVerticesChanged( const MMGeometry &vertices );
void crosshairPointChanged( const QPointF &crosshairPoint );
void isValidGeometryChanged( bool canFinalize );

Expand All @@ -123,8 +124,8 @@ class MeasurementMapTool : public AbstractMapTool

private:
QVector<QgsPoint> mPoints;
QgsGeometry mRecordedGeometry;
QgsGeometry mExistingVertices;
MMGeometry mRecordedGeometry;
MMGeometry mExistingVertices;
QgsDistanceArea mDistanceArea;
QPointF mCrosshairPoint;
double mLengthWithGuideline = 0;
Expand Down
5 changes: 3 additions & 2 deletions app/multieditmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "featurelayerpair.h"
#include "staticfeaturesmodel.h"
#include "externalTypes/mmgeometry.h"

class QgsVectorLayer;

Expand All @@ -30,7 +31,7 @@ class MultiEditManager : public QObject

Q_PROPERTY( QgsVectorLayer *layer MEMBER mLayer NOTIFY layerChanged )
Q_PROPERTY( StaticFeaturesModel *model READ model CONSTANT )
Q_PROPERTY( QgsGeometry geometry READ collectGeometry NOTIFY geometryChanged )
Q_PROPERTY( MMGeometry geometry READ collectGeometry NOTIFY geometryChanged )
Q_PROPERTY( InputMapSettings *mapSettings MEMBER mMapSettings )

public:
Expand All @@ -49,7 +50,7 @@ class MultiEditManager : public QObject
Q_INVOKABLE void deleteSelectedFeatures();

//! Returns multipart geometry of all geometries in the model, in map crs
QgsGeometry collectGeometry() const { return mModel->collectGeometries( mMapSettings ); }
MMGeometry collectGeometry() const { return mModel->collectGeometries( mMapSettings ); }

StaticFeaturesModel *model() const { return mModel.get(); }

Expand Down
Loading
Loading