Skip to content

Commit

Permalink
Add equality/inequality operators for QgsFeatureRequest::QgsSimplifyM…
Browse files Browse the repository at this point in the history
…ethod

Includes unit test

The equality operator is useful for unit tests, the inequality
operator was added for completeness as requested by Nyall
in #45384 (comment)
  • Loading branch information
strk authored and nyalldawson committed Jan 31, 2022
1 parent 9ce1664 commit 182732e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/core/auto_generated/qgssimplifymethod.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ Gets whether the simplification executes after fetch the geometries from provide
Creates a geometry simplifier according to specified method
%End

bool operator==( const QgsSimplifyMethod &v ) const;

bool operator!=( const QgsSimplifyMethod &v ) const;

protected:
};

Expand Down
14 changes: 14 additions & 0 deletions src/core/qgssimplifymethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@ QgsAbstractGeometrySimplifier *QgsSimplifyMethod::createGeometrySimplifier( cons
return nullptr;
}
}

bool QgsSimplifyMethod::operator==( const QgsSimplifyMethod &v ) const
{
return
mMethodType == v.mMethodType &&
mTolerance == v.mTolerance &&
mThreshold == v.mThreshold &&
mForceLocalOptimization == v.mForceLocalOptimization;
}

bool QgsSimplifyMethod::operator!=( const QgsSimplifyMethod &v ) const
{
return !( v == *this );
}
6 changes: 6 additions & 0 deletions src/core/qgssimplifymethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class CORE_EXPORT QgsSimplifyMethod
//! Creates a geometry simplifier according to specified method
static QgsAbstractGeometrySimplifier *createGeometrySimplifier( const QgsSimplifyMethod &simplifyMethod );

//! Equality operator
bool operator==( const QgsSimplifyMethod &v ) const;

//! Inequality operator
bool operator!=( const QgsSimplifyMethod &v ) const;

protected:
//! Simplification method
MethodType mMethodType = QgsSimplifyMethod::NoSimplification;
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ set(TESTS
testqgssettingsregistry.cpp
testqgsshapeburst.cpp
testqgssimplemarker.cpp
testqgssimplifymethod.cpp
testqgssnappingutils.cpp
testqgsspatialindex.cpp
testqgsspatialindexkdbush.cpp
Expand Down
82 changes: 82 additions & 0 deletions tests/src/core/testqgssimplifymethod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/***************************************************************************
testqgssimplifymethod.cpp
--------------------------
Date : Oct 2021
Copyright : (C) 2021 Sandro Santilli
Email : strk at kbt dot io
***************************************************************************
* *
* 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 <QObject>
#include <QString>
#include <QStringList>
#include <QLocale>

#include <memory>

#include "qgssimplifymethod.h"

class TestQgsSimplifyMethod: public QObject
{
Q_OBJECT

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 testCreate();//test creating a simplify method
void testEqualityInequality();//test equality operator

private:
};

void TestQgsSimplifyMethod::initTestCase()
{
// Set up the QgsSettings environment
QCoreApplication::setOrganizationName( QStringLiteral( "QGIS" ) );
QCoreApplication::setOrganizationDomain( QStringLiteral( "qgis.org" ) );
QCoreApplication::setApplicationName( QStringLiteral( "QGIS-TEST" ) );
}

void TestQgsSimplifyMethod::cleanupTestCase()
{

}

void TestQgsSimplifyMethod::init()
{
QLocale::setDefault( QLocale::English );
}

void TestQgsSimplifyMethod::cleanup()
{
QLocale::setDefault( QLocale::English );
}

void TestQgsSimplifyMethod::testCreate()
{
QgsSimplifyMethod method0;
QCOMPARE( method0.methodType(), QgsSimplifyMethod::NoSimplification );
}

void TestQgsSimplifyMethod::testEqualityInequality()
{
QgsSimplifyMethod method0;
QgsSimplifyMethod method1;
method1.setMethodType( QgsSimplifyMethod::OptimizeForRendering );

QVERIFY( method0 == method0 );
QVERIFY( method0 != method1 );
}


QGSTEST_MAIN( TestQgsSimplifyMethod )
#include "testqgssimplifymethod.moc"

0 comments on commit 182732e

Please sign in to comment.