Skip to content
Permalink
Browse files
add setCadPoint and cadPoint methods and fix test
  • Loading branch information
lbartoletti authored and nyalldawson committed Sep 12, 2021
1 parent 992dc6c commit 2414a2884b1919ba7ac983d8359edb4b223f4c65
@@ -94,6 +94,19 @@ Set points to mCadPointList

.. versionadded:: 3.22
%End
void setCadPoint( const QgsPoint &point, int index );
%Docstring
Set ``point`` at ``index`` to mCadPointList

.. versionadded:: 3.22
%End
QgsPoint cadPoint( int index ) const;
%Docstring
Get ``point`` at ``index`` from mCadPointList

.. versionadded:: 3.22
%End

%Property( name = cadPointList, get = _cadPointList, set = _setCadPointList )
void _setCadPointList( const QList< QgsPointXY > &list );
QList< QgsPointXY > _cadPointList() const;
@@ -58,9 +58,9 @@ QgsCadUtils::AlignMapPointOutput QgsCadUtils::alignMapPoint( const QgsPointXY &o

QgsPointXY previousPt, penultimatePt;
if ( ctx.cadPoints().count() >= 2 )
previousPt = ctx.cadPoints().at( 1 );
previousPt = ctx.cadPoint( 1 );
if ( ctx.cadPoints().count() >= 3 )
penultimatePt = ctx.cadPoints().at( 2 );
penultimatePt = ctx.cadPoint( 2 );

// *****************************
// ---- X constraint
@@ -76,6 +76,7 @@ class CORE_EXPORT QgsCadUtils
};

/**
* \ingroup core
* Class defining all constraints for alignMapPoint() method
*
* This class was a structure before QGIS 3.22.
@@ -138,6 +139,19 @@ class CORE_EXPORT QgsCadUtils
*/
void setCadPoints( const QList< QgsPoint> &list ) { mCadPointList = list; };

/**
* Set \a point at \a index to mCadPointList
* \since QGIS 3.22
*/
void setCadPoint( const QgsPoint &point, int index ) { mCadPointList[index] = point; };

/**
* Get \a point at \a index from mCadPointList
* \since QGIS 3.22
*/
QgsPoint cadPoint( int index ) const { return mCadPointList[index]; };


#ifdef SIP_RUN
SIP_PROPERTY( name = cadPointList, get = _cadPointList, set = _setCadPointList )
#endif
@@ -53,7 +53,7 @@ class TestQgsCadUtils : public QObject
QgsCadUtils::AlignMapPointContext context;
context.snappingUtils = mSnappingUtils;
context.mapUnitsPerPixel = mMapSettings.mapUnitsPerPixel();
context.cadPoints() << QgsPoint() << QgsPoint( 30, 20 ) << QgsPoint( 30, 30 );
context.setCadPoints( QList<QgsPoint>() << QgsPoint() << QgsPoint( 30, 20 ) << QgsPoint( 30, 30 ) );
return context;
}

@@ -231,7 +231,7 @@ void TestQgsCadUtils::testCommonAngle()
// common angle rel
context.angleConstraint = QgsCadUtils::AlignMapPointConstraint();
context.commonAngleConstraint = QgsCadUtils::AlignMapPointConstraint( true, true, 90 );
context.cadPoints()[1] = QgsPoint( 40, 20 );
context.setCadPoint( QgsPoint( 40, 20 ), 1 );
QgsCadUtils::AlignMapPointOutput res3 = QgsCadUtils::alignMapPoint( QgsPointXY( 50.1, 29.9 ), context );
QVERIFY( res3.valid );
QCOMPARE( res3.softLockCommonAngle, 90.0 );

0 comments on commit 2414a28

Please sign in to comment.