Skip to content

Commit 6063591

Browse files
authored
allow to drop 2dm files from system file browser (#8987)
* allow to drop 2dm files from system file browser * support non-ascii files for mesh layer
1 parent 1686f0d commit 6063591

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/app/qgisapp.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -6471,6 +6471,12 @@ bool QgisApp::openLayer( const QString &fileName, bool allowInteractive )
64716471

64726472
CPLPopErrorHandler();
64736473

6474+
// Try to load as mesh layer after raster & vector
6475+
if ( !ok )
6476+
{
6477+
ok = addMeshLayer( fileName, fileInfo.completeBaseName(), "mdal" );
6478+
}
6479+
64746480
if ( !ok )
64756481
{
64766482
// we have no idea what this file is...

src/providers/mdal/qgsmdalprovider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ QgsCoordinateReferenceSystem QgsMdalProvider::crs() const
5454
QgsMdalProvider::QgsMdalProvider( const QString &uri, const ProviderOptions &options )
5555
: QgsMeshDataProvider( uri, options )
5656
{
57-
QByteArray curi = uri.toAscii();
57+
QByteArray curi = uri.toUtf8();
5858
mMeshH = MDAL_LoadMesh( curi.constData() );
5959
if ( mMeshH )
6060
{

tests/src/providers/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
99
${CMAKE_SOURCE_DIR}/src/core/auth
1010
${CMAKE_SOURCE_DIR}/src/core/expression
1111
${CMAKE_SOURCE_DIR}/src/core/geometry
12+
${CMAKE_SOURCE_DIR}/src/core/mesh
1213
${CMAKE_SOURCE_DIR}/src/core/metadata
1314
${CMAKE_SOURCE_DIR}/src/core/raster
1415
${CMAKE_SOURCE_DIR}/src/core/symbology

tests/src/providers/testqgsmdalprovider.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <qgis.h>
2828
#include <qgsapplication.h>
2929
#include <qgsproviderregistry.h>
30+
#include <qgsmeshdataprovider.h>
3031

3132
/**
3233
* \ingroup UnitTests
@@ -42,6 +43,7 @@ class TestQgsMdalProvider : public QObject
4243
void init() {}// will be called before each testfunction is executed.
4344
void cleanup() {}// will be called after every testfunction.
4445

46+
void load();
4547
void filters();
4648

4749
private:
@@ -83,5 +85,36 @@ void TestQgsMdalProvider::filters()
8385
QVERIFY( datasetFilters.contains( "*.dat" ) );
8486
}
8587

88+
89+
void TestQgsMdalProvider::load()
90+
{
91+
{
92+
QString file = QStringLiteral( TEST_DATA_DIR ) + "/mesh/quad_flower.2dm";
93+
QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider(
94+
QStringLiteral( "mdal" ),
95+
file,
96+
QgsDataProvider::ProviderOptions()
97+
);
98+
99+
QgsMeshDataProvider *mp = dynamic_cast< QgsMeshDataProvider * >( provider );
100+
QVERIFY( mp );
101+
QVERIFY( mp->isValid() );
102+
delete provider;
103+
}
104+
{
105+
QString file = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/goodluckwiththisfilename.2dm" );
106+
QgsDataProvider *provider = QgsProviderRegistry::instance()->createProvider(
107+
QStringLiteral( "mdal" ),
108+
file,
109+
QgsDataProvider::ProviderOptions()
110+
);
111+
112+
QgsMeshDataProvider *mp = dynamic_cast< QgsMeshDataProvider * >( provider );
113+
QVERIFY( mp );
114+
QVERIFY( !mp->isValid() );
115+
delete provider;
116+
}
117+
}
118+
86119
QGSTEST_MAIN( TestQgsMdalProvider )
87120
#include "testqgsmdalprovider.moc"

0 commit comments

Comments
 (0)