Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Add some tests for circle map tools
- Loading branch information
1 parent
916e4ba
commit 58610b4
Showing
6 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/*************************************************************************** | ||
testqgsmaptoolcircle.cpp | ||
------------------------ | ||
Date : January 2018 | ||
Copyright : (C) 2018 by Paul Blottiere | ||
Email : paul.blottiere@oslandia.com | ||
*************************************************************************** | ||
* * | ||
* 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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgstest.h" | ||
|
||
#include "qgisapp.h" | ||
#include "qgsgeometry.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgssettings.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsmaptooladdfeature.h" | ||
|
||
#include "testqgsmaptoolutils.h" | ||
#include "qgsmaptoolcircle2points.h" | ||
#include "qgsmaptoolcircle3points.h" | ||
#include "qgsmaptoolcirclecenterpoint.h" | ||
|
||
|
||
class TestQgsMapToolCircle : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
TestQgsMapToolCircle(); | ||
|
||
private slots: | ||
void initTestCase(); | ||
void cleanupTestCase(); | ||
|
||
void testCircleFrom2Points(); | ||
void testCircleFrom3Points(); | ||
void testCircleFromCenterPoint(); | ||
|
||
private: | ||
QgisApp *mQgisApp = nullptr; | ||
QgsMapToolCapture *mParentTool = nullptr; | ||
QgsMapCanvas *mCanvas = nullptr; | ||
QgsVectorLayer *mLayer = nullptr; | ||
}; | ||
|
||
TestQgsMapToolCircle::TestQgsMapToolCircle() = default; | ||
|
||
|
||
//runs before all tests | ||
void TestQgsMapToolCircle::initTestCase() | ||
{ | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
|
||
mQgisApp = new QgisApp(); | ||
|
||
mCanvas = new QgsMapCanvas(); | ||
mCanvas->setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:27700" ) ) ); | ||
|
||
// make testing layers | ||
mLayer = new QgsVectorLayer( QStringLiteral( "LineStringZ?crs=EPSG:27700" ), QStringLiteral( "layer line Z" ), QStringLiteral( "memory" ) ); | ||
QVERIFY( mLayer->isValid() ); | ||
QgsProject::instance()->addMapLayers( QList<QgsMapLayer *>() << mLayer ); | ||
|
||
// set layers in canvas | ||
mCanvas->setLayers( QList<QgsMapLayer *>() << mLayer ); | ||
mCanvas->setCurrentLayer( mLayer ); | ||
|
||
mParentTool = new QgsMapToolAddFeature( mCanvas, QgsMapToolCapture::CaptureLine ); | ||
} | ||
|
||
void TestQgsMapToolCircle::cleanupTestCase() | ||
{ | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void TestQgsMapToolCircle::testCircleFrom2Points() | ||
{ | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 333 ); | ||
mLayer->startEditing(); | ||
|
||
QgsMapToolCircle2Points mapTool( mParentTool, mCanvas ); | ||
mCanvas->setMapTool( &mapTool ); | ||
|
||
TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool ); | ||
utils.mouseClick( 0, 0, Qt::LeftButton ); | ||
utils.mouseMove( 0, 2 ); | ||
utils.mouseClick( 0, 2, Qt::RightButton ); | ||
QgsFeatureId newFid = utils.newFeatureId(); | ||
|
||
QCOMPARE( mLayer->featureCount(), ( long )1 ); | ||
QgsFeature f = mLayer->getFeature( newFid ); | ||
|
||
QString wkt = "CompoundCurveZ (CircularStringZ (0 2 333, 1 1 333, 0 0 333, -1 1 333, 0 2 333))"; | ||
QCOMPARE( f.geometry().asWkt(), wkt ); | ||
|
||
mLayer->rollBack(); | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 ); | ||
} | ||
|
||
void TestQgsMapToolCircle::testCircleFrom3Points() | ||
{ | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 111 ); | ||
mLayer->startEditing(); | ||
|
||
QgsMapToolCircle3Points mapTool( mParentTool, mCanvas ); | ||
mCanvas->setMapTool( &mapTool ); | ||
|
||
TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool ); | ||
utils.mouseClick( 0, 0, Qt::LeftButton ); | ||
utils.mouseClick( 0, 2, Qt::LeftButton ); | ||
utils.mouseMove( 1, 1 ); | ||
utils.mouseClick( 1, 1, Qt::RightButton ); | ||
QgsFeatureId newFid = utils.newFeatureId(); | ||
|
||
QCOMPARE( mLayer->featureCount(), ( long )1 ); | ||
QgsFeature f = mLayer->getFeature( newFid ); | ||
|
||
QString wkt = "CompoundCurveZ (CircularStringZ (0 2 111, 1 1 111, 0 0 111, -1 1 111, 0 2 111))"; | ||
QCOMPARE( f.geometry().asWkt(), wkt ); | ||
|
||
mLayer->rollBack(); | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 ); | ||
} | ||
|
||
void TestQgsMapToolCircle::testCircleFromCenterPoint() | ||
{ | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 222 ); | ||
mLayer->startEditing(); | ||
|
||
QgsMapToolCircleCenterPoint mapTool( mParentTool, mCanvas ); | ||
mCanvas->setMapTool( &mapTool ); | ||
|
||
TestQgsMapToolAdvancedDigitizingUtils utils( &mapTool ); | ||
utils.mouseClick( 0, 0, Qt::LeftButton ); | ||
utils.mouseMove( 0, 2 ); | ||
utils.mouseClick( 0, 2, Qt::RightButton ); | ||
QgsFeatureId newFid = utils.newFeatureId(); | ||
|
||
QCOMPARE( mLayer->featureCount(), ( long )1 ); | ||
QgsFeature f = mLayer->getFeature( newFid ); | ||
|
||
QString wkt = "CompoundCurveZ (CircularStringZ (0 2 222, 2 0 222, 0 -2 222, -2 0 222, 0 2 222))"; | ||
QCOMPARE( f.geometry().asWkt(), wkt ); | ||
|
||
mLayer->rollBack(); | ||
QgsSettings().setValue( QStringLiteral( "/qgis/digitizing/default_z_value" ), 0 ); | ||
} | ||
|
||
QGSTEST_MAIN( TestQgsMapToolCircle ) | ||
#include "testqgsmaptoolcircle.moc" |