Skip to content
Permalink
Browse files

[needs-doc] New option to update joined fields in form

  • Loading branch information
pblottiere committed Jun 30, 2017
1 parent c38e6e2 commit 73bb463c057767fc340eda678f9fc428685d47f0
@@ -84,6 +84,21 @@ Returns whether values from the joined layer should be cached in memory to speed
:rtype: bool
%End

bool isDynamicFormEnabled() const;
%Docstring
Returns whether the form has to be dynamically updated with joined fields
when a feature is being created in the target layer.
.. versionadded:: 3.0
:rtype: bool
%End

void setDynamicFormEnabled( bool enabled );
%Docstring
Sets whether the form has to be dynamically updated with joined fields
when a feature is being created in the target layer.
.. versionadded:: 3.0
%End

bool operator==( const QgsVectorLayerJoinInfo &other ) const;

void setJoinFieldNamesSubset( QStringList *fieldNamesSubset /Transfer/ );
@@ -108,6 +123,7 @@ Returns whether values from the joined layer should be cached in memory to speed




};


@@ -42,6 +42,8 @@ QgsJoinDialog::QgsJoinDialog( QgsVectorLayer *layer, QList<QgsMapLayer *> alread

mTargetFieldComboBox->setLayer( mLayer );

mDynamicFormCheckBox->setToolTip( tr( "This option allows values of the joined fields to be automatically updated when the \"Target Field\" is updated" ) );

mJoinLayerComboBox->setFilters( QgsMapLayerProxyModel::VectorLayer );
mJoinLayerComboBox->setExceptedLayerList( alreadyJoinedLayers );
connect( mJoinLayerComboBox, &QgsMapLayerComboBox::layerChanged, mJoinFieldComboBox, &QgsFieldComboBox::setLayer );
@@ -73,6 +75,7 @@ void QgsJoinDialog::setJoinInfo( const QgsVectorLayerJoinInfo &joinInfo )
mJoinFieldComboBox->setField( joinInfo.joinFieldName() );
mTargetFieldComboBox->setField( joinInfo.targetFieldName() );
mCacheInMemoryCheckBox->setChecked( joinInfo.isUsingMemoryCache() );
mDynamicFormCheckBox->setChecked( joinInfo.isDynamicFormEnabled() );
if ( joinInfo.prefix().isNull() )
{
mUseCustomPrefix->setChecked( false );
@@ -110,6 +113,7 @@ QgsVectorLayerJoinInfo QgsJoinDialog::joinInfo() const
info.setJoinFieldName( mJoinFieldComboBox->currentField() );
info.setTargetFieldName( mTargetFieldComboBox->currentField() );
info.setUsingMemoryCache( mCacheInMemoryCheckBox->isChecked() );
info.setDynamicFormEnabled( mDynamicFormCheckBox->isChecked() );

if ( mUseCustomPrefix->isChecked() )
info.setPrefix( mCustomPrefix->text() );
@@ -1235,16 +1235,21 @@ void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorLayerJoinInfo
joinItem->setText( 3, QChar( 0x2714 ) );
}

joinItem->setText( 4, join.prefix() );
if ( join.isDynamicFormEnabled() )
{
joinItem->setText( 4, QChar( 0x2714 ) );
}

joinItem->setText( 5, join.prefix() );

const QStringList *list = join.joinFieldNamesSubset();
if ( list )
{
joinItem->setText( 5, QStringLiteral( "%1" ).arg( list->count() ) );
joinItem->setText( 6, QStringLiteral( "%1" ).arg( list->count() ) );
}
else
{
joinItem->setText( 5, tr( "all" ) );
joinItem->setText( 6, tr( "all" ) );
}

if ( insertIndex >= 0 )
@@ -1255,7 +1260,7 @@ void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorLayerJoinInfo
{
mJoinTreeWidget->addTopLevelItem( joinItem );
}
for ( int c = 0; c < 5; c++ )
for ( int c = 0; c < 6; c++ )
{
mJoinTreeWidget->resizeColumnToContents( c );
}
@@ -275,6 +275,7 @@ void QgsVectorLayerJoinBuffer::writeXml( QDomNode &layer_node, QDomDocument &doc
joinElem.setAttribute( QStringLiteral( "joinFieldName" ), joinIt->joinFieldName() );

joinElem.setAttribute( QStringLiteral( "memoryCache" ), joinIt->isUsingMemoryCache() );
joinElem.setAttribute( QStringLiteral( "dynamicForm" ), joinIt->isDynamicFormEnabled() );

if ( joinIt->joinFieldNamesSubset() )
{
@@ -315,6 +316,7 @@ void QgsVectorLayerJoinBuffer::readXml( const QDomNode &layer_node )
info.setJoinLayerId( infoElem.attribute( QStringLiteral( "joinLayerId" ) ) );
info.setTargetFieldName( infoElem.attribute( QStringLiteral( "targetFieldName" ) ) );
info.setUsingMemoryCache( infoElem.attribute( QStringLiteral( "memoryCache" ) ).toInt() );
info.setDynamicFormEnabled( infoElem.attribute( QStringLiteral( "dynamicForm" ) ).toInt() );

QDomElement subsetElem = infoElem.firstChildElement( QStringLiteral( "joinFieldsSubset" ) );
if ( !subsetElem.isNull() )
@@ -0,0 +1,35 @@
/***************************************************************************
qgsvectorlayerjoininfo.cpp
--------------------------
begin : Jun 29, 2017
copyright : (C) 2017 by Paul Blottiere
email : paul.blottiere@oslandia.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 "qgsvectorlayerjoininfo.h"

QString QgsVectorLayerJoinInfo::prefixedFieldName( const QgsField &f ) const
{
QString name;

if ( joinLayer() )
{
if ( prefix().isNull() )
name = joinLayer()->name() + '_';
else
name = prefix();

name += f.name();
}

return name;
}
@@ -54,6 +54,18 @@ class CORE_EXPORT QgsVectorLayerJoinInfo
//! Returns whether values from the joined layer should be cached in memory to speed up lookups
bool isUsingMemoryCache() const { return mMemoryCache; }

/** Returns whether the form has to be dynamically updated with joined fields
* when a feature is being created in the target layer.
* \since QGIS 3.0
*/
bool isDynamicFormEnabled() const { return mDynamicForm; }

/** Sets whether the form has to be dynamically updated with joined fields
* when a feature is being created in the target layer.
* \since QGIS 3.0
*/
void setDynamicFormEnabled( bool enabled ) { mDynamicForm = enabled; }

bool operator==( const QgsVectorLayerJoinInfo &other ) const
{
return mTargetFieldName == other.mTargetFieldName &&
@@ -99,6 +111,8 @@ class CORE_EXPORT QgsVectorLayerJoinInfo
//! True if the cached join attributes need to be updated
bool cacheDirty;

bool mDynamicForm;

//! Cache for joined attributes to provide fast lookup (size is 0 if no memory caching)
QHash< QString, QgsAttributes> cachedAttributes;

@@ -44,10 +44,10 @@
<item row="2" column="1">
<widget class="QgsFieldComboBox" name="mTargetFieldComboBox"/>
</item>
<item row="5" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mUseJoinFieldsSubset">
<property name="title">
<string>Choose which fields are joined</string>
<string>Choose which fields are &amp;joined</string>
</property>
<property name="checkable">
<bool>true</bool>
@@ -65,10 +65,10 @@
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mUseCustomPrefix">
<property name="title">
<string>Custom field name prefix</string>
<string>Custom field &amp;name prefix</string>
</property>
<property name="checkable">
<bool>true</bool>
@@ -86,7 +86,7 @@
</layout>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -116,7 +116,7 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -126,6 +126,13 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="mDynamicFormCheckBox">
<property name="text">
<string>Dynamic form</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@@ -303,7 +303,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>9</number>
</property>
<widget class="QWidget" name="mOptsPage_Information">
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -379,8 +379,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>639</width>
<height>592</height>
<width>653</width>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
@@ -831,7 +831,7 @@ border-radius: 2px;</string>
<x>0</x>
<y>0</y>
<width>653</width>
<height>536</height>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
@@ -1069,7 +1069,7 @@ border-radius: 2px;</string>
<x>0</x>
<y>0</y>
<width>653</width>
<height>536</height>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
@@ -1170,7 +1170,7 @@ border-radius: 2px;</string>
<x>0</x>
<y>0</y>
<width>653</width>
<height>536</height>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
@@ -1229,8 +1229,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>671</width>
<height>522</height>
<width>653</width>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_32">
@@ -1249,7 +1249,7 @@ border-radius: 2px;</string>
<item>
<widget class="QgsCollapsibleGroupBox" name="mScaleVisibilityGroupBox">
<property name="title">
<string>Scale dependent visibility</string>
<string>Scale dependen&amp;t visibility</string>
</property>
<property name="checkable">
<bool>true</bool>
@@ -1268,7 +1268,7 @@ border-radius: 2px;</string>
<item>
<widget class="QGroupBox" name="mSimplifyDrawingGroupBox">
<property name="title">
<string>Simplify geometry</string>
<string>Simplify &amp;geometry</string>
</property>
<property name="checkable">
<bool>true</bool>
@@ -1590,7 +1590,7 @@ border-radius: 2px;</string>
<x>0</x>
<y>0</y>
<width>653</width>
<height>536</height>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
@@ -1656,7 +1656,7 @@ border-radius: 2px;</string>
<x>0</x>
<y>0</y>
<width>653</width>
<height>536</height>
<height>542</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_23">
@@ -1675,7 +1675,7 @@ border-radius: 2px;</string>
<item>
<widget class="QTreeWidget" name="mJoinTreeWidget">
<property name="columnCount">
<number>6</number>
<number>7</number>
</property>
<column>
<property name="text">
@@ -1697,6 +1697,11 @@ border-radius: 2px;</string>
<string>Memory cache</string>
</property>
</column>
<column>
<property name="text">
<string>Dynamic form</string>
</property>
</column>
<column>
<property name="text">
<string>Prefix</string>

0 comments on commit 73bb463

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