Skip to content
Permalink
Browse files

implementation for containers

and changed to string of formMode in the attributeformcontext
  • Loading branch information
signedav committed Sep 11, 2018
1 parent d80ad3d commit 4da6e6975a8aadec2a66504bbb32267f20cf6ef0
@@ -208,28 +208,20 @@ Set current ``feature`` for the currently edited form or table row
.. versionadded:: 3.2
%End

Mode attributeFormMode() const;
QString attributeFormMode() const;
%Docstring
Returns current attributeFormMode

.. versionadded:: 3.4
%End

void setAttributeFormMode( const Mode attributeFormMode );
void setAttributeFormMode( const QString &attributeFormMode );
%Docstring
Set ``attributeFormMode`` for the edited form

.. versionadded:: 3.4
%End

QString attributeFormModeString() const;
%Docstring
Returns the context as string

.. versionadded:: 3.4
%End


};


@@ -89,6 +89,13 @@ Sets the current mode of the form.
.. seealso:: :py:func:`mode`

.. versionadded:: 2.16
%End

QString modeString( Mode mode ) const;
%Docstring
Returns the context as string of ``mode``

.. versionadded:: 3.4
%End

void setEditCommandMessage( const QString &message );
@@ -86,7 +86,7 @@ void QgsQmlWidgetWrapper::setQmlContext( )
return;

QgsExpressionContext expressionContext = layer()->createExpressionContext();
expressionContext << QgsExpressionContextUtils::formScope( mFeature, context().attributeFormModeString() );
expressionContext << QgsExpressionContextUtils::formScope( mFeature, context().attributeFormMode() );
expressionContext.setFeature( mFeature );

QmlExpression *qmlExpression = new QmlExpression();
@@ -220,37 +220,13 @@ class GUI_EXPORT QgsAttributeEditorContext
* Returns current attributeFormMode
* \since QGIS 3.4
*/
Mode attributeFormMode() const { return mAttributeFormMode; }
QString attributeFormMode() const { return mAttributeFormMode; }

/**
* Set \a attributeFormMode for the edited form
* \since QGIS 3.4
*/
void setAttributeFormMode( const Mode attributeFormMode ) { mAttributeFormMode = attributeFormMode; }

/**
* Returns the context as string
* \since QGIS 3.4
*/
QString attributeFormModeString() const
{
switch ( mAttributeFormMode )
{
case SingleEditMode:
return QStringLiteral( "SingleEditMode" );
case AddFeatureMode:
return QStringLiteral( "AddFeatureMode" );
case MultiEditMode:
return QStringLiteral( "MultiEditMode" );
case SearchMode:
return QStringLiteral( "SearchMode" );
case AggregateSearchMode:
return QStringLiteral( "AggregateSearchMode" );
case IdentifyMode:
return QStringLiteral( "IdentifyMode" );
}
}

void setAttributeFormMode( const QString &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }

private:
const QgsAttributeEditorContext *mParentContext = nullptr;
@@ -264,7 +240,7 @@ class GUI_EXPORT QgsAttributeEditorContext
QgsFeature mFormFeature;
FormMode mFormMode = Embed;
bool mAllowCustomUi = true;
Mode mAttributeFormMode = QgsAttributeEditorContext::SingleEditMode;
QString mAttributeFormMode = QStringLiteral( "SingleEditMode" );
};

#endif // QGSATTRIBUTEEDITORCONTEXT_H
@@ -187,7 +187,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
for ( QgsWidgetWrapper *w : qgis::as_const( mWidgets ) )
{
QgsAttributeEditorContext newContext = w->context();
newContext.setAttributeFormMode( ( QgsAttributeEditorContext::Mode )mode );
newContext.setAttributeFormMode( modeString( mMode ) );
w->setContext( newContext );
}

@@ -234,6 +234,25 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
emit modeChanged( mMode );
}

QString QgsAttributeForm::modeString( Mode mode ) const
{
switch ( mode )
{
case SingleEditMode:
return QStringLiteral( "SingleEditMode" );
case AddFeatureMode:
return QStringLiteral( "AddFeatureMode" );
case MultiEditMode:
return QStringLiteral( "MultiEditMode" );
case SearchMode:
return QStringLiteral( "SearchMode" );
case AggregateSearchMode:
return QStringLiteral( "AggregateSearchMode" );
case IdentifyMode:
return QStringLiteral( "IdentifyMode" );
}
}

void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &value, const QString &hintText )
{
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
@@ -804,6 +823,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
synchronizeEnabledState();

mExpressionContext.setFeature( ft );
mExpressionContext << QgsExpressionContextUtils::formScope( ft, modeString( mMode ) );

// Recheck visibility for all containers which are controlled by this value
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
@@ -1784,7 +1804,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt
QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this );
qmlWrapper->setQmlCode( elementDef->qmlCode() );
qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( elementDef->name() ) );
context.setAttributeFormMode( ( QgsAttributeEditorContext::Mode ) mode() );
context.setAttributeFormMode( modeString( mMode ) );
qmlWrapper->setContext( context );

mWidgets.append( qmlWrapper );
@@ -130,6 +130,12 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
*/
void setMode( Mode mode );

/**
* Returns the context as string of \a mode
* \since QGIS 3.4
*/
QString modeString( Mode mode ) const;

/**
* Sets the edit command message (Undo) that will be used when the dialog is accepted
*

0 comments on commit 4da6e69

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