Skip to content

Commit

Permalink
[feature] addMeshLayer to qgsinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterPetrik authored and wonder-sk committed Jul 13, 2018
1 parent c8b94d3 commit e135b9c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 18 deletions.
5 changes: 5 additions & 0 deletions python/gui/auto_generated/qgisinterface.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 8 additions & 8 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
{
Expand All @@ -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() );

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 );

Expand Down
5 changes: 5 additions & 0 deletions src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisappinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgisinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class QgsVectorLayerTools;
class QgsOptionsWidgetFactory;
class QgsLocatorFilter;
class QgsStatusBar;
class QgsMeshLayer;

#include <QObject>
#include <QFont>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsabstractdatasourcewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsdatasourcemanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mdal/qgsmdalsourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) );
}
}

Expand Down

0 comments on commit e135b9c

Please sign in to comment.