Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove -1 return code for QgsMapToolCapture::addVertex
This code corresponded to a "not a vector layer" error, which needlessly prevents the QgsMapToolCapture class from being usable as a base class for map tools which operate on non-vector layers.
- Loading branch information
1 parent
b6c032d
commit c8ac971
Showing
5 changed files
with
107 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*************************************************************************** | ||
testqgsmaptooledit.cpp | ||
-------------------------------------- | ||
Date : September 2021 | ||
Copyright : (C) 2021 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot 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 <QCoreApplication> | ||
|
||
#include "qgstest.h" | ||
#include "qgsguiutils.h" | ||
#include "qgsmaptoolcapture.h" | ||
#include "qgsapplication.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgslogger.h" | ||
#include "qgsannotationlayer.h" | ||
#include "qgsadvanceddigitizingdockwidget.h" | ||
|
||
class TestQgsMapToolCapture : public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
TestQgsMapToolCapture() = default; | ||
|
||
private slots: | ||
void initTestCase(); // will be called before the first testfunction is executed. | ||
void cleanupTestCase(); // will be called after the last testfunction was executed. | ||
void init(); // will be called before each testfunction is executed. | ||
void cleanup(); // will be called after every testfunction. | ||
|
||
void addVertexNonVectorLayer(); | ||
|
||
}; | ||
|
||
void TestQgsMapToolCapture::initTestCase() | ||
{ | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
QgsApplication::showSettings(); | ||
} | ||
|
||
void TestQgsMapToolCapture::cleanupTestCase() | ||
{ | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void TestQgsMapToolCapture::init() | ||
{ | ||
} | ||
|
||
void TestQgsMapToolCapture::cleanup() | ||
{ | ||
} | ||
|
||
void TestQgsMapToolCapture::addVertexNonVectorLayer() | ||
{ | ||
QgsProject::instance()->clear(); | ||
QgsMapCanvas canvas; | ||
canvas.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) ); | ||
canvas.setFrameStyle( QFrame::NoFrame ); | ||
canvas.resize( 600, 600 ); | ||
canvas.setExtent( QgsRectangle( 0, 0, 10, 10 ) ); | ||
canvas.show(); // to make the canvas resize | ||
|
||
QgsAnnotationLayer *layer = new QgsAnnotationLayer( QStringLiteral( "test" ), QgsAnnotationLayer::LayerOptions( QgsProject::instance()->transformContext() ) ); | ||
QVERIFY( layer->isValid() ); | ||
QgsProject::instance()->addMapLayers( { layer} ); | ||
|
||
canvas.setLayers( { layer } ); | ||
canvas.setCurrentLayer( layer ); | ||
|
||
QgsAdvancedDigitizingDockWidget cadDock( &canvas ); | ||
QgsMapToolCapture tool( &canvas, &cadDock, QgsMapToolCapture::CaptureLine ); | ||
canvas.setMapTool( &tool ); | ||
|
||
// even though we don't have a vector layer selected, adding vertices should still be allowed | ||
QCOMPARE( tool.addVertex( QgsPoint( 5, 5 ), QgsPointLocator::Match() ), 0 ); | ||
|
||
|
||
} | ||
|
||
QGSTEST_MAIN( TestQgsMapToolCapture ) | ||
#include "testqgsmaptoolcapture.moc" |