mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
Merge pull request #38318 from signedav/attachement-expression
Update documuent viewer in the attachment widget on attribute change
This commit is contained in:
commit
d998bb3d17
@ -44,6 +44,14 @@ class QgsAttributeForm : QWidget
|
|||||||
|
|
||||||
const QgsFeature &feature();
|
const QgsFeature &feature();
|
||||||
|
|
||||||
|
QgsFeature currentFormFeature() const;
|
||||||
|
%Docstring
|
||||||
|
Returns the feature that is currently displayed in the form with all
|
||||||
|
the changes received on editing the values in the widgets.
|
||||||
|
|
||||||
|
.. versionadded:: 3.16
|
||||||
|
%End
|
||||||
|
|
||||||
void displayWarning( const QString &message );
|
void displayWarning( const QString &message );
|
||||||
%Docstring
|
%Docstring
|
||||||
Displays a warning message in the form message bar
|
Displays a warning message in the form message bar
|
||||||
|
@ -77,7 +77,7 @@ bool QgsExternalResourceWidgetWrapper::valid() const
|
|||||||
return mLineEdit || mLabel || mQgsWidget;
|
return mLineEdit || mLabel || mQgsWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsExternalResourceWidgetWrapper::setFeature( const QgsFeature &feature )
|
void QgsExternalResourceWidgetWrapper::updateProperties( const QgsFeature &feature )
|
||||||
{
|
{
|
||||||
if ( mQgsWidget && mPropertyCollection.hasActiveProperties() )
|
if ( mQgsWidget && mPropertyCollection.hasActiveProperties() )
|
||||||
{
|
{
|
||||||
@ -115,12 +115,21 @@ void QgsExternalResourceWidgetWrapper::setFeature( const QgsFeature &feature )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsExternalResourceWidgetWrapper::setFeature( const QgsFeature &feature )
|
||||||
|
{
|
||||||
|
updateProperties( feature );
|
||||||
QgsEditorWidgetWrapper::setFeature( feature );
|
QgsEditorWidgetWrapper::setFeature( feature );
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *QgsExternalResourceWidgetWrapper::createWidget( QWidget *parent )
|
QWidget *QgsExternalResourceWidgetWrapper::createWidget( QWidget *parent )
|
||||||
{
|
{
|
||||||
|
mForm = qobject_cast<QgsAttributeForm *>( parent );
|
||||||
|
|
||||||
|
if ( mForm )
|
||||||
|
connect( mForm, &QgsAttributeForm::widgetValueChanged, this, &QgsExternalResourceWidgetWrapper::widgetValueChanged );
|
||||||
|
|
||||||
return new QgsExternalResourceWidget( parent );
|
return new QgsExternalResourceWidget( parent );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +261,23 @@ void QgsExternalResourceWidgetWrapper::setEnabled( bool enabled )
|
|||||||
mQgsWidget->setReadOnly( !enabled );
|
mQgsWidget->setReadOnly( !enabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsExternalResourceWidgetWrapper::widgetValueChanged( const QString &attribute, const QVariant &newValue, bool attributeChanged )
|
||||||
|
{
|
||||||
|
Q_UNUSED( newValue );
|
||||||
|
if ( attributeChanged )
|
||||||
|
{
|
||||||
|
QgsExpression documentViewerContentExp = QgsExpression( mPropertyCollection.property( QgsEditorWidgetWrapper::DocumentViewerContent ).expressionString() );
|
||||||
|
QgsExpression rootPathExp = QgsExpression( mPropertyCollection.property( QgsEditorWidgetWrapper::RootPath ).expressionString() );
|
||||||
|
|
||||||
|
if ( documentViewerContentExp.referencedColumns().contains( attribute ) ||
|
||||||
|
rootPathExp.referencedColumns().contains( attribute ) )
|
||||||
|
{
|
||||||
|
QgsFeature feature = mForm->currentFormFeature();
|
||||||
|
updateProperties( feature );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QgsExternalResourceWidgetWrapper::updateConstraintWidgetStatus()
|
void QgsExternalResourceWidgetWrapper::updateConstraintWidgetStatus()
|
||||||
{
|
{
|
||||||
if ( mLineEdit )
|
if ( mLineEdit )
|
||||||
|
@ -23,6 +23,7 @@ class QLineEdit;
|
|||||||
|
|
||||||
#include "qgseditorwidgetwrapper.h"
|
#include "qgseditorwidgetwrapper.h"
|
||||||
#include "qgis_gui.h"
|
#include "qgis_gui.h"
|
||||||
|
#include "qgsattributeform.h"
|
||||||
|
|
||||||
SIP_NO_FILE
|
SIP_NO_FILE
|
||||||
|
|
||||||
@ -68,12 +69,26 @@ class GUI_EXPORT QgsExternalResourceWidgetWrapper : public QgsEditorWidgetWrappe
|
|||||||
void setFeature( const QgsFeature &feature ) override;
|
void setFeature( const QgsFeature &feature ) override;
|
||||||
void setEnabled( bool enabled ) override;
|
void setEnabled( bool enabled ) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will be called when a value in the current edited form or table row
|
||||||
|
* changes
|
||||||
|
*
|
||||||
|
* \param attribute The name of the attribute that changed.
|
||||||
|
* \param newValue The new value of the attribute.
|
||||||
|
* \param attributeChanged If TRUE, it corresponds to an actual change of the feature attribute
|
||||||
|
* \since QGIS 3.16
|
||||||
|
*/
|
||||||
|
void widgetValueChanged( const QString &attribute, const QVariant &newValue, bool attributeChanged );
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateValues( const QVariant &value, const QVariantList & = QVariantList() ) override;
|
void updateValues( const QVariant &value, const QVariantList & = QVariantList() ) override;
|
||||||
void updateConstraintWidgetStatus() override;
|
void updateConstraintWidgetStatus() override;
|
||||||
|
void updateProperties( const QgsFeature &feature );
|
||||||
|
|
||||||
QLineEdit *mLineEdit = nullptr;
|
QLineEdit *mLineEdit = nullptr;
|
||||||
QLabel *mLabel = nullptr;
|
QLabel *mLabel = nullptr;
|
||||||
|
QgsAttributeForm *mForm = nullptr;
|
||||||
QgsExternalResourceWidget *mQgsWidget = nullptr;
|
QgsExternalResourceWidget *mQgsWidget = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -282,6 +282,7 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature )
|
|||||||
{
|
{
|
||||||
mIsSettingFeature = true;
|
mIsSettingFeature = true;
|
||||||
mFeature = feature;
|
mFeature = feature;
|
||||||
|
mCurrentFormFeature = feature;
|
||||||
|
|
||||||
switch ( mMode )
|
switch ( mMode )
|
||||||
{
|
{
|
||||||
@ -872,6 +873,8 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value, const QVariant
|
|||||||
if ( mValuesInitialized )
|
if ( mValuesInitialized )
|
||||||
mDirty = true;
|
mDirty = true;
|
||||||
|
|
||||||
|
mCurrentFormFeature.setAttribute( eww->field().name(), value );
|
||||||
|
|
||||||
switch ( mMode )
|
switch ( mMode )
|
||||||
{
|
{
|
||||||
case QgsAttributeEditorContext::SingleEditMode:
|
case QgsAttributeEditorContext::SingleEditMode:
|
||||||
@ -957,7 +960,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
|
|||||||
{
|
{
|
||||||
// get the current feature set in the form
|
// get the current feature set in the form
|
||||||
QgsFeature ft;
|
QgsFeature ft;
|
||||||
if ( currentFormFeature( ft ) )
|
if ( currentFormValuesFeature( ft ) )
|
||||||
{
|
{
|
||||||
// if the layer is NOT being edited then we only check layer based constraints, and not
|
// if the layer is NOT being edited then we only check layer based constraints, and not
|
||||||
// any constraints enforced by the provider. Because:
|
// any constraints enforced by the provider. Because:
|
||||||
@ -1039,7 +1042,7 @@ void QgsAttributeForm::updateLabels()
|
|||||||
if ( ! mLabelDataDefinedProperties.isEmpty() )
|
if ( ! mLabelDataDefinedProperties.isEmpty() )
|
||||||
{
|
{
|
||||||
QgsFeature currentFeature;
|
QgsFeature currentFeature;
|
||||||
if ( currentFormFeature( currentFeature ) )
|
if ( currentFormValuesFeature( currentFeature ) )
|
||||||
{
|
{
|
||||||
QgsExpressionContext context = createExpressionContext( currentFeature );
|
QgsExpressionContext context = createExpressionContext( currentFeature );
|
||||||
|
|
||||||
@ -1057,7 +1060,7 @@ void QgsAttributeForm::updateLabels()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QgsAttributeForm::currentFormFeature( QgsFeature &feature )
|
bool QgsAttributeForm::currentFormValuesFeature( QgsFeature &feature )
|
||||||
{
|
{
|
||||||
bool rc = true;
|
bool rc = true;
|
||||||
feature = QgsFeature( mFeature );
|
feature = QgsFeature( mFeature );
|
||||||
@ -2460,7 +2463,7 @@ void QgsAttributeForm::updateJoinedFields( const QgsEditorWidgetWrapper &eww )
|
|||||||
QgsField field = eww.layer()->fields().field( eww.fieldIdx() );
|
QgsField field = eww.layer()->fields().field( eww.fieldIdx() );
|
||||||
QList<const QgsVectorLayerJoinInfo *> infos = eww.layer()->joinBuffer()->joinsWhereFieldIsId( field );
|
QList<const QgsVectorLayerJoinInfo *> infos = eww.layer()->joinBuffer()->joinsWhereFieldIsId( field );
|
||||||
|
|
||||||
if ( infos.count() == 0 || !currentFormFeature( formFeature ) )
|
if ( infos.count() == 0 || !currentFormValuesFeature( formFeature ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QString hint = tr( "No feature joined" );
|
const QString hint = tr( "No feature joined" );
|
||||||
|
@ -75,6 +75,14 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
|
|
||||||
const QgsFeature &feature() { return mFeature; }
|
const QgsFeature &feature() { return mFeature; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the feature that is currently displayed in the form with all
|
||||||
|
* the changes received on editing the values in the widgets.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.16
|
||||||
|
*/
|
||||||
|
QgsFeature currentFormFeature() const { return mCurrentFormFeature; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a warning message in the form message bar
|
* Displays a warning message in the form message bar
|
||||||
* \param message message string
|
* \param message message string
|
||||||
@ -403,7 +411,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
void updateContainersVisibility();
|
void updateContainersVisibility();
|
||||||
void updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww );
|
void updateConstraint( const QgsFeature &ft, QgsEditorWidgetWrapper *eww );
|
||||||
void updateLabels();
|
void updateLabels();
|
||||||
bool currentFormFeature( QgsFeature &feature );
|
bool currentFormValuesFeature( QgsFeature &feature );
|
||||||
bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
|
bool currentFormValidConstraints( QStringList &invalidFields, QStringList &descriptions );
|
||||||
QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
|
QList<QgsEditorWidgetWrapper *> constraintDependencies( QgsEditorWidgetWrapper *w );
|
||||||
|
|
||||||
@ -411,6 +419,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
|
|
||||||
QgsVectorLayer *mLayer = nullptr;
|
QgsVectorLayer *mLayer = nullptr;
|
||||||
QgsFeature mFeature;
|
QgsFeature mFeature;
|
||||||
|
QgsFeature mCurrentFormFeature;
|
||||||
QgsMessageBar *mMessageBar = nullptr;
|
QgsMessageBar *mMessageBar = nullptr;
|
||||||
bool mOwnsMessageBar;
|
bool mOwnsMessageBar;
|
||||||
QgsMessageBarItem *mMultiEditUnsavedMessageBarItem = nullptr;
|
QgsMessageBarItem *mMultiEditUnsavedMessageBarItem = nullptr;
|
||||||
|
@ -99,7 +99,9 @@ QgsExternalResourceWidget::DocumentViewerContent QgsExternalResourceWidget::docu
|
|||||||
void QgsExternalResourceWidget::setDocumentViewerContent( QgsExternalResourceWidget::DocumentViewerContent content )
|
void QgsExternalResourceWidget::setDocumentViewerContent( QgsExternalResourceWidget::DocumentViewerContent content )
|
||||||
{
|
{
|
||||||
mDocumentViewerContent = content;
|
mDocumentViewerContent = content;
|
||||||
updateDocumentViewer();
|
if ( mDocumentViewerContent != Image )
|
||||||
|
updateDocumentViewer();
|
||||||
|
loadDocument( mFileWidget->filePath() );
|
||||||
}
|
}
|
||||||
|
|
||||||
int QgsExternalResourceWidget::documentViewerHeight() const
|
int QgsExternalResourceWidget::documentViewerHeight() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user