Skip to content

Commit

Permalink
[needs-doc] New option to update joined fields in form
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Jun 30, 2017
1 parent c38e6e2 commit 73bb463
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 23 deletions.
16 changes: 16 additions & 0 deletions python/core/qgsvectorlayerjoininfo.sip
Expand Up @@ -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/ );
Expand All @@ -108,6 +123,7 @@ Returns whether values from the joined layer should be cached in memory to speed




};


Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsjoindialog.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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() );
Expand Down
13 changes: 9 additions & 4 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -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 )
Expand All @@ -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 );
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayerjoinbuffer.cpp
Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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() )
Expand Down
35 changes: 35 additions & 0 deletions src/core/qgsvectorlayerjoininfo.cpp
@@ -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;
}
14 changes: 14 additions & 0 deletions src/core/qgsvectorlayerjoininfo.h
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;

Expand Down
19 changes: 13 additions & 6 deletions src/ui/qgsjoindialogbase.ui
Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down
31 changes: 18 additions & 13 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand All @@ -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">
Expand All @@ -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>
Expand Down

0 comments on commit 73bb463

Please sign in to comment.