Skip to content

Commit

Permalink
[needs-doc] Add editable/upsert on edit/delete cascade options
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Aug 28, 2017
1 parent 55a01dc commit 1897bec
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 23 deletions.
11 changes: 11 additions & 0 deletions src/app/qgsjoindialog.cpp
Expand Up @@ -76,6 +76,10 @@ void QgsJoinDialog::setJoinInfo( const QgsVectorLayerJoinInfo &joinInfo )
mTargetFieldComboBox->setField( joinInfo.targetFieldName() );
mCacheInMemoryCheckBox->setChecked( joinInfo.isUsingMemoryCache() );
mDynamicFormCheckBox->setChecked( joinInfo.isDynamicFormEnabled() );
mEditableJoinLayer->setChecked( joinInfo.isEditable() );
mUpsertOnEditCheckBox->setChecked( joinInfo.isUpsertOnEdit() );
mDeleteCascadeCheckBox->setChecked( joinInfo.isDeleteCascade() );

if ( joinInfo.prefix().isNull() )
{
mUseCustomPrefix->setChecked( false );
Expand Down Expand Up @@ -115,6 +119,13 @@ QgsVectorLayerJoinInfo QgsJoinDialog::joinInfo() const
info.setUsingMemoryCache( mCacheInMemoryCheckBox->isChecked() );
info.setDynamicFormEnabled( mDynamicFormCheckBox->isChecked() );

info.setEditable( mEditableJoinLayer->isChecked() );
if ( info.isEditable() )
{
info.setUpsertOnEdit( mUpsertOnEditCheckBox->isChecked() );
info.setDeleteCascade( mDeleteCascadeCheckBox->isChecked() );
}

if ( mUseCustomPrefix->isChecked() )
info.setPrefix( mCustomPrefix->text() );
else
Expand Down
23 changes: 19 additions & 4 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -1241,16 +1241,31 @@ void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorLayerJoinInfo
joinItem->setText( 4, QChar( 0x2714 ) );
}

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

if ( join.isUpsertOnEdit() )
{
joinItem->setText( 6, QChar( 0x2714 ) );
}

if ( join.isDeleteCascade() )
{
joinItem->setText( 7, QChar( 0x2714 ) );
}

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

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

if ( insertIndex >= 0 )
Expand All @@ -1261,7 +1276,7 @@ void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorLayerJoinInfo
{
mJoinTreeWidget->addTopLevelItem( joinItem );
}
for ( int c = 0; c < 6; c++ )
for ( int c = 0; c < 9; c++ )
{
mJoinTreeWidget->resizeColumnToContents( c );
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayerjoinbuffer.cpp
Expand Up @@ -276,6 +276,9 @@ void QgsVectorLayerJoinBuffer::writeXml( QDomNode &layer_node, QDomDocument &doc

joinElem.setAttribute( QStringLiteral( "memoryCache" ), joinIt->isUsingMemoryCache() );
joinElem.setAttribute( QStringLiteral( "dynamicForm" ), joinIt->isDynamicFormEnabled() );
joinElem.setAttribute( QStringLiteral( "editable" ), joinIt->isEditable() );
joinElem.setAttribute( QStringLiteral( "upsertOnEdit" ), joinIt->isUpsertOnEdit() );
joinElem.setAttribute( QStringLiteral( "deleteCascade" ), joinIt->isDeleteCascade() );

if ( joinIt->joinFieldNamesSubset() )
{
Expand Down Expand Up @@ -317,6 +320,9 @@ void QgsVectorLayerJoinBuffer::readXml( const QDomNode &layer_node )
info.setTargetFieldName( infoElem.attribute( QStringLiteral( "targetFieldName" ) ) );
info.setUsingMemoryCache( infoElem.attribute( QStringLiteral( "memoryCache" ) ).toInt() );
info.setDynamicFormEnabled( infoElem.attribute( QStringLiteral( "dynamicForm" ) ).toInt() );
info.setEditable( infoElem.attribute( QStringLiteral( "editable" ) ).toInt() );
info.setUpsertOnEdit( infoElem.attribute( QStringLiteral( "upsertOnEdit" ) ).toInt() );
info.setDeleteCascade( infoElem.attribute( QStringLiteral( "deleteCascade" ) ).toInt() );

QDomElement subsetElem = infoElem.firstChildElement( QStringLiteral( "joinFieldsSubset" ) );
if ( !subsetElem.isNull() )
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgsvectorlayerjoininfo.cpp
Expand Up @@ -33,3 +33,14 @@ QString QgsVectorLayerJoinInfo::prefixedFieldName( const QgsField &f ) const

return name;
}

void QgsVectorLayerJoinInfo::setEditable( bool enabled )
{
mEditable = enabled;

if ( ! mEditable )
{
setDeleteCascade( false );
setUpsertOnEdit( false );
}
}
41 changes: 41 additions & 0 deletions src/core/qgsvectorlayerjoininfo.h
Expand Up @@ -81,6 +81,41 @@ class CORE_EXPORT QgsVectorLayerJoinInfo
*/
void setDynamicFormEnabled( bool enabled ) { mDynamicForm = enabled; }

/** Returns whether joined fields may be edited through the form of
* the target layer.
* \since QGIS 3.0
*/
bool isEditable() const { return mEditable; }

/** Sets whether the form of the target layer allows to edit joined fields.
* \since QGIS 3.0
*/
void setEditable( bool enabled );

/** Returns whether a feature created on the target layer has to impact
* the joined layer by creating a new feature if necessary.
* \since QGIS 3.0
*/
bool isUpsertOnEdit() const { return mUpsertOnEdit; }

/** Sets whether a feature created on the target layer has to impact
* the joined layer by creating a new feature if necessary.
* \since QGIS 3.0
*/
void setUpsertOnEdit( bool enabled ) { mUpsertOnEdit = enabled; }

/** Returns whether a feature deleted on the target layer has to impact the
* joined layer by deleting the corresponding joined feature.
* \since QGIS 3.0
*/
bool isDeleteCascade() const { return mDeleteCascade; }

/** Sets whether a feature deleted on the target layer has to impact the
* joined layer by deleting the corresponding joined feature.
* \since QGIS 3.0
*/
void setDeleteCascade( bool enabled ) { mDeleteCascade = enabled; }

/** Returns the prefixed name of the field.
* \param field the field
* \returns the prefixed name of the field
Expand Down Expand Up @@ -135,6 +170,12 @@ class CORE_EXPORT QgsVectorLayerJoinInfo

bool mDynamicForm = false;

bool mEditable;

bool mUpsertOnEdit;

bool mDeleteCascade;

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

Expand Down
44 changes: 38 additions & 6 deletions src/ui/qgsjoindialogbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>505</width>
<height>395</height>
<height>487</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -44,7 +44,7 @@
<item row="2" column="1">
<widget class="QgsFieldComboBox" name="mTargetFieldComboBox"/>
</item>
<item row="6" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mUseJoinFieldsSubset">
<property name="title">
<string>Choose which fields are &amp;joined</string>
Expand All @@ -65,7 +65,7 @@
</layout>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<widget class="QgsCollapsibleGroupBox" name="mUseCustomPrefix">
<property name="title">
<string>Custom field &amp;name prefix</string>
Expand All @@ -86,7 +86,7 @@
</layout>
</widget>
</item>
<item row="8" column="0">
<item row="10" 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="9" column="0" colspan="2">
<item row="11" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -126,13 +126,45 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QCheckBox" name="mDynamicFormCheckBox">
<property name="text">
<string>Dynamic form</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QgsCollapsibleGroupBox" name="mEditableJoinLayer">
<property name="title">
<string>Edi&amp;table join layer</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="collapsed" stdset="0">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="mUpsertOnEditCheckBox">
<property name="text">
<string>Upsert on edit</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="mDeleteCascadeCheckBox">
<property name="text">
<string>Delete cascade</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
41 changes: 28 additions & 13 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -379,8 +379,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>542</height>
<width>306</width>
<height>508</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -830,8 +830,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>542</height>
<width>268</width>
<height>321</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
Expand Down Expand Up @@ -1068,8 +1068,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>542</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_18">
Expand Down Expand Up @@ -1169,8 +1169,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>542</height>
<width>100</width>
<height>30</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>653</width>
<height>542</height>
<width>632</width>
<height>276</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_32">
Expand Down Expand Up @@ -1589,8 +1589,8 @@ border-radius: 2px;</string>
<rect>
<x>0</x>
<y>0</y>
<width>653</width>
<height>542</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
Expand Down Expand Up @@ -1675,7 +1675,7 @@ border-radius: 2px;</string>
<item>
<widget class="QTreeWidget" name="mJoinTreeWidget">
<property name="columnCount">
<number>7</number>
<number>10</number>
</property>
<column>
<property name="text">
Expand All @@ -1702,6 +1702,21 @@ border-radius: 2px;</string>
<string>Dynamic form</string>
</property>
</column>
<column>
<property name="text">
<string>Editable</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>Delete cascade</string>
</property>
</column>
<column>
<property name="text">
<string>Prefix</string>
Expand Down

0 comments on commit 1897bec

Please sign in to comment.