Skip to content

Commit

Permalink
[needs-docs] Relation Reference Widget: Add option to show/hide the O…
Browse files Browse the repository at this point in the history
…pen Form Button

The option was already available in the API (QgsRelationReferenceWidget->setOpenFormButtonVisible), but couldn't be used from QgsEditorWidgetSetup nor from the config dialog. For the former, a 'ShowOpenFormButton' key is added, whereas for the latter, a new checkbox is available.

Being able to hide the Open Form Button is helpful when configuring lookup tables, where a single combo box should be shown in the edit form with no additional buttons.
  • Loading branch information
gacarrillor committed Jul 30, 2017
1 parent 45fc00a commit 91e39a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferenceconfigdlg.cpp
Expand Up @@ -44,6 +44,7 @@ QgsRelationReferenceConfigDlg::QgsRelationReferenceConfigDlg( QgsVectorLayer *vl
connect( mCbxAllowNull, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxOrderByValue, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxShowForm, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxShowOpenFormButton, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxMapIdentification, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mCbxReadOnly, &QAbstractButton::toggled, this, &QgsEditorConfigWidget::changed );
connect( mComboRelation, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsEditorConfigWidget::changed );
Expand All @@ -59,6 +60,7 @@ void QgsRelationReferenceConfigDlg::setConfig( const QVariantMap &config )
mCbxAllowNull->setChecked( config.value( QStringLiteral( "AllowNULL" ), false ).toBool() );
mCbxOrderByValue->setChecked( config.value( QStringLiteral( "OrderByValue" ), false ).toBool() );
mCbxShowForm->setChecked( config.value( QStringLiteral( "ShowForm" ), false ).toBool() );
mCbxShowOpenFormButton->setChecked( config.value( QStringLiteral( "ShowOpenFormButton" ), true ).toBool() );

if ( config.contains( QStringLiteral( "Relation" ) ) )
{
Expand Down Expand Up @@ -121,6 +123,7 @@ QVariantMap QgsRelationReferenceConfigDlg::config()
myConfig.insert( QStringLiteral( "AllowNULL" ), mCbxAllowNull->isChecked() );
myConfig.insert( QStringLiteral( "OrderByValue" ), mCbxOrderByValue->isChecked() );
myConfig.insert( QStringLiteral( "ShowForm" ), mCbxShowForm->isChecked() );
myConfig.insert( QStringLiteral( "ShowOpenFormButton" ), mCbxShowOpenFormButton->isChecked() );
myConfig.insert( QStringLiteral( "MapIdentification" ), mCbxMapIdentification->isEnabled() && mCbxMapIdentification->isChecked() );
myConfig.insert( QStringLiteral( "ReadOnly" ), mCbxReadOnly->isChecked() );
myConfig.insert( QStringLiteral( "Relation" ), mComboRelation->currentData() );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/editorwidgets/qgsrelationreferencewidgetwrapper.cpp
Expand Up @@ -50,11 +50,13 @@ void QgsRelationReferenceWidgetWrapper::initWidget( QWidget *editor )
bool mapIdent = config( QStringLiteral( "MapIdentification" ), false ).toBool();
bool readOnlyWidget = config( QStringLiteral( "ReadOnly" ), false ).toBool();
bool orderByValue = config( QStringLiteral( "OrderByValue" ), false ).toBool();
bool showOpenFormButton = config( QStringLiteral( "ShowOpenFormButton" ), true ).toBool();

mWidget->setEmbedForm( showForm );
mWidget->setReadOnlySelector( readOnlyWidget );
mWidget->setAllowMapIdentification( mapIdent );
mWidget->setOrderByValue( orderByValue );
mWidget->setOpenFormButtonVisible( showOpenFormButton );
if ( config( QStringLiteral( "FilterFields" ), QVariant() ).isValid() )
{
mWidget->setFilterFields( config( QStringLiteral( "FilterFields" ) ).toStringList() );
Expand Down
16 changes: 12 additions & 4 deletions src/ui/editorwidgets/qgsrelationreferenceconfigdlgbase.ui
Expand Up @@ -21,6 +21,13 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxShowOpenFormButton">
<property name="text">
<string>Show open form button</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mComboRelation"/>
</item>
Expand All @@ -31,7 +38,7 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxReadOnly">
<property name="text">
<string>Use a read-only line edit instead of a combobox</string>
Expand Down Expand Up @@ -59,7 +66,7 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxMapIdentification">
<property name="text">
<string>On map identification (for geometric layers only)</string>
Expand All @@ -73,7 +80,7 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mFilterGroupBox">
<property name="title">
<string>Filters</string>
Expand Down Expand Up @@ -152,7 +159,7 @@
</layout>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="mCbxAllowAddFeatures">
<property name="text">
<string>Allow adding new features</string>
Expand Down Expand Up @@ -181,6 +188,7 @@
<tabstop>mCbxAllowNull</tabstop>
<tabstop>mCbxOrderByValue</tabstop>
<tabstop>mCbxShowForm</tabstop>
<tabstop>mCbxShowOpenFormButton</tabstop>
<tabstop>mCbxMapIdentification</tabstop>
<tabstop>mCbxReadOnly</tabstop>
<tabstop>mCbxAllowAddFeatures</tabstop>
Expand Down

0 comments on commit 91e39a7

Please sign in to comment.