mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
Take changes of embedded forms into account
when clicking on ok of an attribute form, tell all embedded widgets (all widgets actually) that we are going to close the form and it's the last call to push changes to the edit buffer or they will be lost. Fix #19137
This commit is contained in:
parent
353eb65117
commit
0749835071
@ -153,6 +153,15 @@ Sets the editor widget's property collection, used for data defined overrides.
|
|||||||
.. seealso:: :py:func:`dataDefinedProperties`
|
.. seealso:: :py:func:`dataDefinedProperties`
|
||||||
|
|
||||||
.. versionadded:: 3.0
|
.. versionadded:: 3.0
|
||||||
|
%End
|
||||||
|
|
||||||
|
void notifyAboutToSave();
|
||||||
|
%Docstring
|
||||||
|
Notify this widget, that the containing form is about to save and
|
||||||
|
that any pending changes should be pushed to the edit buffer or they
|
||||||
|
might be lost.
|
||||||
|
|
||||||
|
.. versionadded:: 3.2
|
||||||
%End
|
%End
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -97,6 +97,11 @@ QgsWidgetWrapper *QgsWidgetWrapper::fromWidget( QWidget *widget )
|
|||||||
return widget->property( "EWV2Wrapper" ).value<QgsWidgetWrapper *>();
|
return widget->property( "EWV2Wrapper" ).value<QgsWidgetWrapper *>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsWidgetWrapper::notifyAboutToSave()
|
||||||
|
{
|
||||||
|
aboutToSave();
|
||||||
|
}
|
||||||
|
|
||||||
void QgsWidgetWrapper::initWidget( QWidget *editor )
|
void QgsWidgetWrapper::initWidget( QWidget *editor )
|
||||||
{
|
{
|
||||||
Q_UNUSED( editor )
|
Q_UNUSED( editor )
|
||||||
@ -106,3 +111,8 @@ void QgsWidgetWrapper::setEnabled( bool enabled )
|
|||||||
{
|
{
|
||||||
Q_UNUSED( enabled );
|
Q_UNUSED( enabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsWidgetWrapper::aboutToSave()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -190,6 +190,15 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
|
|||||||
*/
|
*/
|
||||||
void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mPropertyCollection = collection; }
|
void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mPropertyCollection = collection; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify this widget, that the containing form is about to save and
|
||||||
|
* that any pending changes should be pushed to the edit buffer or they
|
||||||
|
* might be lost.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.2
|
||||||
|
*/
|
||||||
|
void notifyAboutToSave();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -234,6 +243,15 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
|
|||||||
virtual void setEnabled( bool enabled );
|
virtual void setEnabled( bool enabled );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the containing attribute form is about to save.
|
||||||
|
* Use this to push any widget states to the edit buffer.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.2
|
||||||
|
*/
|
||||||
|
virtual void aboutToSave();
|
||||||
|
|
||||||
QgsAttributeEditorContext mContext;
|
QgsAttributeEditorContext mContext;
|
||||||
QVariantMap mConfig;
|
QVariantMap mConfig;
|
||||||
QWidget *mWidget = nullptr;
|
QWidget *mWidget = nullptr;
|
||||||
|
@ -46,6 +46,14 @@ void QgsRelationWidgetWrapper::setVisible( bool visible )
|
|||||||
mWidget->setVisible( visible );
|
mWidget->setVisible( visible );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsRelationWidgetWrapper::aboutToSave()
|
||||||
|
{
|
||||||
|
mRelation.referencingLayer()->isModified();
|
||||||
|
|
||||||
|
if ( mNmRelation.isValid() )
|
||||||
|
mNmRelation.referencedLayer()->isModified();
|
||||||
|
}
|
||||||
|
|
||||||
QgsRelation QgsRelationWidgetWrapper::relation() const
|
QgsRelation QgsRelationWidgetWrapper::relation() const
|
||||||
{
|
{
|
||||||
return mRelation;
|
return mRelation;
|
||||||
@ -96,14 +104,14 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor )
|
|||||||
|
|
||||||
w->setEditorContext( myContext );
|
w->setEditorContext( myContext );
|
||||||
|
|
||||||
QgsRelation nmrel = QgsProject::instance()->relationManager()->relation( config( QStringLiteral( "nm-rel" ) ).toString() );
|
mNmRelation = QgsProject::instance()->relationManager()->relation( config( QStringLiteral( "nm-rel" ) ).toString() );
|
||||||
|
|
||||||
// If this widget is already embedded by the same relation, reduce functionality
|
// If this widget is already embedded by the same relation, reduce functionality
|
||||||
const QgsAttributeEditorContext *ctx = &context();
|
const QgsAttributeEditorContext *ctx = &context();
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if ( ( ctx->relation().name() == mRelation.name() && ctx->formMode() == QgsAttributeEditorContext::Embed )
|
if ( ( ctx->relation().name() == mRelation.name() && ctx->formMode() == QgsAttributeEditorContext::Embed )
|
||||||
|| ( nmrel.isValid() && ctx->relation().name() == nmrel.name() ) )
|
|| ( mNmRelation.isValid() && ctx->relation().name() == mNmRelation.name() ) )
|
||||||
{
|
{
|
||||||
w->setVisible( false );
|
w->setVisible( false );
|
||||||
break;
|
break;
|
||||||
@ -113,7 +121,7 @@ void QgsRelationWidgetWrapper::initWidget( QWidget *editor )
|
|||||||
while ( ctx );
|
while ( ctx );
|
||||||
|
|
||||||
|
|
||||||
w->setRelations( mRelation, nmrel );
|
w->setRelations( mRelation, mNmRelation );
|
||||||
|
|
||||||
mWidget = w;
|
mWidget = w;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,9 @@ class GUI_EXPORT QgsRelationWidgetWrapper : public QgsWidgetWrapper
|
|||||||
void setVisible( bool visible );
|
void setVisible( bool visible );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void aboutToSave() override;
|
||||||
QgsRelation mRelation;
|
QgsRelation mRelation;
|
||||||
|
QgsRelation mNmRelation;
|
||||||
QgsRelationEditorWidget *mWidget = nullptr;
|
QgsRelationEditorWidget *mWidget = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ bool QgsAttributeForm::saveEdits()
|
|||||||
QgsAttributes src = mFeature.attributes();
|
QgsAttributes src = mFeature.attributes();
|
||||||
QgsAttributes dst = mFeature.attributes();
|
QgsAttributes dst = mFeature.attributes();
|
||||||
|
|
||||||
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
|
for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) )
|
||||||
{
|
{
|
||||||
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
|
QgsEditorWidgetWrapper *eww = qobject_cast<QgsEditorWidgetWrapper *>( ww );
|
||||||
if ( eww )
|
if ( eww )
|
||||||
@ -588,6 +588,11 @@ bool QgsAttributeForm::save()
|
|||||||
if ( mIsSaving )
|
if ( mIsSaving )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
for ( QgsWidgetWrapper *wrapper : qgis::as_const( mWidgets ) )
|
||||||
|
{
|
||||||
|
wrapper->notifyAboutToSave();
|
||||||
|
}
|
||||||
|
|
||||||
// only do the dirty checks when editing an existing feature - for new
|
// only do the dirty checks when editing an existing feature - for new
|
||||||
// features we need to add them even if the attributes are unchanged from the initial
|
// features we need to add them even if the attributes are unchanged from the initial
|
||||||
// default values
|
// default values
|
||||||
|
Loading…
x
Reference in New Issue
Block a user