Skip to content
Permalink
Browse files

[feature] addMeshLayer to qgsinterface

  • Loading branch information
PeterPetrik authored and wonder-sk committed Jul 13, 2018
1 parent c8b94d3 commit e135b9cf9fb66f4dfda22c418ce54469dc287abf
@@ -629,6 +629,11 @@ Add a raster layer given a raster layer file name
virtual QgsRasterLayer *addRasterLayer( const QString &url, const QString &layerName, const QString &providerKey ) = 0;
%Docstring
Add a WMS layer
%End

virtual QgsMeshLayer *addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey ) = 0;
%Docstring
Add a mesh layer
%End

virtual bool addProject( const QString &project ) = 0;
@@ -76,7 +76,7 @@ If ``providerKey`` is not specified, the default provider key associated with th
will be used.
%End

void addMeshLayer( const QString &uri, const QString &providerKey );
void addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey );
%Docstring
Emitted when a mesh layer has been selected for addition.

@@ -4486,13 +4486,12 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
} // QgisApp::addVectorLayer()


bool QgisApp::addMeshLayer( const QString &uri, const QString &providerKey )
QgsMeshLayer *QgisApp::addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey )
{
bool wasfrozen = mMapCanvas->isFrozen();
QgsSettings settings;

QFileInfo fi( uri );
QString base = fi.completeBaseName();
QString base( baseName );

if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
@@ -4503,23 +4502,24 @@ bool QgisApp::addMeshLayer( const QString &uri, const QString &providerKey )

// create the layer
QgsMeshLayer::LayerOptions options;
std::unique_ptr<QgsMeshLayer> layer( new QgsMeshLayer( uri, base, providerKey, options ) );
std::unique_ptr<QgsMeshLayer> layer( new QgsMeshLayer( url, base, providerKey, options ) );

if ( ! layer || !layer->isValid() )
{
QString msg = tr( "%1 is not a valid or recognized data source." ).arg( uri );
QString msg = tr( "%1 is not a valid or recognized data source." ).arg( url );
messageBar()->pushMessage( tr( "Invalid Data Source" ), msg, Qgis::Critical, messageTimeout() );

// since the layer is bad, stomp on it
return false;
return nullptr;
}

// Register this layer with the layers registry
freezeCanvases();

QgsProject::instance()->addMapLayer( layer.get() );
bool ok;
layer->loadDefaultStyle( ok );
layer->loadDefaultMetadata( ok );
QgsProject::instance()->addMapLayer( layer.release() );

activateDeactivateLayerRelatedActions( activeLayer() );

@@ -4530,7 +4530,7 @@ bool QgisApp::addMeshLayer( const QString &uri, const QString &providerKey )
freezeCanvases( false );
refreshMapCanvas();
}
return true;
return layer.release();
} // QgisApp::addMeshLayer()

// present a dialog to choose zipitem layers
@@ -905,6 +905,12 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
QgsVectorLayer *addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );

/**
* Adds a mesh layer directly without prompting user for location
* \returns true if successfully added layer
*/
QgsMeshLayer *addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey );

/**
* \brief overloaded version of the private addLayer method that takes a list of
* file names instead of prompting user with a dialog.
@@ -922,12 +928,6 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*/
bool addRasterLayers( const QStringList &layerQStringList, bool guiWarning = true );

/**
* Adds a mesh layer directly without prompting user for location
* \returns true if successfully added layer
*/
bool addMeshLayer( const QString &uri, const QString &providerKey );

//! Open a plugin layer using its provider
QgsPluginLayer *addPluginLayer( const QString &uri, const QString &baseName, const QString &providerKey );

@@ -157,6 +157,11 @@ QgsRasterLayer *QgisAppInterface::addRasterLayer( const QString &url, const QStr
return qgis->addRasterLayer( url, baseName, providerKey );
}

QgsMeshLayer *QgisAppInterface::addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey )
{
return qgis->addMeshLayer( url, baseName, providerKey );
}

bool QgisAppInterface::addProject( const QString &projectName )
{
return qgis->addProject( projectName );
@@ -75,6 +75,8 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
QgsRasterLayer *addRasterLayer( const QString &rasterLayerPath, const QString &baseName ) override;
//! Add a WMS layer
QgsRasterLayer *addRasterLayer( const QString &url, const QString &baseName, const QString &providerKey ) override;
//! Add a mesh layer
QgsMeshLayer *addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey ) override;

//! Add a project
bool addProject( const QString &projectName ) override;
@@ -47,6 +47,7 @@ class QgsVectorLayerTools;
class QgsOptionsWidgetFactory;
class QgsLocatorFilter;
class QgsStatusBar;
class QgsMeshLayer;

#include <QObject>
#include <QFont>
@@ -546,6 +547,9 @@ class GUI_EXPORT QgisInterface : public QObject
//! Add a WMS layer
virtual QgsRasterLayer *addRasterLayer( const QString &url, const QString &layerName, const QString &providerKey ) = 0;

//! Add a mesh layer
virtual QgsMeshLayer *addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey ) = 0;

//! Add a project
virtual bool addProject( const QString &project ) = 0;
//! Start a blank project
@@ -93,7 +93,7 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
* Emitted when a mesh layer has been selected for addition.
* \since QGIS 3.4
*/
void addMeshLayer( const QString &uri, const QString &providerKey );
void addMeshLayer( const QString &url, const QString &baseName, const QString &providerKey );

/**
* Emitted when one or more OGR supported layers are selected for addition
@@ -100,7 +100,7 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
* Emitted when a mesh layer was selected for addition: for signal forwarding to QgisApp\
* \since QGIS 3.4
*/
void addMeshLayer( const QString &uri, const QString &providerKey );
void addMeshLayer( const QString &uri, const QString &baseName, const QString &providerKey );
//! Replace the selected layer by a vector layer defined by uri, layer name, data source uri
void replaceSelectedVectorLayer( const QString &oldId, const QString &uri, const QString &layerName, const QString &provider );
//! Emitted when a one or more layer were selected for addition: for signal forwarding to QgisApp
@@ -49,7 +49,7 @@ void QgsMdalSourceSelect::addButtonClicked()

for ( const QString &path : QgsFileWidget::splitFilePaths( mMeshPath ) )
{
emit addMeshLayer( path, QStringLiteral( "mdal" ) );
emit addMeshLayer( path, QFileInfo( path ).baseName(), QStringLiteral( "mdal" ) );
}
}

0 comments on commit e135b9c

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