Skip to content

Commit

Permalink
implementation for containers
Browse files Browse the repository at this point in the history
and changed to string of formMode in the attributeformcontext
  • Loading branch information
signedav committed Sep 11, 2018
1 parent d80ad3d commit 4da6e69
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
12 changes: 2 additions & 10 deletions python/gui/auto_generated/qgsattributeeditorcontext.sip.in
Expand Up @@ -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


};


Expand Down
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsattributeform.sip.in
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
Expand Up @@ -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();
Expand Down
30 changes: 3 additions & 27 deletions src/gui/qgsattributeeditorcontext.h
Expand Up @@ -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;
Expand All @@ -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
Expand Down
24 changes: 22 additions & 2 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsattributeform.h
Expand Up @@ -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
*
Expand Down

0 comments on commit 4da6e69

Please sign in to comment.