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

This commit is contained in:
Peter Petrik 2018-07-12 15:04:11 +02:00 committed by Martin Dobias
parent bf56bd3ce1
commit 4f7017322f
13 changed files with 448 additions and 0 deletions

View File

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

View 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>

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

@ -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 );

View File

@ -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 )
{

View File

@ -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 );

View File

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

View File

@ -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 ) ),

View File

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

View File

@ -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(

View File

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

View File

@ -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 );
}

View File

@ -0,0 +1,46 @@
/***************************************************************************
qgsmdalsourceselect.h
-------------------
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. *
* *
***************************************************************************/
#ifndef QGMDALSOURCESELECT_H
#define QGMDALSOURCESELECT_H
#include "ui_qgsmdalsourceselectbase.h"
#include "qgsabstractdatasourcewidget.h"
#include "qgis_gui.h"
/**
* \class QgsMdalSourceSelect
* \brief Dialog to select MDAL supported mesh sources
*/
class QgsMdalSourceSelect : public QgsAbstractDataSourceWidget, private Ui::QgsMdalSourceSelectBase
{
Q_OBJECT
public:
//! Constructor
QgsMdalSourceSelect( QWidget *parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None );
public slots:
//! Determines the tables the user selected and closes the dialog
void addButtonClicked() override;
private:
QString mMeshPath;
};
#endif // QGMDALSOURCESELECT_H

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsMdalSourceSelectBase</class>
<widget class="QDialog" name="QgsMdalSourceSelectBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>351</width>
<height>115</height>
</rect>
</property>
<property name="windowTitle">
<string>Add Mesh Layer(s)</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>.</normaloff>.</iconset>
</property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="fileGroupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Source</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Mesh dataset</string>
</property>
</widget>
</item>
<item>
<widget class="QgsFileWidget" name="mFileWidget" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::NoButton</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QgsFileWidget</class>
<extends>QWidget</extends>
<header>qgsfilewidget.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsMdalSourceSelectBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>518</x>
<y>510</y>
</hint>
<hint type="destinationlabel">
<x>551</x>
<y>370</y>
</hint>
</hints>
</connection>
</connections>
</ui>