Skip to content
Permalink
Browse files

Enum Mode in QgsAttributeEditorContext

instead of QgsAttributeForm - because it's used on places not including QgsAttributeForm
now it's able to use @form_mode in expressions of containers and QML widgets
  • Loading branch information
signedav committed Sep 11, 2018
1 parent 05b1e83 commit b3e4755e2eb93f846ff3f6f6170548d9c53a4a00
Showing with 153 additions and 182 deletions.
  1. +2 −0 python/gui/auto_additions/qgsattributeeditorcontext.py
  2. +1 −1 python/gui/auto_generated/attributetable/qgsdualview.sip.in
  3. +1 −1 python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in
  4. +0 −3 python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in
  5. +1 −1 python/gui/auto_generated/qgsactionmenu.sip.in
  6. +2 −2 python/gui/auto_generated/qgsattributedialog.sip.in
  7. +12 −2 python/gui/auto_generated/qgsattributeeditorcontext.sip.in
  8. +3 −20 python/gui/auto_generated/qgsattributeform.sip.in
  9. +1 −1 src/app/qgisapp.cpp
  10. +1 −1 src/app/qgisappinterface.cpp
  11. +2 −2 src/app/qgsattributetabledialog.cpp
  12. +1 −1 src/app/qgsattributetabledialog.h
  13. +3 −3 src/app/qgsfeatureaction.cpp
  14. +1 −1 src/app/qgsmaptoolfillring.cpp
  15. +1 −1 src/app/qgsselectbyformdialog.cpp
  16. +1 −1 src/gui/CMakeLists.txt
  17. +3 −3 src/gui/attributetable/qgsdualview.cpp
  18. +1 −1 src/gui/attributetable/qgsdualview.h
  19. +1 −1 src/gui/editorwidgets/core/qgswidgetwrapper.h
  20. +2 −1 src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
  21. +3 −2 src/gui/editorwidgets/qgsqmlwidgetwrapper.h
  22. +1 −1 src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp
  23. +3 −3 src/gui/qgsactionmenu.cpp
  24. +2 −2 src/gui/qgsactionmenu.h
  25. +2 −2 src/gui/qgsattributedialog.cpp
  26. +2 −2 src/gui/qgsattributedialog.h
  27. +18 −4 src/gui/qgsattributeeditorcontext.h
  28. +68 −87 src/gui/qgsattributeform.cpp
  29. +4 −22 src/gui/qgsattributeform.h
  30. +2 −2 src/gui/qgsidentifymenu.cpp
  31. +8 −8 tests/src/gui/testqgsattributeform.cpp
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/gui/qgsattributeeditorcontext.h
QgsAttributeEditorContext.Mode.baseClass = QgsAttributeEditorContext
@@ -240,7 +240,7 @@ Is emitted when a filter expression is set using the view.
.. versionadded:: 2.16
%End

void formModeChanged( QgsAttributeForm::Mode mode );
void formModeChanged( QgsAttributeEditorContext::Mode mode );
%Docstring
Emitted when the form changes mode.

@@ -171,7 +171,7 @@ might be lost.

void contextChanged();
%Docstring
Signal when QgsAttributeEditorContext mContext changed after the widget wrapper has already been intialized
Signal when QgsAttributeEditorContext mContext changed

.. versionadded:: 3.4
%End
@@ -49,9 +49,6 @@ writes the ``qmlCode`` into a temporary file
%End

public slots:

void setQmlContext();

virtual void setFeature( const QgsFeature &feature );


@@ -73,7 +73,7 @@ Change the feature on which actions are performed
as long as the menu is displayed and the action is running.
%End

void setMode( QgsAttributeForm::Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
%Docstring
Change the mode of the actions

@@ -50,11 +50,11 @@ Is this dialog editable?
:return: returns true, if this dialog was created in an editable manner.
%End

void setMode( QgsAttributeForm::Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
%Docstring
Toggles the form mode.

:param mode: form mode. For example, if set to QgsAttributeForm.AddFeatureMode, the dialog will be editable even with an invalid feature and
:param mode: form mode. For example, if set to QgsAttributeEditorContext.AddFeatureMode, the dialog will be editable even with an invalid feature and
will add a new feature when the form is accepted.
%End

@@ -22,6 +22,9 @@ showing an embedded form due to relations)
%TypeHeaderCode
#include "qgsattributeeditorcontext.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum Mode
@@ -208,17 +211,24 @@ Set current ``feature`` for the currently edited form or table row
.. versionadded:: 3.2
%End

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

.. versionadded:: 3.4
%End

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

.. versionadded:: 3.4
%End

QString attributeFormModeString( const Mode &attributeFormMode );
%Docstring
Returns given ``attributeFormMode`` as string

.. versionadded:: 3.4
%End

@@ -19,16 +19,6 @@ class QgsAttributeForm : QWidget
%End
public:

enum Mode
{
SingleEditMode,
AddFeatureMode,
MultiEditMode,
SearchMode,
AggregateSearchMode,
IdentifyMode
};

enum FilterType
{
ReplaceFilter,
@@ -71,7 +61,7 @@ Returns if the form is currently in editable mode.
:return: Editable mode of this form
%End

Mode mode() const;
QgsAttributeEditorContext::Mode mode() const;
%Docstring
Returns the current mode of the form.

@@ -80,7 +70,7 @@ Returns the current mode of the form.
.. versionadded:: 2.16
%End

void setMode( Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );
%Docstring
Sets the current mode of the form.

@@ -89,13 +79,6 @@ 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 );
@@ -184,7 +167,7 @@ Is emitted when a filter expression is set using the form.
.. versionadded:: 2.16
%End

void modeChanged( QgsAttributeForm::Mode mode );
void modeChanged( QgsAttributeEditorContext::Mode mode );
%Docstring
Emitted when the form changes mode.

@@ -8196,7 +8196,7 @@ void QgisApp::modifyAttributesOfSelectedFeatures()
context.setAllowCustomUi( false );

QgsAttributeDialog *dialog = new QgsAttributeDialog( vl, &f, false, this, true, context );
dialog->setMode( QgsAttributeForm::MultiEditMode );
dialog->setMode( QgsAttributeEditorContext::MultiEditMode );
dialog->exec();
}

@@ -745,7 +745,7 @@ QgsAttributeDialog *QgisAppInterface::getFeatureForm( QgsVectorLayer *l, QgsFeat
QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, qgis, true, context );
if ( !feature.isValid() )
{
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
}
return dialog;
}
@@ -475,9 +475,9 @@ void QgsAttributeTableDialog::updateFieldFromExpressionSelected()
runFieldCalculation( mLayer, mFieldCombo->currentField(), mUpdateExpressionText->asExpression(), filteredIds );
}

void QgsAttributeTableDialog::viewModeChanged( QgsAttributeForm::Mode mode )
void QgsAttributeTableDialog::viewModeChanged( QgsAttributeEditorContext::Mode mode )
{
if ( mode != QgsAttributeForm::SearchMode )
if ( mode != QgsAttributeEditorContext::SearchMode )
mActionSearchForm->setChecked( false );
}

@@ -218,7 +218,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib
void runFieldCalculation( QgsVectorLayer *layer, const QString &fieldName, const QString &expression, const QgsFeatureIds &filteredIds = QgsFeatureIds() );
void updateFieldFromExpression();
void updateFieldFromExpressionSelected();
void viewModeChanged( QgsAttributeForm::Mode mode );
void viewModeChanged( QgsAttributeEditorContext::Mode mode );
void formFilterSet( const QString &filter, QgsAttributeForm::FilterType type );
void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid );
void toggleDockMode( bool docked );
@@ -135,7 +135,7 @@ bool QgsFeatureAction::editFeature( bool showModal )
std::unique_ptr<QgsAttributeDialog> dialog( newDialog( false ) );

if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );

int rv = dialog->exec();
mFeature->setAttributes( dialog->feature()->attributes() );
@@ -155,7 +155,7 @@ bool QgsFeatureAction::editFeature( bool showModal )
dialog = newDialog( false );

if ( !mFeature->isValid() )
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );

// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
@@ -235,7 +235,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
QgsAttributeDialog *dialog = newDialog( false );
// delete the dialog when it is closed
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
dialog->setEditCommandMessage( text() );

connect( dialog->attributeForm(), &QgsAttributeForm::featureSaved, this, &QgsFeatureAction::onFeatureSaved );
@@ -161,7 +161,7 @@ void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
else
{
QgsAttributeDialog *dialog = new QgsAttributeDialog( vlayer, &ft, false, nullptr, true );
dialog->setMode( QgsAttributeForm::AddFeatureMode );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
res = dialog->exec(); // will also add the feature
}

@@ -30,7 +30,7 @@ QgsSelectByFormDialog::QgsSelectByFormDialog( QgsVectorLayer *layer, const QgsAt
dlgContext.setAllowCustomUi( false );

mForm = new QgsAttributeForm( layer, QgsFeature(), dlgContext, this );
mForm->setMode( QgsAttributeForm::SearchMode );
mForm->setMode( QgsAttributeEditorContext::SearchMode );

QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->setMargin( 0 );
@@ -547,6 +547,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsdatasourcemanagerdialog.h
qgsabstractdatasourcewidget.h
qgswidgetstatehelper_p.h
qgsattributeeditorcontext.h

ogr/qgsnewogrconnection.h
ogr/qgsvectorlayersaveasdialog.h
@@ -757,7 +758,6 @@ ENDIF(MSVC)
# for installing headers

SET(QGIS_GUI_HDRS
qgsattributeeditorcontext.h
qgsattributeforminterface.h
qgsattributeformlegacyinterface.h
qgsdetaileditemdata.h
@@ -446,19 +446,19 @@ void QgsDualView::setMultiEditEnabled( bool enabled )
if ( enabled )
setView( AttributeEditor );

mAttributeForm->setMode( enabled ? QgsAttributeForm::MultiEditMode : QgsAttributeForm::SingleEditMode );
mAttributeForm->setMode( enabled ? QgsAttributeEditorContext::MultiEditMode : QgsAttributeEditorContext::SingleEditMode );
}

void QgsDualView::toggleSearchMode( bool enabled )
{
if ( enabled )
{
setView( AttributeEditor );
mAttributeForm->setMode( QgsAttributeForm::SearchMode );
mAttributeForm->setMode( QgsAttributeEditorContext::SearchMode );
}
else
{
mAttributeForm->setMode( QgsAttributeForm::SingleEditMode );
mAttributeForm->setMode( QgsAttributeEditorContext::SingleEditMode );
}
}

@@ -267,7 +267,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
* Emitted when the form changes mode.
* \param mode new mode
*/
void formModeChanged( QgsAttributeForm::Mode mode );
void formModeChanged( QgsAttributeEditorContext::Mode mode );

/**
* Emitted when selecting context menu on the feature list to create the context menu individually
@@ -205,7 +205,7 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject
signals:

/**
* Signal when QgsAttributeEditorContext mContext changed after the widget wrapper has already been intialized
* Signal when QgsAttributeEditorContext mContext changed
*
* \since QGIS 3.4
*/
@@ -85,8 +85,9 @@ void QgsQmlWidgetWrapper::setQmlContext( )
if ( !mWidget )
return;

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

QmlExpression *qmlExpression = new QmlExpression();
@@ -54,11 +54,12 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
void setQmlCode( const QString &qmlCode );

public slots:
void setFeature( const QgsFeature &feature ) override;

private slots:
//! sets the qml context with the current values
void setQmlContext();

void setFeature( const QgsFeature &feature ) override;

private:
QTemporaryFile mQmlFile;
QQuickWidget *mWidget = nullptr;
@@ -90,7 +90,7 @@ bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEv
{
QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed );
mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, mContainerWidget );
mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode );
mAttributeForm->setMode( QgsAttributeEditorContext::AggregateSearchMode );
QGridLayout *glayout = new QGridLayout();
mContainerWidget->setLayout( glayout );
glayout->setMargin( 0 );
@@ -67,7 +67,7 @@ void QgsActionMenu::setFeature( const QgsFeature &feature )
mFeature = feature;
}

void QgsActionMenu::setMode( const QgsAttributeForm::Mode mode )
void QgsActionMenu::setMode( const QgsAttributeEditorContext::Mode mode )
{
mMode = mode;
reloadActions();
@@ -120,7 +120,7 @@ void QgsActionMenu::reloadActions()
if ( !mLayer->isEditable() && action.isEnabledOnlyWhenEditable() )
continue;

if ( action.isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeForm::AddFeatureMode || mMode == QgsAttributeForm::IdentifyMode ) )
if ( action.isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeEditorContext::AddFeatureMode || mMode == QgsAttributeEditorContext::IdentifyMode ) )
continue;

QgsAction act( action );
@@ -155,7 +155,7 @@ void QgsActionMenu::reloadActions()
{
QgsMapLayerAction *qaction = mapLayerActions.at( i );

if ( qaction->isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeForm::AddFeatureMode || mMode == QgsAttributeForm::IdentifyMode ) )
if ( qaction->isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeEditorContext::AddFeatureMode || mMode == QgsAttributeEditorContext::IdentifyMode ) )
continue;

QAction *qAction = new QAction( qaction->icon(), qaction->text(), this );
@@ -97,7 +97,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
*
* \param mode The mode of the attribute form
*/
void setMode( QgsAttributeForm::Mode mode );
void setMode( QgsAttributeEditorContext::Mode mode );

/**
* Sets an expression context scope used to resolve underlying actions.
@@ -131,7 +131,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
QgsFeatureId mFeatureId;
QString mActionScope;
QgsExpressionContextScope mExpressionContextScope;
QgsAttributeForm::Mode mMode;
QgsAttributeEditorContext::Mode mMode;
};


@@ -79,7 +79,7 @@ void QgsAttributeDialog::show()
void QgsAttributeDialog::reject()
{
// Delete any actions on other layers that may have been triggered from this dialog
if ( mAttributeForm->mode() == QgsAttributeForm::AddFeatureMode )
if ( mAttributeForm->mode() == QgsAttributeEditorContext::AddFeatureMode )
mTrackedVectorLayerTools.rollback();

QDialog::reject();
@@ -116,7 +116,7 @@ void QgsAttributeDialog::init( QgsVectorLayer *layer, QgsFeature *feature, const
focusNextChild();
}

void QgsAttributeDialog::setMode( QgsAttributeForm::Mode mode )
void QgsAttributeDialog::setMode( QgsAttributeEditorContext::Mode mode )
{
mAttributeForm->setMode( mode );
mMenu->setMode( mode );

0 comments on commit b3e4755

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