Skip to content

Commit

Permalink
Enum Mode in QgsAttributeEditorContext
Browse files Browse the repository at this point in the history
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 b3e4755
Show file tree
Hide file tree
Showing 31 changed files with 153 additions and 182 deletions.
2 changes: 2 additions & 0 deletions python/gui/auto_additions/qgsattributeeditorcontext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The following has been generated automatically from src/gui/qgsattributeeditorcontext.h
QgsAttributeEditorContext.Mode.baseClass = QgsAttributeEditorContext
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ writes the ``qmlCode`` into a temporary file
%End

public slots:

void setQmlContext();

virtual void setFeature( const QgsFeature &feature );


Expand Down
2 changes: 1 addition & 1 deletion python/gui/auto_generated/qgsactionmenu.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions python/gui/auto_generated/qgsattributedialog.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions python/gui/auto_generated/qgsattributeeditorcontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ showing an embedded form due to relations)
%TypeHeaderCode
#include "qgsattributeeditorcontext.h"
%End
public:
static const QMetaObject staticMetaObject;

public:

enum Mode
Expand Down Expand Up @@ -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

Expand Down
23 changes: 3 additions & 20 deletions python/gui/auto_generated/qgsattributeform.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ class QgsAttributeForm : QWidget
%End
public:

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

enum FilterType
{
ReplaceFilter,
Expand Down Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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 );
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisappinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsattributetabledialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsfeatureaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolfillring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsselectbyformdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsdatasourcemanagerdialog.h
qgsabstractdatasourcewidget.h
qgswidgetstatehelper_p.h
qgsattributeeditorcontext.h

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

SET(QGIS_GUI_HDRS
qgsattributeeditorcontext.h
qgsattributeforminterface.h
qgsattributeformlegacyinterface.h
qgsdetaileditemdata.h
Expand Down
6 changes: 3 additions & 3 deletions src/gui/attributetable/qgsdualview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsdualview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/core/qgswidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 2 additions & 1 deletion src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions src/gui/qgsactionmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsactionmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -131,7 +131,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu
QgsFeatureId mFeatureId;
QString mActionScope;
QgsExpressionContextScope mExpressionContextScope;
QgsAttributeForm::Mode mMode;
QgsAttributeEditorContext::Mode mMode;
};


Expand Down
4 changes: 2 additions & 2 deletions src/gui/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit b3e4755

Please sign in to comment.