Skip to content
Permalink
Browse files

Code cleanups, GUI improvements

  • Loading branch information
wonder-sk committed May 5, 2020
1 parent 49f832a commit a9701072de8b1acdc1462b09c4a2221502146ae5
@@ -106,7 +106,7 @@ QgsProcessingAlgorithm *QgsWriteVectorTilesXyzAlgorithm::createInstance() const

void QgsWriteVectorTilesXyzAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterFolderDestination( QStringLiteral( "OUTPUT_DIR" ), QObject::tr( "Output directry" ) ) );
addParameter( new QgsProcessingParameterFolderDestination( QStringLiteral( "OUTPUT_DIR" ), QObject::tr( "Output directory" ) ) );
addParameter( new QgsProcessingParameterString( QStringLiteral( "XYZ_TEMPLATE" ), QObject::tr( "File template" ), QStringLiteral( "{z}/{x}/{y}.pbf" ) ) );

addBaseParameters();
@@ -97,8 +97,6 @@ QString QgsProcessingParameterVectorTileWriterLayers::asPythonString( QgsProcess
case QgsProcessing::PythonQgsProcessingAlgorithmSubclass:
{
QString code = QStringLiteral( "QgsProcessingParameterVectorTileWriterLayers('%1', '%2'" ).arg( name(), description() );
//if ( mFlags & FlagOptional )
// code += QStringLiteral( ", optional=True" );
code += QStringLiteral( ")" );
return code;
}
@@ -16,13 +16,38 @@
#ifndef QGSPROCESSINGPARAMETERVECTORTILEWRITERLAYERS_H
#define QGSPROCESSINGPARAMETERVECTORTILEWRITERLAYERS_H

#include "qgsprocessingparameters.h"
#define SIP_NO_FILE

#include "qgsprocessingparameters.h"
#include "qgsprocessingparametertype.h"
#include "qgsvectortilewriter.h"


/**
* A parameter for processing algorithms that need a list of input vector layers for writing
* of vector tiles - this parameter provides processing framework's adapter for QList<QgsVectorTileWriter::Layer>.
*
* A valid value for this parameter is a list (QVariantList), where each item is a map (QVariantMap) in this form:
* {
* 'layer': <string> or <QgsMapLayer>,
* // key-value pairs below are optional
* 'layerName': <string>,
* 'filterExpression': <string>,
* 'minZoom': <int>,
* 'maxZoom': <int>
* }
*
* Static functions parametersAsLayers(), variantMapAsLayer(), layerAsVariantMap() provide conversion between
* QgsVectorTileWriter::Layer representation and QVariant representation.
*
* \ingroup core
* \note This class is not a part of public API.
* \since QGIS 3.14
*/
class CORE_EXPORT QgsProcessingParameterVectorTileWriterLayers : public QgsProcessingParameterDefinition
{
public:
//! Constructor for QgsProcessingParameterVectorTileWriterLayers.
QgsProcessingParameterVectorTileWriterLayers( const QString &name, const QString &description = QString() );

QgsProcessingParameterDefinition *clone() const override;
@@ -31,26 +56,29 @@ class CORE_EXPORT QgsProcessingParameterVectorTileWriterLayers : public QgsProce
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
QString asPythonString( QgsProcessing::PythonOutputType outputType = QgsProcessing::PythonQgsProcessingAlgorithmSubclass ) const override;

//! Returns the type name for the parameter class.
static QString typeName() { return QStringLiteral( "vectortilewriterlayers" ); }

//! Converts a QVariant value (a QVariantList) to a list of input layers
static QList<QgsVectorTileWriter::Layer> parameterAsLayers( const QVariant &layersVariant, QgsProcessingContext &context );

//! Converts a QVariant value (a QVariantMap) to a single input layer
static QgsVectorTileWriter::Layer variantMapAsLayer( const QVariantMap &layerVariantMap, QgsProcessingContext &context );
//! Converts a single input layer to QVariant representation (a QVariantMap)
static QVariantMap layerAsVariantMap( const QgsVectorTileWriter::Layer &layer );

};

#include "qgsprocessingparametertype.h"

/**
* A parameter for processing algorithms which accepts multiple map layers.
* Parameter type definition for QgsProcessingParameterVectorTileWriterLayers.
*
* \ingroup core
* \note No Python bindings available. Get your copy from QgsApplication.processingRegistry().parameterType('vectortilewriterlayers')
* \since QGIS 3.2
* \note This class is not a part of public API.
* \since QGIS 3.14
*/
class CORE_EXPORT QgsProcessingParameterTypeVectorTileWriterLayers : public QgsProcessingParameterType
class QgsProcessingParameterTypeVectorTileWriterLayers : public QgsProcessingParameterType
{
public:
QgsProcessingParameterDefinition *create( const QString &name ) const override SIP_FACTORY
{
return new QgsProcessingParameterVectorTileWriterLayers( name );
@@ -70,25 +98,6 @@ class CORE_EXPORT QgsProcessingParameterTypeVectorTileWriterLayers : public QgsP
{
return QgsProcessingParameterVectorTileWriterLayers::typeName();
}
/*
QString pythonImportString() const override
{
return QStringLiteral( "from qgis.core import QgsProcessingParameterMultipleLayers" );
}
QString className() const override
{
return QStringLiteral( "QgsProcessingParameterMultipleLayers" );
}
QStringList acceptedPythonTypes() const override
{
return QStringList() << QObject::tr( "list[str]: list of layer IDs" )
<< QObject::tr( "list[str]: list of layer names" )
<< QObject::tr( "list[str]: list of layer sources" )
<< QStringLiteral( "list[QgsMapLayer]" )
<< QStringLiteral( "QgsProperty" );
}*/
};


@@ -47,16 +47,21 @@ QgsProcessingVectorTileWriteLayerDetailsWidget::QgsProcessingVectorTileWriteLaye
if ( !mLayer )
return;

mSpinMinZoom->setClearValue( -1, tr( "Not set" ) );
mSpinMaxZoom->setClearValue( -1, tr( "Not set" ) );
mEditFilterExpression->setMultiLine( true );
mEditFilterExpression->setLayer( mLayer );

mSpinMinZoom->setValue( layer.minZoom() );
mSpinMaxZoom->setValue( layer.maxZoom() );
mEditLayerName->setText( layer.layerName() );
mEditLayerName->setPlaceholderText( mLayer->name() );
mEditFilterExpression->setPlainText( layer.filterExpression() );
mEditFilterExpression->setExpression( layer.filterExpression() );

connect( mSpinMinZoom, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( mSpinMaxZoom, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsPanelWidget::widgetChanged );
connect( mEditLayerName, &QLineEdit::textChanged, this, &QgsPanelWidget::widgetChanged );
// TODO?? connect( mEditFilterExpression, &QTextEdit::textChanged, this, &QgsPanelWidget::widgetChanged );
connect( mEditFilterExpression, &QgsExpressionLineEdit::expressionChanged, this, &QgsPanelWidget::widgetChanged );
}

QVariant QgsProcessingVectorTileWriteLayerDetailsWidget::value() const
@@ -65,7 +70,7 @@ QVariant QgsProcessingVectorTileWriteLayerDetailsWidget::value() const
layer.setMinZoom( mSpinMinZoom->value() );
layer.setMaxZoom( mSpinMaxZoom->value() );
layer.setLayerName( mEditLayerName->text() );
layer.setFilterExpression( mEditFilterExpression->toPlainText() );
layer.setFilterExpression( mEditFilterExpression->expression() );
return QgsProcessingParameterVectorTileWriterLayers::layerAsVariantMap( layer );
}

@@ -121,9 +126,8 @@ QgsProcessingVectorTileWriterLayersPanelWidget::QgsProcessingVectorTileWriterLay

QString title = layer->name();

addOption( vm, title, false ); //, true );
addOption( vm, title, false );
}

}


@@ -144,25 +148,28 @@ void QgsProcessingVectorTileWriterLayersPanelWidget::configureLayer()
{
QgsProcessingVectorTileWriteLayerDetailsWidget *widget = new QgsProcessingVectorTileWriteLayerDetailsWidget( value, mProject );
widget->setPanelTitle( tr( "Configure Layer" ) );
widget->buttonBox()->hide();

connect( widget, &QgsProcessingVectorTileWriteLayerDetailsWidget::widgetChanged, this, [ = ]()
{
setItemValue( item, widget->value() );
} );
// connect( widget, &QgsProcessingVectorTileWriteLayerDetailsWidget::acceptClicked, widget, &QgsPanelWidget::acceptPanel );
panel->openPanel( widget );
}
else
{
// TODO
#if 0
QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel, this, nullptr );
dlg.setProject( mProject );
QDialog dlg;
dlg.setWindowTitle( tr( "Configure Layer" ) );
QVBoxLayout *vLayout = new QVBoxLayout();
QgsProcessingVectorTileWriteLayerDetailsWidget *widget = new QgsProcessingVectorTileWriteLayerDetailsWidget( value, mProject );
vLayout->addWidget( widget );
connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
dlg.setLayout( vLayout );
if ( dlg.exec() )
{
setValue( dlg.selectedOptions() );
setItemValue( item, widget->value() );
}
#endif
}

}
@@ -197,12 +204,17 @@ QString QgsProcessingVectorTileWriterLayersPanelWidget::titleForLayer( const Qgs
QString title = layer.layer()->name();

// add more details
if ( layer.minZoom() >= 0 || layer.maxZoom() >= 0 )
title += QString( " [zoom: %1 - %2]" ).arg( layer.minZoom() ).arg( layer.maxZoom() );
if ( layer.minZoom() >= 0 && layer.maxZoom() >= 0 )
title += tr( " [zoom %1...%2]" ).arg( layer.minZoom() ).arg( layer.maxZoom() );
else if ( layer.minZoom() >= 0 )
title += tr( " [zoom >= %1]" ).arg( layer.minZoom() );
else if ( layer.maxZoom() >= 0 )
title += tr( " [zoom <= %1]" ).arg( layer.maxZoom() );

if ( !layer.layerName().isEmpty() )
title += QString( " [name: %1]" ).arg( layer.layerName() );
title += tr( " [name: %1]" ).arg( layer.layerName() );
if ( !layer.filterExpression().isEmpty() )
title += QString( " [with filter]" );
title += tr( " [with filter]" );

return title;
}
@@ -267,15 +279,19 @@ void QgsProcessingVectorTileWriterLayersWidget::showDialog()
}
else
{
// TODO
#if 0
QgsProcessingMultipleInputDialog dlg( mParam, mValue, mModelSources, mModel, this, nullptr );
dlg.setProject( mProject );
QDialog dlg;
dlg.setWindowTitle( tr( "Input layers" ) );
QVBoxLayout *vLayout = new QVBoxLayout();
QgsProcessingVectorTileWriterLayersPanelWidget *widget = new QgsProcessingVectorTileWriterLayersPanelWidget( mValue, mProject );
vLayout->addWidget( widget );
widget->buttonBox()->addButton( QDialogButtonBox::Cancel );
connect( widget->buttonBox(), &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
connect( widget->buttonBox(), &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
dlg.setLayout( vLayout );
if ( dlg.exec() )
{
setValue( dlg.selectedOptions() );
setValue( widget->selectedOptions() );
}
#endif
}
}

@@ -306,7 +322,6 @@ QgsAbstractProcessingParameterWidgetWrapper *QgsProcessingVectorTileWriterLayers
QWidget *QgsProcessingVectorTileWriterLayersWidgetWrapper::createWidget()
{
mPanel = new QgsProcessingVectorTileWriterLayersWidget( nullptr );
//mPanel->setToolTip( parameterDefinition()->toolTip() );
mPanel->setProject( widgetContext().project() );
connect( mPanel, &QgsProcessingVectorTileWriterLayersWidget::changed, this, [ = ]
{
@@ -326,6 +341,7 @@ void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetContext( const Q

void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetValue( const QVariant &value, QgsProcessingContext &context )
{
Q_UNUSED( context )
if ( mPanel )
{
mPanel->setValue( value );
@@ -335,22 +351,14 @@ void QgsProcessingVectorTileWriterLayersWidgetWrapper::setWidgetValue( const QVa
QVariant QgsProcessingVectorTileWriterLayersWidgetWrapper::widgetValue() const
{
return mPanel ? mPanel->value() : QVariant();
// if ( mPanel )
// return !mPanel->value().toList().isEmpty() ? mPanel->value() : QVariant();
// else
// return QVariant();
}

QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleParameterTypes() const
{
return QStringList();
// << QgsProcessingParameterBand::typeName()
// << QgsProcessingParameterNumber::typeName()
// << QgsProcessingOutputFolder::typeName();
}

QStringList QgsProcessingVectorTileWriterLayersWidgetWrapper::compatibleOutputTypes() const
{
return QStringList();
// << QgsProcessingOutputNumber::typeName();
}
@@ -16,6 +16,8 @@
#ifndef QGSPROCESSINGVECTORTILEWRITERLAYERSWIDGETWRAPPER_H
#define QGSPROCESSINGVECTORTILEWRITERLAYERSWIDGETWRAPPER_H

#define SIP_NO_FILE

#include "qgsprocessingwidgetwrapper.h"
#include "qgsprocessingmultipleselectiondialog.h"
#include "qgsvectortilewriter.h"
@@ -35,6 +37,8 @@ class QgsProcessingVectorTileWriteLayerDetailsWidget : public QgsPanelWidget, pr

QVariant value() const;

QDialogButtonBox *buttonBox() { return mButtonBox; }

private:
QgsVectorLayer *mLayer = nullptr;
};
@@ -11,15 +11,8 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Min. zoom level</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="mSpinMinZoom">
<widget class="QgsSpinBox" name="mSpinMinZoom">
<property name="minimum">
<number>-1</number>
</property>
@@ -31,6 +24,13 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Min. zoom level</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
@@ -39,7 +39,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="mSpinMaxZoom">
<widget class="QgsSpinBox" name="mSpinMaxZoom">
<property name="minimum">
<number>-1</number>
</property>
@@ -69,10 +69,30 @@
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QPlainTextEdit" name="mEditFilterExpression"/>
<widget class="QgsExpressionLineEdit" name="mEditFilterExpression" native="true"/>
</item>
<item row="5" column="0" colspan="2">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsSpinBox</class>
<extends>QSpinBox</extends>
<header>qgsspinbox.h</header>
</customwidget>
<customwidget>
<class>QgsExpressionLineEdit</class>
<extends>QWidget</extends>
<header>qgsexpressionlineedit.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit a970107

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