Skip to content

Commit

Permalink
fix #20316 not possible to assign mesh crs
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Jan 15, 2019
1 parent 6957009 commit 9aacf4b
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app/mesh/qgsmeshlayerproperties.cpp
Expand Up @@ -111,6 +111,7 @@ void QgsMeshLayerProperties::syncToLayer()
*/ */
mLayerOrigNameLineEd->setText( mMeshLayer->name() ); mLayerOrigNameLineEd->setText( mMeshLayer->name() );
leDisplayName->setText( mMeshLayer->name() ); leDisplayName->setText( mMeshLayer->name() );
whileBlocking( mCrsSelector )->setCrs( mMeshLayer->crs() );


if ( mMeshLayer && mMeshLayer->dataProvider() ) if ( mMeshLayer && mMeshLayer->dataProvider() )
{ {
Expand Down Expand Up @@ -186,6 +187,7 @@ void QgsMeshLayerProperties::apply()


void QgsMeshLayerProperties::changeCrs( const QgsCoordinateReferenceSystem &crs ) void QgsMeshLayerProperties::changeCrs( const QgsCoordinateReferenceSystem &crs )
{ {
QgisApp::instance()->askUserForDatumTransform( crs, QgsProject::instance()->crs() );
mMeshLayer->setCrs( crs ); mMeshLayer->setCrs( crs );
} }


Expand Down
2 changes: 2 additions & 0 deletions src/app/mesh/qgsmeshlayerproperties.h
Expand Up @@ -65,6 +65,8 @@ class APP_EXPORT QgsMeshLayerProperties : public QgsOptionsDialogBase, private U


//! \brief Pointer to the mesh layer that this property dilog changes the behavior of. //! \brief Pointer to the mesh layer that this property dilog changes the behavior of.
QgsMeshLayer *mMeshLayer = nullptr; QgsMeshLayer *mMeshLayer = nullptr;

friend class TestQgsMeshLayerPropertiesDialog;
}; };




Expand Down
1 change: 1 addition & 0 deletions tests/src/app/CMakeLists.txt
Expand Up @@ -121,3 +121,4 @@ ADD_QGIS_TEST(maptooltrimextendfeaturetest testqgsmaptooltrimextendfeature.cpp)
ADD_QGIS_TEST(projectproperties testqgsprojectproperties.cpp) ADD_QGIS_TEST(projectproperties testqgsprojectproperties.cpp)
ADD_QGIS_TEST(layoutvaliditychecks testqgsapplayoutvaliditychecks.cpp) ADD_QGIS_TEST(layoutvaliditychecks testqgsapplayoutvaliditychecks.cpp)
ADD_QGIS_TEST(meshcalculator testqgsmeshcalculatordialog.cpp) ADD_QGIS_TEST(meshcalculator testqgsmeshcalculatordialog.cpp)
ADD_QGIS_TEST(meshlayerpropertiesdialog testqgsmeshlayerpropertiesdialog.cpp)
87 changes: 87 additions & 0 deletions tests/src/app/testqgsmeshlayerpropertiesdialog.cpp
@@ -0,0 +1,87 @@
/***************************************************************************
testqgsmeshlayerpropertiesdialog.cpp
------------------------------------
Date : January 2019
Copyright : (C) 2019 by Peter Petrik
Email : zilolv 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 "qgstest.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsmeshlayer.h"
#include "qgsmeshdataprovider.h"
#include "qgsmeshlayerproperties.h"
#include "qgsfeedback.h"
#include "qgis.h"
#include "qgsmapcanvas.h"

#include <QTemporaryFile>

/**
* \ingroup UnitTests
* This is a unit test for the mesh layer properties dialog
*/
class TestQgsMeshLayerPropertiesDialog : public QObject
{
Q_OBJECT
public:
TestQgsMeshLayerPropertiesDialog();

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 testCrs();

private:
QgisApp *mQgisApp = nullptr;
QgsMeshLayer *mpMeshLayer = nullptr;
};

TestQgsMeshLayerPropertiesDialog::TestQgsMeshLayerPropertiesDialog() = default;

//runs before all tests
void TestQgsMeshLayerPropertiesDialog::initTestCase()
{
qDebug() << "TestQgisAppClipboard::initTestCase()";
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
mQgisApp = new QgisApp();

QString testDataDir = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/mesh/" );
QString uri( testDataDir + "/quad_and_triangle.2dm" );
mpMeshLayer = new QgsMeshLayer( uri, "Triangle and Quad MDAL", "mdal" );

QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpMeshLayer );
}

//runs after all tests
void TestQgsMeshLayerPropertiesDialog::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsMeshLayerPropertiesDialog::testCrs()
{
std::unique_ptr< QgsMeshLayerProperties > dialog = qgis::make_unique< QgsMeshLayerProperties> ( mpMeshLayer,
mQgisApp->mapCanvas()
);
QCOMPARE( dialog->mCrsSelector->crs(), mpMeshLayer->crs() );
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem::fromEpsgId( 27700 );
dialog->mCrsSelector->setCrs( crs );
QCOMPARE( crs, mpMeshLayer->crs() );
}

QGSTEST_MAIN( TestQgsMeshLayerPropertiesDialog )
#include "testqgsmeshlayerpropertiesdialog.moc"

0 comments on commit 9aacf4b

Please sign in to comment.