Skip to content
Permalink
Browse files

add support for browser dialog for mesh layer extensions too

  • Loading branch information
PeterPetrik committed Dec 17, 2018
1 parent 39d168c commit e4d490531ce6f992d5d64a6c30acae11854b4ae6
@@ -191,6 +191,8 @@ supported by all data providers.
This walks through all data providers appending calls to their
fileMeshFilters to a string, which is then returned.

.. seealso:: :py:func:`fileMeshDatasetFilters`

.. versionadded:: 3.6
%End

@@ -204,6 +206,8 @@ supported by all data providers.
This walks through all data providers appending calls to their
fileMeshFilters to a string, which is then returned.

.. seealso:: :py:func:`fileMeshFilters`

.. versionadded:: 3.6
%End

@@ -189,6 +189,8 @@ class CORE_EXPORT QgsProviderRegistry
This walks through all data providers appending calls to their
fileMeshFilters to a string, which is then returned.
\see fileMeshDatasetFilters()
\since QGIS 3.6
*/
virtual QString fileMeshFilters() const;
@@ -202,6 +204,8 @@ class CORE_EXPORT QgsProviderRegistry
This walks through all data providers appending calls to their
fileMeshFilters to a string, which is then returned.
\see fileMeshFilters()
\since QGIS 3.6
*/
virtual QString fileMeshDatasetFilters() const;
@@ -64,15 +64,10 @@ QGISEXTERN QgsDataItem *dataItem( QString path, QgsDataItem *parentItem )
static std::once_flag initialized;
std::call_once( initialized, [ = ]( )
{
// TODO ask MDAL for extensions !
sExtensions << QStringLiteral( "2dm" )
<< QStringLiteral( "grb" )
<< QStringLiteral( "grb2" )
<< QStringLiteral( "bin" )
<< QStringLiteral( "grib" )
<< QStringLiteral( "grib1" )
<< QStringLiteral( "grib2" )
<< QStringLiteral( "nc" );
QStringList meshExtensions;
QStringList datasetsExtensions;
QgsMdalProvider::fileMeshExtensions( sExtensions, datasetsExtensions );
Q_UNUSED( datasetsExtensions );
} );

// Filter files by extension
@@ -241,6 +241,58 @@ void QgsMdalProvider::fileMeshFilters( QString &fileMeshFiltersString, QString &
QgsDebugMsg( "Mesh dataset filter list built: " + fileMeshDatasetFiltersString );
}

void QgsMdalProvider::fileMeshExtensions( QStringList &fileMeshExtensions,
QStringList &fileMeshDatasetExtensions )
{
DriverH mdalDriver;

// Grind through all the drivers and their respective metadata.
// We'll add a file extension for those drivers that have a file
// extension defined for them

fileMeshExtensions.clear();
fileMeshDatasetExtensions.clear();

int driverCount = MDAL_driverCount();

for ( int i = 0; i < driverCount; ++i )
{
mdalDriver = MDAL_driverFromIndex( i );
if ( !mdalDriver )
{
QgsLogger::warning( "unable to get driver " + QString::number( i ) );
continue;
}

const QString driverFilters = MDAL_DR_filters( mdalDriver );
QStringList extensions = driverFilters.split( QStringLiteral( ";;" ), QString::SkipEmptyParts );
bool isMeshDriver = MDAL_DR_meshLoadCapability( mdalDriver );

if ( !extensions.isEmpty() )
{
for ( auto ext : extensions )
{
ext.remove( QStringLiteral( "*." ) );
if ( isMeshDriver )
fileMeshExtensions += ext;
else
fileMeshDatasetExtensions += ext;
}
}
}

// sort file extensions alphabetically
fileMeshExtensions.sort();
fileMeshDatasetExtensions.sort();

// remove duplicates
fileMeshExtensions.erase( std::unique( fileMeshExtensions.begin(), fileMeshExtensions.end() ), fileMeshExtensions.end() );
fileMeshDatasetExtensions.erase( std::unique( fileMeshDatasetExtensions.begin(), fileMeshDatasetExtensions.end() ), fileMeshDatasetExtensions.end() );

QgsDebugMsg( "Mesh extensions list built: " + fileMeshExtensions.join( QStringLiteral( ";;" ) ) );
QgsDebugMsg( "Mesh dataset extensions list built: " + fileMeshDatasetExtensions.join( QStringLiteral( ";;" ) ) );
}

/*----------------------------------------------------------------------------------------------*/

bool QgsMdalProvider::addDataset( const QString &uri )
@@ -18,6 +18,7 @@

#include <QString>
#include <QVector>
#include <QStringList>

#include <mdal.h>

@@ -70,12 +71,27 @@ class QgsMdalProvider : public QgsMeshDataProvider
QgsRectangle extent() const override;

/**
* Returns filters for meshes and datasets to be used in Open File Dialogs
* Returns file filters for meshes and datasets to be used in Open File Dialogs
* \param fileMeshFiltersString file mesh filters
* \param fileMeshDatasetFiltersString file mesh datasets filters
*
* \see fileMeshExtensions()
*
* \since QGIS 3.6
*/
static void fileMeshFilters( QString &fileMeshFiltersString, QString &fileMeshDatasetFiltersString );

/**
* Returns file extensions for meshes and datasets
* \param fileMeshExtensions file mesh extensions
* \param fileMeshDatasetExtensions file mesh datasets extensions
*
* \see fileMeshFilters()
*
* \since QGIS 3.6
*/
static void fileMeshExtensions( QStringList &fileMeshExtensions, QStringList &fileMeshDatasetExtensions );

private:
QVector<QgsMeshVertex> vertices( ) const;
QVector<QgsMeshFace> faces( ) const;

0 comments on commit e4d4905

Please sign in to comment.
You can’t perform that action at this time.