Skip to content

Commit

Permalink
Merge pull request #35364 from nyalldawson/new_table_panel_prc
Browse files Browse the repository at this point in the history
Allowing saving outputs direct to more database formats (and other nice stuff)
  • Loading branch information
elpaso committed Mar 26, 2020
2 parents a418fc9 + f131355 commit ff0b012
Show file tree
Hide file tree
Showing 15 changed files with 306 additions and 62 deletions.
Expand Up @@ -65,6 +65,14 @@ Emitted whenever the "skip output" option is toggled in the widget.
%Docstring
Emitted whenever the destination value is changed in the widget.
%End
protected:

virtual void dragEnterEvent( QDragEnterEvent *event );

virtual void dragLeaveEvent( QDragLeaveEvent *event );

virtual void dropEvent( QDropEvent *event );


};

Expand Down
11 changes: 11 additions & 0 deletions python/gui/auto_generated/qgsnewdatabasetablenamewidget.sip.in
Expand Up @@ -44,6 +44,13 @@ Constructs a new QgsNewDatabaseTableNameWidget
shown in the widget, if not specified all providers data items with database
capabilities will be shown
:param parent: optional parent for this widget
%End

void setAcceptButtonVisible( bool visible );
%Docstring
Sets whether the optional "Ok"/accept button should be visible.

By default this is hidden, to better allow the widget to be embedded inside other widgets and dialogs.
%End

QString schema() const;
Expand Down Expand Up @@ -121,6 +128,10 @@ This signal is emitted when the URI of the new table changes, whether or not it
:param uri: URI string representation
%End

void accepted();
%Docstring
Emitted when the OK/accept button is clicked.
%End

};

Expand Down
2 changes: 0 additions & 2 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -813,14 +813,12 @@ QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingPara
QVariant val = value;

QgsProject *destinationProject = nullptr;
QVariantMap createOptions;
QString destName;
if ( val.canConvert<QgsProcessingOutputLayerDefinition>() )
{
// input is a QgsProcessingOutputLayerDefinition - get extra properties from it
QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( val );
destinationProject = fromVar.destinationProject;
createOptions = fromVar.createOptions;
val = fromVar.sink;
destName = fromVar.destinationName;
}
Expand Down
20 changes: 15 additions & 5 deletions src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -602,16 +602,26 @@ QString QgsProcessingUtils::stringToPythonLiteral( const QString &string )
void QgsProcessingUtils::parseDestinationString( QString &destination, QString &providerKey, QString &uri, QString &layerName, QString &format, QMap<QString, QVariant> &options, bool &useWriter, QString &extension )
{
extension.clear();
QRegularExpression splitRx( QStringLiteral( "^(.{3,}?):(.*)$" ) );
QRegularExpressionMatch match = splitRx.match( destination );
if ( match.hasMatch() )
bool matched = decodeProviderKeyAndUri( destination, providerKey, uri );

if ( !matched )
{
QRegularExpression splitRx( QStringLiteral( "^(.{3,}?):(.*)$" ) );
QRegularExpressionMatch match = splitRx.match( destination );
if ( match.hasMatch() )
{
providerKey = match.captured( 1 );
uri = match.captured( 2 );
matched = true;
}
}

if ( matched )
{
providerKey = match.captured( 1 );
if ( providerKey == QStringLiteral( "postgis" ) ) // older processing used "postgis" instead of "postgres"
{
providerKey = QStringLiteral( "postgres" );
}
uri = match.captured( 2 );
if ( providerKey == QLatin1String( "ogr" ) )
{
QgsDataSourceUri dsUri( uri );
Expand Down
20 changes: 13 additions & 7 deletions src/gui/processing/qgsprocessingmaplayercombobox.cpp
Expand Up @@ -382,36 +382,40 @@ QString QgsProcessingMapLayerComboBox::compatibleUriFromMimeData( const QMimeDat
{
if ( ( mParameter->type() == QgsProcessingParameterFeatureSource::typeName()
|| mParameter->type() == QgsProcessingParameterVectorLayer::typeName() )
&& u.layerType == QLatin1String( "vector" ) && u.providerKey == QLatin1String( "ogr" ) )
&& u.layerType == QLatin1String( "vector" ) )
{
QList< int > dataTypes = mParameter->type() == QgsProcessingParameterFeatureSource::typeName() ? static_cast< QgsProcessingParameterFeatureSource * >( mParameter.get() )->dataTypes()
: ( mParameter->type() == QgsProcessingParameterVectorLayer::typeName() ? static_cast<QgsProcessingParameterVectorLayer *>( mParameter.get() )->dataTypes()
: QList< int >() );
bool acceptable = false;
switch ( QgsWkbTypes::geometryType( u.wkbType ) )
{
case QgsWkbTypes::UnknownGeometry:
return u.uri;
acceptable = true;
break;

case QgsWkbTypes::PointGeometry:
if ( dataTypes.isEmpty() || dataTypes.contains( QgsProcessing::TypeVector ) || dataTypes.contains( QgsProcessing::TypeVectorAnyGeometry ) || dataTypes.contains( QgsProcessing::TypeVectorPoint ) )
return u.uri;
acceptable = true;
break;

case QgsWkbTypes::LineGeometry:
if ( dataTypes.isEmpty() || dataTypes.contains( QgsProcessing::TypeVector ) || dataTypes.contains( QgsProcessing::TypeVectorAnyGeometry ) || dataTypes.contains( QgsProcessing::TypeVectorLine ) )
return u.uri;
acceptable = true;
break;

case QgsWkbTypes::PolygonGeometry:
if ( dataTypes.isEmpty() || dataTypes.contains( QgsProcessing::TypeVector ) || dataTypes.contains( QgsProcessing::TypeVectorAnyGeometry ) || dataTypes.contains( QgsProcessing::TypeVectorPolygon ) )
return u.uri;
acceptable = true;
break;

case QgsWkbTypes::NullGeometry:
if ( dataTypes.contains( QgsProcessing::TypeVector ) )
return u.uri;
acceptable = true;
break;
}
if ( acceptable )
return u.providerKey != QLatin1String( "ogr" ) ? QgsProcessingUtils::encodeProviderKeyAndUri( u.providerKey, u.uri ) : u.uri;
}
else if ( mParameter->type() == QgsProcessingParameterRasterLayer::typeName()
&& u.layerType == QLatin1String( "raster" ) && u.providerKey == QLatin1String( "gdal" ) )
Expand Down Expand Up @@ -648,7 +652,9 @@ void QgsProcessingMapLayerComboBox::browseForLayer()
connect( widget, &QgsPanelWidget::panelAccepted, this, [ = ]()
{
QgsProcessingContext context;
if ( widget->uri().providerKey == QLatin1String( "ogr" ) )
if ( widget->uri().uri.isEmpty() )
setValue( QVariant(), context );
else if ( widget->uri().providerKey == QLatin1String( "ogr" ) )
setValue( widget->uri().uri, context );
else
setValue( QgsProcessingUtils::encodeProviderKeyAndUri( widget->uri().providerKey, widget->uri().uri ), context );
Expand Down

0 comments on commit ff0b012

Please sign in to comment.