Skip to content
Permalink
Browse files

[processing] Use an editable combobox with current project layout names

when editing a model which uses the print layout parameter type

Instead of a plain text edit with no hints as to the current project's layouts
  • Loading branch information
nyalldawson committed Jun 29, 2020
1 parent d8337ea commit c92354640c3e7f369c7d10cf9468a18d9037d7e0
@@ -2510,13 +2510,21 @@ QWidget *QgsProcessingLayoutWidgetWrapper::createWidget()

case QgsProcessingGui::Modeler:
{
mLineEdit = new QLineEdit();
mLineEdit->setToolTip( tr( "Name of an existing print layout" ) );
connect( mLineEdit, &QLineEdit::textChanged, this, [ = ]( const QString & )
mPlainComboBox = new QComboBox();
mPlainComboBox->setEditable( true );
mPlainComboBox->setToolTip( tr( "Name of an existing print layout" ) );
if ( widgetContext().project() )
{
const QList< QgsPrintLayout * > layouts = widgetContext().project()->layoutManager()->printLayouts();
for ( const QgsPrintLayout *layout : layouts )
mPlainComboBox->addItem( layout->name() );
}

connect( mPlainComboBox, &QComboBox::currentTextChanged, this, [ = ]( const QString & )
{
emit widgetValueHasChanged( this );
} );
return mLineEdit;
return mPlainComboBox;
}
}
return nullptr;
@@ -2536,10 +2544,10 @@ void QgsProcessingLayoutWidgetWrapper::setWidgetValue( const QVariant &value, Qg
mComboBox->setCurrentLayout( nullptr );
}
}
else if ( mLineEdit )
else if ( mPlainComboBox )
{
const QString v = QgsProcessingParameters::parameterAsString( parameterDefinition(), value, context );
mLineEdit->setText( v );
mPlainComboBox->setCurrentText( v );
}
}

@@ -2550,12 +2558,23 @@ QVariant QgsProcessingLayoutWidgetWrapper::widgetValue() const
const QgsMasterLayoutInterface *l = mComboBox->currentLayout();
return l ? l->name() : QVariant();
}
else if ( mLineEdit )
return mLineEdit->text().isEmpty() ? QVariant() : mLineEdit->text();
else if ( mPlainComboBox )
return mPlainComboBox->currentText().isEmpty() ? QVariant() : mPlainComboBox->currentText();
else
return QVariant();
}

void QgsProcessingLayoutWidgetWrapper::setWidgetContext( const QgsProcessingParameterWidgetContext &context )
{
QgsAbstractProcessingParameterWidgetWrapper::setWidgetContext( context );
if ( mPlainComboBox && context.project() )
{
const QList< QgsPrintLayout * > layouts = widgetContext().project()->layoutManager()->printLayouts();
for ( const QgsPrintLayout *layout : layouts )
mPlainComboBox->addItem( layout->name() );
}
}

QStringList QgsProcessingLayoutWidgetWrapper::compatibleParameterTypes() const
{
return QStringList()
@@ -825,6 +825,7 @@ class GUI_EXPORT QgsProcessingLayoutWidgetWrapper : public QgsAbstractProcessing

void setWidgetValue( const QVariant &value, QgsProcessingContext &context ) override;
QVariant widgetValue() const override;
void setWidgetContext( const QgsProcessingParameterWidgetContext &context ) override;

QStringList compatibleParameterTypes() const override;

@@ -834,7 +835,7 @@ class GUI_EXPORT QgsProcessingLayoutWidgetWrapper : public QgsAbstractProcessing
private:

QgsLayoutComboBox *mComboBox = nullptr;
QLineEdit *mLineEdit = nullptr;
QComboBox *mPlainComboBox = nullptr;

friend class TestProcessingGui;
};
@@ -4139,7 +4139,7 @@ void TestProcessingGui::testLayoutWrapper()
}
else
{
QCOMPARE( static_cast< QLineEdit * >( wrapper.wrappedWidget() )->text(), QStringLiteral( "l2" ) );
QCOMPARE( static_cast< QComboBox * >( wrapper.wrappedWidget() )->currentText(), QStringLiteral( "l2" ) );
}
wrapper.setWidgetValue( "l1", context );
QCOMPARE( spy.count(), 2 );
@@ -4151,7 +4151,7 @@ void TestProcessingGui::testLayoutWrapper()
}
else
{
QCOMPARE( static_cast< QLineEdit * >( wrapper.wrappedWidget() )->text(), QStringLiteral( "l1" ) );
QCOMPARE( static_cast< QComboBox * >( wrapper.wrappedWidget() )->currentText(), QStringLiteral( "l1" ) );
}

QLabel *l = wrapper.createWrappedLabel();
@@ -4174,7 +4174,7 @@ void TestProcessingGui::testLayoutWrapper()
}
else
{
static_cast< QLineEdit * >( wrapper.wrappedWidget() )->setText( QStringLiteral( "aaaa" ) );
static_cast< QComboBox * >( wrapper.wrappedWidget() )->setCurrentText( QStringLiteral( "aaaa" ) );
}
QCOMPARE( spy.count(), 3 );

@@ -4199,7 +4199,7 @@ void TestProcessingGui::testLayoutWrapper()
}
else
{
QCOMPARE( static_cast< QLineEdit * >( wrapper2.wrappedWidget() )->text(), QStringLiteral( "l2" ) );
QCOMPARE( static_cast< QComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "l2" ) );
}
wrapper2.setWidgetValue( "l1", context );
QCOMPARE( spy2.count(), 2 );
@@ -4211,7 +4211,7 @@ void TestProcessingGui::testLayoutWrapper()
}
else
{
QCOMPARE( static_cast< QLineEdit * >( wrapper2.wrappedWidget() )->text(), QStringLiteral( "l1" ) );
QCOMPARE( static_cast< QComboBox * >( wrapper2.wrappedWidget() )->currentText(), QStringLiteral( "l1" ) );
}
wrapper2.setWidgetValue( QVariant(), context );
QCOMPARE( spy2.count(), 3 );
@@ -4223,14 +4223,14 @@ void TestProcessingGui::testLayoutWrapper()
}
else
{
QVERIFY( static_cast< QLineEdit * >( wrapper2.wrappedWidget() )->text().isEmpty() );
QVERIFY( static_cast< QComboBox * >( wrapper2.wrappedWidget() )->currentText().isEmpty() );
}

// check signal
if ( type != QgsProcessingGui::Modeler )
static_cast< QComboBox * >( wrapper2.wrappedWidget() )->setCurrentIndex( 2 );
else
static_cast< QLineEdit * >( wrapper2.wrappedWidget() )->setText( QStringLiteral( "aaa" ) );
static_cast< QComboBox * >( wrapper2.wrappedWidget() )->setCurrentText( QStringLiteral( "aaa" ) );
QCOMPARE( spy2.count(), 4 );

delete w;

0 comments on commit c923546

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