Skip to content

Commit 4da6e69

Browse files
committedSep 11, 2018
implementation for containers
and changed to string of formMode in the attributeformcontext
1 parent d80ad3d commit 4da6e69

File tree

6 files changed

+41
-40
lines changed

6 files changed

+41
-40
lines changed
 

‎python/gui/auto_generated/qgsattributeeditorcontext.sip.in

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,28 +208,20 @@ Set current ``feature`` for the currently edited form or table row
208208
.. versionadded:: 3.2
209209
%End
210210

211-
Mode attributeFormMode() const;
211+
QString attributeFormMode() const;
212212
%Docstring
213213
Returns current attributeFormMode
214214

215215
.. versionadded:: 3.4
216216
%End
217217

218-
void setAttributeFormMode( const Mode attributeFormMode );
218+
void setAttributeFormMode( const QString &attributeFormMode );
219219
%Docstring
220220
Set ``attributeFormMode`` for the edited form
221221

222222
.. versionadded:: 3.4
223223
%End
224224

225-
QString attributeFormModeString() const;
226-
%Docstring
227-
Returns the context as string
228-
229-
.. versionadded:: 3.4
230-
%End
231-
232-
233225
};
234226

235227

‎python/gui/auto_generated/qgsattributeform.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ Sets the current mode of the form.
8989
.. seealso:: :py:func:`mode`
9090

9191
.. versionadded:: 2.16
92+
%End
93+
94+
QString modeString( Mode mode ) const;
95+
%Docstring
96+
Returns the context as string of ``mode``
97+
98+
.. versionadded:: 3.4
9299
%End
93100

94101
void setEditCommandMessage( const QString &message );

‎src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void QgsQmlWidgetWrapper::setQmlContext( )
8686
return;
8787

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

9292
QmlExpression *qmlExpression = new QmlExpression();

‎src/gui/qgsattributeeditorcontext.h

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -220,37 +220,13 @@ class GUI_EXPORT QgsAttributeEditorContext
220220
* Returns current attributeFormMode
221221
* \since QGIS 3.4
222222
*/
223-
Mode attributeFormMode() const { return mAttributeFormMode; }
223+
QString attributeFormMode() const { return mAttributeFormMode; }
224224

225225
/**
226226
* Set \a attributeFormMode for the edited form
227227
* \since QGIS 3.4
228228
*/
229-
void setAttributeFormMode( const Mode attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
230-
231-
/**
232-
* Returns the context as string
233-
* \since QGIS 3.4
234-
*/
235-
QString attributeFormModeString() const
236-
{
237-
switch ( mAttributeFormMode )
238-
{
239-
case SingleEditMode:
240-
return QStringLiteral( "SingleEditMode" );
241-
case AddFeatureMode:
242-
return QStringLiteral( "AddFeatureMode" );
243-
case MultiEditMode:
244-
return QStringLiteral( "MultiEditMode" );
245-
case SearchMode:
246-
return QStringLiteral( "SearchMode" );
247-
case AggregateSearchMode:
248-
return QStringLiteral( "AggregateSearchMode" );
249-
case IdentifyMode:
250-
return QStringLiteral( "IdentifyMode" );
251-
}
252-
}
253-
229+
void setAttributeFormMode( const QString &attributeFormMode ) { mAttributeFormMode = attributeFormMode; }
254230

255231
private:
256232
const QgsAttributeEditorContext *mParentContext = nullptr;
@@ -264,7 +240,7 @@ class GUI_EXPORT QgsAttributeEditorContext
264240
QgsFeature mFormFeature;
265241
FormMode mFormMode = Embed;
266242
bool mAllowCustomUi = true;
267-
Mode mAttributeFormMode = QgsAttributeEditorContext::SingleEditMode;
243+
QString mAttributeFormMode = QStringLiteral( "SingleEditMode" );
268244
};
269245

270246
#endif // QGSATTRIBUTEEDITORCONTEXT_H

‎src/gui/qgsattributeform.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode )
187187
for ( QgsWidgetWrapper *w : qgis::as_const( mWidgets ) )
188188
{
189189
QgsAttributeEditorContext newContext = w->context();
190-
newContext.setAttributeFormMode( ( QgsAttributeEditorContext::Mode )mode );
190+
newContext.setAttributeFormMode( modeString( mMode ) );
191191
w->setContext( newContext );
192192
}
193193

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

237+
QString QgsAttributeForm::modeString( Mode mode ) const
238+
{
239+
switch ( mode )
240+
{
241+
case SingleEditMode:
242+
return QStringLiteral( "SingleEditMode" );
243+
case AddFeatureMode:
244+
return QStringLiteral( "AddFeatureMode" );
245+
case MultiEditMode:
246+
return QStringLiteral( "MultiEditMode" );
247+
case SearchMode:
248+
return QStringLiteral( "SearchMode" );
249+
case AggregateSearchMode:
250+
return QStringLiteral( "AggregateSearchMode" );
251+
case IdentifyMode:
252+
return QStringLiteral( "IdentifyMode" );
253+
}
254+
}
255+
237256
void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &value, const QString &hintText )
238257
{
239258
Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets )
@@ -804,6 +823,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
804823
synchronizeEnabledState();
805824

806825
mExpressionContext.setFeature( ft );
826+
mExpressionContext << QgsExpressionContextUtils::formScope( ft, modeString( mMode ) );
807827

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

17901810
mWidgets.append( qmlWrapper );

‎src/gui/qgsattributeform.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
130130
*/
131131
void setMode( Mode mode );
132132

133+
/**
134+
* Returns the context as string of \a mode
135+
* \since QGIS 3.4
136+
*/
137+
QString modeString( Mode mode ) const;
138+
133139
/**
134140
* Sets the edit command message (Undo) that will be used when the dialog is accepted
135141
*

0 commit comments

Comments
 (0)
Please sign in to comment.