Skip to content
Permalink
Browse files

[mesh] option to add mesh layer from data source manager dialog

  • Loading branch information
PeterPetrik authored and wonder-sk committed Jul 12, 2018
1 parent bf56bd3 commit 4f7017322f02390489c757a423e5f954be00cc72
@@ -170,6 +170,7 @@
<file>themes/default/mActionDistributeTop.svg</file>
<file>themes/default/mActionDistributeVCenter.svg</file>
<file>themes/default/mActionAddLayer.svg</file>
<file>themes/default/mActionAddMeshLayer.svg</file>
<file>themes/default/mActionAddAllToOverview.svg</file>
<file>themes/default/mActionAddArrow.svg</file>
<file>themes/default/mActionAddBasicShape.svg</file>
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
height="24"
width="24"
version="1.1"
id="svg22"
sodipodi:docname="mActionAddMeshLayer.svg"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)">
<metadata
id="metadata28">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs26" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1015"
id="namedview24"
showgrid="false"
inkscape:zoom="27.812867"
inkscape:cx="12.444503"
inkscape:cy="11.691578"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="g20" />
<g
transform="translate(0 -8)"
id="g20">
<g
transform="matrix(.69230769 0 0 .69230769 1.8461539 9.8461539)"
id="g18">
<rect
fill="#5a8c5a"
height="13"
rx="2.6149371"
ry="2.6149368"
width="13"
x="19"
y="19"
id="rect10" />
<path
d="m21.6 25.499999l7.8 0"
style="fill:#fff;fill-rule:evenodd;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"
id="path12" />
<path
d="m25.5 29.399999l0-7.799999"
style="fill:#fff;fill-rule:evenodd;stroke:#fff;stroke-width:2.5999999;stroke-linecap:round;stroke-linejoin:round;overflow:visible"
id="path14" />
<path
d="m20.3 25.499999h10.4c0 0 0 0 0-2.6 0-2.599999-.65-2.599999-5.2-2.599999-4.55 0-5.2 0-5.2 2.599999 0 2.6 0 2.6 0 2.6z"
fill="#fcffff"
fill-rule="evenodd"
opacity=".3"
id="path16" />
</g>
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 1.5100924,9.3486136 1.0426829,30.202271 13.482968,30.022498 13.626786,21.393398 1.114592,21.24958 23.118796,21.501262 23.082841,8.629522 1.4381833,8.9171586 1.5100924,9.8519778 13.698696,21.429353 13.806559,8.8452495 v 0 0 -0.035955"
id="path829"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 22.615432,8.5935674 14.166105,20.961943"
id="path831"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 7.9819171,21.429353 7.8740534,30.166316"
id="path833"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 1.0067283,25.887721 H 13.482968"
id="path835"
inkscape:connector-curvature="0" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 1.5100924,21.177671 13.806559,8.8452495"
id="path837"
inkscape:connector-curvature="0" />
</g>
</svg>
@@ -74,6 +74,13 @@ Emitted when a vector layer has been selected for addition.

If ``providerKey`` is not specified, the default provider key associated with the source
will be used.
%End

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

.. versionadded:: 3.4
%End

void addVectorLayers( const QStringList &layerList, const QString &encoding, const QString &dataSourceType );
@@ -1765,6 +1765,7 @@ void QgisApp::dataSourceManager( const QString &pageName )
this, SLOT( addVectorLayer( QString const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, SIGNAL( addVectorLayers( QStringList const &, QString const &, QString const & ) ),
this, SLOT( addVectorLayers( QStringList const &, QString const &, QString const & ) ) );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::addMeshLayer, this, &QgisApp::addMeshLayer );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::showProgress, this, &QgisApp::showProgress );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::showStatusMessage, this, &QgisApp::showStatusMessage );
connect( mDataSourceManagerDialog, &QgsDataSourceManagerDialog::addDatabaseLayers, this, &QgisApp::addDatabaseLayers );
@@ -4484,6 +4485,54 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
return true;
} // QgisApp::addVectorLayer()


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

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

if ( settings.value( QStringLiteral( "qgis/formatLayerName" ), false ).toBool() )
{
base = QgsMapLayer::formatLayerName( base );
}

QgsDebugMsg( "completeBaseName: " + base );

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

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

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

// Register this layer with the layers registry
freezeCanvases();
bool ok;
layer->loadDefaultStyle( ok );
layer->loadDefaultMetadata( ok );
QgsProject::instance()->addMapLayer( layer.release() );

activateDeactivateLayerRelatedActions( activeLayer() );

// Only update the map if we frozen in this method
// Let the caller do it otherwise
if ( !wasfrozen )
{
freezeCanvases( false );
refreshMapCanvas();
}
return true;
} // QgisApp::addMeshLayer()

// present a dialog to choose zipitem layers
bool QgisApp::askUserForZipItemLayers( const QString &path )
{
@@ -922,6 +922,12 @@ 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 );

@@ -89,6 +89,12 @@ class GUI_EXPORT QgsAbstractDataSourceWidget : public QDialog
*/
void addVectorLayer( const QString &uri, const QString &layerName, const QString &providerKey = QString() );

/**
* Emitted when a mesh layer has been selected for addition.
* \since QGIS 3.4
*/
void addMeshLayer( const QString &uri, const QString &providerKey );

/**
* Emitted when one or more OGR supported layers are selected for addition
* \param layerList list of layers protocol URIs
@@ -161,6 +161,8 @@ void QgsDataSourceManagerDialog::makeConnections( QgsAbstractDataSourceWidget *d
// Raster
connect( dlg, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ),
this, SIGNAL( addRasterLayer( QString const &, QString const &, QString const & ) ) );
// Mesh
connect( dlg, &QgsAbstractDataSourceWidget::addMeshLayer, this, &QgsDataSourceManagerDialog::addMeshLayer );

// Virtual
connect( dlg, SIGNAL( replaceVectorLayer( QString, QString, QString, QString ) ),
@@ -95,6 +95,11 @@ class GUI_EXPORT QgsDataSourceManagerDialog : public QgsOptionsDialogBase, priva
void addRasterLayer();
//! Emitted when a vector layer was selected for addition: for signal forwarding to QgisApp
void addVectorLayer( const QString &vectorLayerPath, const QString &baseName, const QString &providerKey );
/*
* 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 );
//! 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
@@ -9,6 +9,14 @@ SET(MDAL_MOC_HDRS
SET(MDAL_HDRS
)

IF (WITH_GUI)
SET(MDAL_SRCS ${MDAL_SRCS}
qgsmdalsourceselect.cpp
)
SET(MDAL_MOC_HDRS ${MDAL_MOC_HDRS}
qgsmdalsourceselect.h
)
ENDIF ()

########################################################
# Compile internal MDAL
@@ -58,8 +66,13 @@ INCLUDE_DIRECTORIES (
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/auth

${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/gui
${CMAKE_BINARY_DIR}/src/ui

)

QT5_WRAP_CPP(MDAL_MOC_SRCS ${MDAL_MOC_HDRS})
@@ -70,6 +83,12 @@ TARGET_LINK_LIBRARIES (mdalprovider
${MDAL_LIBRARY}
)

IF (WITH_GUI)
TARGET_LINK_LIBRARIES (mdalprovider
qgis_gui
)
ENDIF ()

# clang-tidy
IF(CLANG_TIDY_EXE)
SET_TARGET_PROPERTIES(
@@ -19,6 +19,11 @@

#include "qgsmdalprovider.h"

#ifdef HAVE_GUI
#include "qgssourceselectprovider.h"
#include "qgsmdalsourceselect.h"
#endif

static const QString TEXT_PROVIDER_KEY = QStringLiteral( "mdal" );
static const QString TEXT_PROVIDER_DESCRIPTION = QStringLiteral( "MDAL provider" );

@@ -229,3 +234,32 @@ QGISEXTERN void cleanupProvider()
{
}

#ifdef HAVE_GUI

//! Provider for mdal mesh source select
class QgsMdalMeshSourceSelectProvider : public QgsSourceSelectProvider
{
public:

QString providerKey() const override { return QStringLiteral( "mdal" ); }
QString text() const override { return QObject::tr( "Mesh" ); }
int ordering() const override { return QgsSourceSelectProvider::OrderLocalProvider + 22; }
QIcon icon() const override { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMeshLayer.svg" ) ); }
QgsAbstractDataSourceWidget *createDataSourceWidget( QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::Widget, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Embedded ) const override
{
return new QgsMdalSourceSelect( parent, fl, widgetMode );
}
};


QGISEXTERN QList<QgsSourceSelectProvider *> *sourceSelectProviders()
{
QList<QgsSourceSelectProvider *> *providers = new QList<QgsSourceSelectProvider *>();

*providers
<< new QgsMdalMeshSourceSelectProvider;

return providers;
}

#endif
@@ -0,0 +1,59 @@
/***************************************************************************
qgsmdalsourceselect.cpp
-----------------------
begin : July 2018
copyright : (C) 2018 by Peter Petrik
email : zilolv at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include <QMessageBox>

#include "qgsmdalsourceselect.h"
#include "qgsproviderregistry.h"
#include "ogr/qgsogrhelperfunctions.h"

QgsMdalSourceSelect::QgsMdalSourceSelect( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode ):
QgsAbstractDataSourceWidget( parent, fl, widgetMode )
{
setupUi( this );
setupButtons( buttonBox );

mFileWidget->setDialogTitle( tr( "Open MDAL Supported Mesh Dataset(s)" ) );
mFileWidget->setFilter( QStringLiteral( "Mesh File (*.2dm);;All files (*.*)" ) );
mFileWidget->setStorageMode( QgsFileWidget::GetMultipleFiles );
connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
{
mMeshPath = path;
emit enableButtons( ! mMeshPath.isEmpty() );
} );
}

void QgsMdalSourceSelect::addButtonClicked()
{
if ( mMeshPath.isEmpty() )
{
QMessageBox::information( this,
tr( "Add mesh layer" ),
tr( "No layers selected." ) );
return;
}

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

QGISEXTERN QgsMdalSourceSelect *selectWidget( QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
{
return new QgsMdalSourceSelect( parent, fl, widgetMode );
}

0 comments on commit 4f70173

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