Skip to content

Commit

Permalink
add support for browser dialog for mesh layer extensions too
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik committed Dec 17, 2018
1 parent 39d168c commit e4d4905
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 10 deletions.
4 changes: 4 additions & 0 deletions python/core/auto_generated/qgsproviderregistry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsproviderregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions src/providers/mdal/qgsmdaldataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions src/providers/mdal/qgsmdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
18 changes: 17 additions & 1 deletion src/providers/mdal/qgsmdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

#include <mdal.h>

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e4d4905

Please sign in to comment.